From c75fd5deea521931a6c98e514fc1047df304120b Mon Sep 17 00:00:00 2001 From: Lukas Burger Date: Sat, 25 May 2019 12:50:53 -0400 Subject: [PATCH] first pass --- src/api.js | 47 +++++++++++++++++++++-------- src/components/Account/Account.js | 4 +-- src/components/Landing/Landing.js | 32 -------------------- src/components/SendTo/SendTo.js | 30 +++++------------- src/components/SwipeApp/Balance.js | 3 -- src/components/SwipeApp/SwipeApp.js | 6 ++-- src/redux/crypto/actions.js | 5 +-- src/redux/reducers.js | 1 + 8 files changed, 48 insertions(+), 80 deletions(-) diff --git a/src/api.js b/src/api.js index 9783e0a47..d7951bdc7 100644 --- a/src/api.js +++ b/src/api.js @@ -152,6 +152,39 @@ const UpdateUser = (uid, updateDict) => { }); }; +async function GetUserFromAddress(address, currency, network='mainnet') { + if (erc20Names.indexOf(currency) > -1) currency = 'ETH' + const query = "wallets." + currency + "." + network + '.address' + + firestore.collection("users").where(query, "==", address).get().then(data => { + if (!data.empty) { + const userData = { + id: data.docs[0].id, + ...data.docs[0].data() + } + return userData + } + else { + // could not find a user for this address + } + }).catch(error => { + Sentry.captureMessage(error) + }) +} + +async function DeleteUser(userId) { + try { + await Keychain.resetGenericPassword(); + await DeleteTransactions(userId); + await firestore + .collection("users") + .doc(userId) + .delete(); + } catch (e) { + console.log(e); + } +} + const UpdateTransaction = (transactionId, updateDict) => { return new Promise((resolve, reject) => { firestore @@ -224,19 +257,6 @@ async function AddToKeychain(userId, key, value) { } } -async function DeleteUser(userId) { - try { - await Keychain.resetGenericPassword(); - await DeleteTransactions(userId); - await firestore - .collection("users") - .doc(userId) - .delete(); - } catch (e) { - console.log(e); - } -} - async function DeleteTransactions(userId) { try { const query1 = await firestore @@ -269,6 +289,7 @@ async function DeleteTransactions(userId) { export default (api = { CreateUser, UpdateUser, + GetUserFromAddress, UpdateTransaction, GetExchangeRate, AddToKeychain, diff --git a/src/components/Account/Account.js b/src/components/Account/Account.js index 505c6e266..df932624e 100644 --- a/src/components/Account/Account.js +++ b/src/components/Account/Account.js @@ -33,7 +33,7 @@ const Account = ({activeCryptoCurrency, activeCryptoNetwork, splashtag, userId, navigation.navigate('SwipeApp') toggleLockout(enabled) }).catch(e => { - Sentry.captureException(e) + Sentry.captureMessage(e) Alert.alert("An error occurred. Please try again later.") }) } @@ -47,7 +47,7 @@ const Account = ({activeCryptoCurrency, activeCryptoNetwork, splashtag, userId, navigation.navigate('SwipeApp') toggleLockout(enabled) }).catch(e => { - Sentry.captureException(e) + Sentry.captureMessage(e) Alert.alert("An error occurred. Please try again later.") }) } diff --git a/src/components/Landing/Landing.js b/src/components/Landing/Landing.js index b7d6fa664..494d3b2de 100644 --- a/src/components/Landing/Landing.js +++ b/src/components/Landing/Landing.js @@ -11,13 +11,10 @@ import { import { colors } from "../../lib/colors"; import { defaults, icons } from "../../lib/styles"; import { Input } from "../universal/Input"; -import firebase from "react-native-firebase"; import AnimatedWaves from "../universal/AnimatedWaves"; import TouchID from 'react-native-touch-id' import Button from "../universal/Button" -let firestore = firebase.firestore() - class Landing extends Component { constructor(props) { @@ -31,35 +28,6 @@ class Landing extends Component { } } - componentDidMount() { - - firebase - .links() - .getInitialLink() - .then(url => { - if (url) { - this.handleDeepLink({ url: url }); - } - }); - } - - handleDeepLink = event => { - if (event.url) { - const parts = event.url.split("/"); - const splashtag = parts[3]; - const phoneNumber = parts[4]; - - if ( - !( - splashtag == this.props.splashtagOnHold && - phoneNumber == this.props.phoneNumber - ) - ) { - this.props.getDeepLinkedSplashtag(splashtag, phoneNumber); - } - } - }; - handlePress() { if (this.props.splashtagOnHold && this.props.phoneNumber) { this.props.SmsAuthenticate(this.props.phoneNumber, null); diff --git a/src/components/SendTo/SendTo.js b/src/components/SendTo/SendTo.js index eafe82d54..4c48b4232 100644 --- a/src/components/SendTo/SendTo.js +++ b/src/components/SendTo/SendTo.js @@ -33,11 +33,9 @@ import { algoliaKeys } from '../../../env/keys.json' import { InstantSearch } from 'react-instantsearch/native'; import SearchBox from "./SearchBox" import api from "../../api" -import firebase from "react-native-firebase"; import Permissions from 'react-native-permissions' import Contacts from 'react-native-contacts'; import moment from "moment" -let firestore = firebase.firestore(); const SCREEN_WIDTH = Dimensions.get("window").width const SCREEN_HEIGHT = Dimensions.get("window").height @@ -160,28 +158,14 @@ class SendTo extends Component { } getUserFromAddress(address) { - let activeCryptoCurrency = this.props.activeCryptoCurrency - if (erc20Names.indexOf(activeCryptoCurrency) > -1) activeCryptoCurrency = 'ETH' - const query = "wallets." + activeCryptoCurrency + "." + this.props.network + '.address' - firestore.collection("users").where(query, "==", address).get().then(query => { - if (!query.empty) { - const userData = { - id: query.docs[0].id, - ...query.docs[0].data() - } - this.setState({ - userFromAddress: userData, - selectedId: userData.id, - selectedSplashtag: userData.splashtag, - selectedAddress: userData.wallets[activeCryptoCurrency][this.props.network].address - }) - } - else { - // could not find a user for this address - } - }).catch(error => { - Sentry.captureMessage(error) + api.GetUserFromAddress(address, this.pros.activeCryptoCurrency, this.props.network).then(userData => { + this.setState({ + userFromAddress: userData, + selectedId: userData.id, + selectedSplashtag: userData.splashtag, + selectedAddress: userData.wallets[activeCryptoCurrency][this.props.network].address + }) }) } diff --git a/src/components/SwipeApp/Balance.js b/src/components/SwipeApp/Balance.js index fd1be5763..46aa4d399 100644 --- a/src/components/SwipeApp/Balance.js +++ b/src/components/SwipeApp/Balance.js @@ -22,14 +22,11 @@ import { bindActionCreators } from "redux" import { isIphoneX } from "react-native-iphone-x-helper" import ReactNativeHapticFeedback from 'react-native-haptic-feedback' import api from '../../api' -import firebase from "react-native-firebase" import LoadingCircle from "../universal/LoadingCircle" import CurrencySwitcher from "../universal/CurrencySwitcher" import { setActiveCurrency } from "../../redux/crypto/actions" import { decimalLengths } from "../../lib/cryptos" -let firestore = firebase.firestore(); - const SCREEN_WIDTH = Dimensions.get("window").width const SCREEN_HEIGHT = Dimensions.get("window").height diff --git a/src/components/SwipeApp/SwipeApp.js b/src/components/SwipeApp/SwipeApp.js index dadc8c7ac..b5f4ef20e 100644 --- a/src/components/SwipeApp/SwipeApp.js +++ b/src/components/SwipeApp/SwipeApp.js @@ -318,7 +318,7 @@ class SwipeApp extends Component { await firebase.messaging().requestPermission() const fcmToken = await firebase.messaging().getToken() if (fcmToken) { - await firebase.firestore().collection('users').doc(this.props.userId).update({pushToken: fcmToken}) + await api.UpdateUser(this.props.userId, {pushToken: fcmToken}) } }) } else { @@ -326,11 +326,11 @@ class SwipeApp extends Component { if (!doc.data().pushToken) { const fcmToken = await firebase.messaging().getToken() if (fcmToken) { - await firebase.firestore().collection('users').doc(this.props.userId).update({pushToken: fcmToken}) + await api.UpdateUser(this.props.userId, {pushToken: fcmToken}) } } this.onTokenRefreshListener = firebase.messaging().onTokenRefresh(async (fcmToken) => { - await firebase.firestore().collection('users').doc(this.props.userId).update({pushToken: fcmToken}) + await api.UpdateUser(this.props.userId, {pushToken: fcmToken}) }); } }).catch(e => console.log('Notification Error:', e)) diff --git a/src/redux/crypto/actions.js b/src/redux/crypto/actions.js index 0d608c517..1c7b3a967 100644 --- a/src/redux/crypto/actions.js +++ b/src/redux/crypto/actions.js @@ -328,10 +328,7 @@ export const OpenWallet = (userId, currencies) => { ) .then(() => { // update user with public wallet data for currency - firestore - .collection("users") - .doc(userId) - .update({ + api.UpdateUser(userId, { wallets: publicWalletData }) .then(() => { diff --git a/src/redux/reducers.js b/src/redux/reducers.js index 33573c48b..b5aeb8219 100644 --- a/src/redux/reducers.js +++ b/src/redux/reducers.js @@ -6,6 +6,7 @@ import crypto from "./crypto/reducer" import payFlow from "./payFlow" import { reducer as formReducer } from 'redux-form'; +// combine reducers const reducers = { user, onboarding,