Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 34 additions & 13 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -269,6 +289,7 @@ async function DeleteTransactions(userId) {
export default (api = {
CreateUser,
UpdateUser,
GetUserFromAddress,
UpdateTransaction,
GetExchangeRate,
AddToKeychain,
Expand Down
4 changes: 2 additions & 2 deletions src/components/Account/Account.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
})
}
Expand All @@ -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.")
})
}
Expand Down
32 changes: 0 additions & 32 deletions src/components/Landing/Landing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
30 changes: 7 additions & 23 deletions src/components/SendTo/SendTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
})
})
}

Expand Down
3 changes: 0 additions & 3 deletions src/components/SwipeApp/Balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/components/SwipeApp/SwipeApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,19 +318,19 @@ 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 {
const doc = await firebase.firestore().collection('users').doc(this.props.userId).get()
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))
Expand Down
5 changes: 1 addition & 4 deletions src/redux/crypto/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
1 change: 1 addition & 0 deletions src/redux/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down