diff --git a/MainBottomTabs.js b/MainBottomTabs.js index ae1f1f4d7..f92f285ba 100644 --- a/MainBottomTabs.js +++ b/MainBottomTabs.js @@ -132,6 +132,21 @@ const CreateTransactionStackNavigator = createStackNavigator({ }, }); +const ManageFundsStackNavigator = createStackNavigator({ + ManageFunds: { + screen: ManageFunds, + }, + SelectWallet: { + screen: SelectWallet, + }, + SendDetails: { + screen: CreateTransactionStackNavigator, + navigationOptions: { + header: null, + }, + }, +}); + const LNDViewInvoiceStackNavigator = createStackNavigator({ LNDViewInvoice: { screen: LNDViewInvoice, @@ -212,7 +227,10 @@ const MainBottomTabs = createStackNavigator( // LND: ManageFunds: { - screen: ManageFunds, + screen: ManageFundsStackNavigator, + navigationOptions: { + header: null, + }, }, ScanLndInvoice: { screen: ScanLndInvoice, @@ -239,10 +257,6 @@ const MainBottomTabs = createStackNavigator( }, }, // Select Wallet. Mostly for deep-linking - - SelectWallet: { - screen: SelectWallet, - }, }, { mode: 'modal', diff --git a/screen/lnd/manageFunds.js b/screen/lnd/manageFunds.js index 87b28c6ff..b9f0f35b6 100644 --- a/screen/lnd/manageFunds.js +++ b/screen/lnd/manageFunds.js @@ -1,17 +1,13 @@ /* global alert */ import React, { Component } from 'react'; import { TouchableOpacity, View } from 'react-native'; -import { Dropdown } from 'react-native-material-dropdown'; -import { BlueSpacingVariable, BlueNavigationStyle, BlueLoading, SafeBlueArea, BlueCard } from '../../BlueComponents'; +import { BlueSpacingVariable, BlueNavigationStyle, SafeBlueArea, BlueCard } from '../../BlueComponents'; import { ListItem } from 'react-native-elements'; import PropTypes from 'prop-types'; -import { LightningCustodianWallet } from '../../class/lightning-custodian-wallet'; /** @type {AppStorage} */ let BlueApp = require('../../BlueApp'); let loc = require('../../loc'); -let data = []; - export default class ManageFunds extends Component { static navigationOptions = ({ navigation }) => ({ ...BlueNavigationStyle(navigation, true), @@ -21,118 +17,62 @@ export default class ManageFunds extends Component { constructor(props) { super(props); - let fromSecret; - if (props.navigation.state.params.fromSecret) fromSecret = props.navigation.state.params.fromSecret; - let fromWallet = false; + this.onWalletSelect = this.onWalletSelect.bind(this); - for (let w of BlueApp.getWallets()) { - if (w.getSecret() === fromSecret) { - fromWallet = w; - break; - } - } - - if (fromWallet) { - console.log(fromWallet.type); - } - - this.state = { - fromWallet, - fromSecret, - isLoading: true, - }; + this.state = { fromWallet: props.navigation.getParam('fromWallet') } } - async componentDidMount() { - data = []; - for (let c = 0; c < BlueApp.getWallets().length; c++) { - let w = BlueApp.getWallets()[c]; - if (w.type !== LightningCustodianWallet.type) { - data.push({ - value: c, - label: w.getLabel() + ' (' + w.getBalance() + ' BTC)', - }); + async onWalletSelect(wallet) { + this.props.navigation.dismiss() + /** @type {LightningCustodianWallet} */ + let toAddress = false; + if (this.state.fromWallet.refill_addressess.length > 0) { + toAddress = this.state.fromWallet.refill_addressess[0]; + } else { + try { + await this.state.fromWallet.fetchBtcAddress(); + toAddress = this.state.fromWallet.refill_addressess[0]; + } catch (Err) { + return alert(Err.message); } } - this.setState({ - isLoading: false, - }); + if (wallet) { + setTimeout(() => { + this.props.navigation.navigate('SendDetails', { + memo: loc.lnd.refill_lnd_balance, + fromSecret: wallet.getSecret(), + address: toAddress, + }); + }, 100); + + } else { + return alert('Internal error'); + } } render() { - if (this.state.isLoading) { - return ; - } - return ( - {(() => { - if (this.state.isRefill) { - return ( - - { - /** @type {LightningCustodianWallet} */ - let fromWallet = this.state.fromWallet; - let toAddress = false; - if (fromWallet.refill_addressess.length > 0) { - toAddress = fromWallet.refill_addressess[0]; - } else { - try { - await fromWallet.fetchBtcAddress(); - toAddress = fromWallet.refill_addressess[0]; - } catch (Err) { - return alert(Err.message); - } - } - - let wallet = BlueApp.getWallets()[value]; - if (wallet) { - console.log(wallet.getSecret()); - setTimeout(() => { - console.log({ toAddress }); - this.props.navigation.navigate('SendDetails', { - memo: loc.lnd.refill_lnd_balance, - fromSecret: wallet.getSecret(), - address: toAddress, - }); - }, 750); - } else { - return alert('Internal error'); - } - }} - /> - - ); - } else { - return ( - - { - this.setState({ isRefill: true }); - }} - title={loc.lnd.refill} - /> - { - alert('Coming soon'); - }} - title={loc.lnd.withdraw} - /> - - ); - } - })()} + { + this.props.navigation.navigate('SelectWallet', { onWalletSelect: this.onWalletSelect }); + }} + title={loc.lnd.refill} + /> + { + alert('Coming soon'); + }} + title={loc.lnd.withdraw} + /> @@ -145,6 +85,7 @@ ManageFunds.propTypes = { navigation: PropTypes.shape({ goBack: PropTypes.function, navigate: PropTypes.function, + getParam: PropTypes.function, state: PropTypes.shape({ params: PropTypes.shape({ fromSecret: PropTypes.string, diff --git a/screen/wallets/transactions.js b/screen/wallets/transactions.js index 5a73b1ad1..71aa769aa 100644 --- a/screen/wallets/transactions.js +++ b/screen/wallets/transactions.js @@ -369,7 +369,7 @@ export default class WalletTransactions extends Component { style={{ alignSelf: 'flex-end', right: 10, flexDirection: 'row' }} onPress={() => { console.log('navigating to', this.state.wallet.getLabel()); - navigate('ManageFunds', { fromSecret: this.state.wallet.getSecret() }); + navigate('ManageFunds', { fromWallet: this.state.wallet }); }} > {loc.lnd.title} @@ -587,7 +587,7 @@ export default class WalletTransactions extends Component { { console.log('navigating to', this.state.wallet.getLabel()); - navigate('ManageFunds', { fromSecret: this.state.wallet.getSecret() }); + navigate('ManageFunds', { fromWallet: this.state.wallet }); }} /> );