From 66bce8874a3d752864a8332807ad89ea263bb22c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Rodriguez=20Ve=CC=81lez?= Date: Sat, 29 Dec 2018 13:24:51 -0500 Subject: [PATCH] FIX: Dismiss add screen --- App.js | 47 +++++------- models/fiatUnit.js | 2 +- .../lndViewAdditionalInvoiceInformation.js | 2 +- screen/lnd/scanLndInvoice.js | 41 +++++----- screen/send/details.js | 76 ++++++++++--------- screen/wallets/add.js | 3 +- 6 files changed, 86 insertions(+), 85 deletions(-) diff --git a/App.js b/App.js index a63eb42db..757362e00 100644 --- a/App.js +++ b/App.js @@ -1,10 +1,7 @@ -/* global alert */ import React from 'react'; import { Linking } from 'react-native'; import { NavigationActions } from 'react-navigation'; import MainBottomTabs from './MainBottomTabs'; -import { LightningCustodianWallet } from './class'; -let BlueApp = require('./BlueApp'); export default class App extends React.Component { navigator = null; @@ -29,33 +26,25 @@ export default class App extends React.Component { return; } if (event.url.indexOf('bitcoin:') === 0 || event.url.indexOf('BITCOIN:') === 0) { - if (BlueApp.getWallets().map(item => item.type !== new LightningCustodianWallet().type).length > 1) { - this.navigator && - this.navigator.dispatch( - NavigationActions.navigate({ - routeName: 'SendDetails', - params: { - uri: event.url, - }, - }), - ); - } else { - alert('Before sending Bitcoins, you must first add a Bitcoin wallet.'); - } + this.navigator && + this.navigator.dispatch( + NavigationActions.navigate({ + routeName: 'SendDetails', + params: { + uri: event.url, + }, + }), + ); } else if (event.url.indexOf('lightning:') === 0 || event.url.indexOf('LIGHTNING:') === 0) { - if (BlueApp.getWallets().map(item => item.type === new LightningCustodianWallet().type).length > 1) { - this.navigator && - this.navigator.dispatch( - NavigationActions.navigate({ - routeName: 'ScanLndInvoice', - params: { - uri: event.url, - }, - }), - ); - } else { - alert('Before paying a Lightning invoice, you must first add a Lightning wallet.'); - } + this.navigator && + this.navigator.dispatch( + NavigationActions.navigate({ + routeName: 'ScanLndInvoice', + params: { + uri: event.url, + }, + }), + ); } }; diff --git a/models/fiatUnit.js b/models/fiatUnit.js index f0541360b..0da32431d 100644 --- a/models/fiatUnit.js +++ b/models/fiatUnit.js @@ -7,4 +7,4 @@ export const FiatUnit = Object.freeze({ CNY: { endPointKey: 'CNY', symbol: '¥', locale: 'zh-CN' }, JPY: { endPointKey: 'JPY', symbol: '¥', locale: 'ja-JP' }, INR: { endPointKey: 'INR', symbol: '₹', locale: 'hi-HN' }, -}); \ No newline at end of file +}); diff --git a/screen/lnd/lndViewAdditionalInvoiceInformation.js b/screen/lnd/lndViewAdditionalInvoiceInformation.js index 0bc4bb814..45eae2f78 100644 --- a/screen/lnd/lndViewAdditionalInvoiceInformation.js +++ b/screen/lnd/lndViewAdditionalInvoiceInformation.js @@ -11,7 +11,7 @@ const loc = require('../../loc'); export default class LNDViewAdditionalInvoiceInformation extends Component { static navigationOptions = ({ navigation }) => ({ ...BlueNavigationStyle(navigation, true, () => navigation.dismiss()), - title: "Additional Information", + title: 'Additional Information', }); state = { walletInfo: undefined }; diff --git a/screen/lnd/scanLndInvoice.js b/screen/lnd/scanLndInvoice.js index eb6903830..abe507bdf 100644 --- a/screen/lnd/scanLndInvoice.js +++ b/screen/lnd/scanLndInvoice.js @@ -25,29 +25,34 @@ export default class ScanLndInvoice extends React.Component { constructor(props) { super(props); - let fromSecret; - if (props.navigation.state.params.fromSecret) fromSecret = props.navigation.state.params.fromSecret; - let fromWallet = {}; - if (!fromSecret) { - const lightningWallets = BlueApp.getWallets().filter(item => item.type === LightningCustodianWallet.type); - if (lightningWallets.length > 0) { - fromSecret = lightningWallets[0].getSecret(); + if (!BlueApp.getWallets().some(item => item.type === LightningCustodianWallet.type)) { + alert('Before paying a Lightning invoice, you must first add a Lightning wallet.'); + } else { + let fromSecret; + if (props.navigation.state.params.fromSecret) fromSecret = props.navigation.state.params.fromSecret; + let fromWallet = {}; + + if (!fromSecret) { + const lightningWallets = BlueApp.getWallets().filter(item => item.type === LightningCustodianWallet.type); + if (lightningWallets.length > 0) { + fromSecret = lightningWallets[0].getSecret(); + } } - } - for (let w of BlueApp.getWallets()) { - if (w.getSecret() === fromSecret) { - fromWallet = w; - break; + for (let w of BlueApp.getWallets()) { + if (w.getSecret() === fromSecret) { + fromWallet = w; + break; + } } - } - this.state = { - fromWallet, - fromSecret, - destination: '', - }; + this.state = { + fromWallet, + fromSecret, + destination: '', + }; + } } async componentDidMount() { diff --git a/screen/send/details.js b/screen/send/details.js index 2c68673ac..f2223ceb2 100644 --- a/screen/send/details.js +++ b/screen/send/details.js @@ -22,6 +22,7 @@ import BitcoinBIP70TransactionDecode from '../../bip70/bip70'; import { BitcoinUnit } from '../../models/bitcoinUnits'; import { HDLegacyP2PKHWallet, HDSegwitP2SHWallet } from '../../class'; import ReactNativeHapticFeedback from 'react-native-haptic-feedback'; +import { LightningCustodianWallet } from '../../class/lightning-custodian-wallet'; const bip21 = require('bip21'); let EV = require('../../events'); let BigNumber = require('bignumber.js'); @@ -40,46 +41,51 @@ export default class SendDetails extends Component { constructor(props) { super(props); - console.log('props.navigation.state.params=', props.navigation.state.params); - let address; - let memo; - if (props.navigation.state.params) address = props.navigation.state.params.address; - if (props.navigation.state.params) memo = props.navigation.state.params.memo; - let fromAddress; - if (props.navigation.state.params) fromAddress = props.navigation.state.params.fromAddress; - let fromSecret; - if (props.navigation.state.params) fromSecret = props.navigation.state.params.fromSecret; - let fromWallet = null; - const wallets = BlueApp.getWallets(); - for (let w of wallets) { - if (w.getSecret() === fromSecret) { - fromWallet = w; - break; + if (!BlueApp.getWallets().some(item => item.type !== LightningCustodianWallet.type)) { + alert('Before sending Bitcoins, you must first add a Bitcoin wallet.'); + props.navigation.goBack(); + } else { + console.log('props.navigation.state.params=', props.navigation.state.params); + let address; + let memo; + if (props.navigation.state.params) address = props.navigation.state.params.address; + if (props.navigation.state.params) memo = props.navigation.state.params.memo; + let fromAddress; + if (props.navigation.state.params) fromAddress = props.navigation.state.params.fromAddress; + let fromSecret; + if (props.navigation.state.params) fromSecret = props.navigation.state.params.fromSecret; + let fromWallet = null; + + for (let w of wallets) { + if (w.getSecret() === fromSecret) { + fromWallet = w; + break; + } + + if (w.getAddress() === fromAddress) { + fromWallet = w; + } } - if (w.getAddress() === fromAddress) { - fromWallet = w; - } + // fallback to first wallet if it exists + if (!fromWallet && wallets[0]) fromWallet = wallets[0]; + + this.state = { + isFeeSelectionModalVisible: false, + fromAddress, + fromWallet, + fromSecret, + isLoading: true, + address, + memo, + fee: 1, + networkTransactionFees: new NetworkTransactionFee(1, 1, 1), + feeSliderValue: 1, + bip70TransactionExpiration: null, + }; } - - // fallback to first wallet if it exists - if (!fromWallet && wallets[0]) fromWallet = wallets[0]; - - this.state = { - isFeeSelectionModalVisible: false, - fromAddress, - fromWallet, - fromSecret, - isLoading: true, - address, - memo, - fee: 1, - networkTransactionFees: new NetworkTransactionFee(1, 1, 1), - feeSliderValue: 1, - bip70TransactionExpiration: null, - }; } async componentDidMount() { diff --git a/screen/wallets/add.js b/screen/wallets/add.js index e2bfaa144..5df7c0c4f 100644 --- a/screen/wallets/add.js +++ b/screen/wallets/add.js @@ -186,7 +186,6 @@ export default class WalletsAdd extends Component { width: width / 1.5, }} onPress={() => { - this.props.navigation.goBack(); setTimeout(async () => { let w; @@ -236,6 +235,7 @@ export default class WalletsAdd extends Component { EV(EV.enum.WALLETS_COUNT_CHANGED); A(A.ENUM.CREATED_WALLET); ReactNativeHapticFeedback.trigger('notificationSuccess', false); + this.props.navigation.dismiss(); }, 1); }} /> @@ -258,5 +258,6 @@ WalletsAdd.propTypes = { navigation: PropTypes.shape({ navigate: PropTypes.func, goBack: PropTypes.func, + dismiss: PropTypes.func, }), };