mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-20 02:09:10 +01:00
ADD: Manages LND funds using new wallet selector
This commit is contained in:
parent
3baf4a439a
commit
fd46fa4476
@ -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',
|
||||
|
@ -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 <BlueLoading />;
|
||||
}
|
||||
|
||||
return (
|
||||
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={{ flex: 1 }}>
|
||||
<BlueSpacingVariable />
|
||||
|
||||
<BlueCard>
|
||||
{(() => {
|
||||
if (this.state.isRefill) {
|
||||
return (
|
||||
<View>
|
||||
<Dropdown
|
||||
label={loc.lnd.choose_source_wallet}
|
||||
data={data}
|
||||
onChangeText={async value => {
|
||||
/** @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');
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<View>
|
||||
<ListItem
|
||||
titleStyle={{ color: BlueApp.settings.foregroundColor }}
|
||||
component={TouchableOpacity}
|
||||
onPress={a => {
|
||||
this.setState({ isRefill: true });
|
||||
}}
|
||||
title={loc.lnd.refill}
|
||||
/>
|
||||
<ListItem
|
||||
titleStyle={{ color: BlueApp.settings.foregroundColor }}
|
||||
component={TouchableOpacity}
|
||||
onPress={a => {
|
||||
alert('Coming soon');
|
||||
}}
|
||||
title={loc.lnd.withdraw}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
})()}
|
||||
<ListItem
|
||||
titleStyle={{ color: BlueApp.settings.foregroundColor }}
|
||||
component={TouchableOpacity}
|
||||
onPress={a => {
|
||||
this.props.navigation.navigate('SelectWallet', { onWalletSelect: this.onWalletSelect });
|
||||
}}
|
||||
title={loc.lnd.refill}
|
||||
/>
|
||||
<ListItem
|
||||
titleStyle={{ color: BlueApp.settings.foregroundColor }}
|
||||
component={TouchableOpacity}
|
||||
onPress={a => {
|
||||
alert('Coming soon');
|
||||
}}
|
||||
title={loc.lnd.withdraw}
|
||||
/>
|
||||
|
||||
<View />
|
||||
</BlueCard>
|
||||
@ -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,
|
||||
|
@ -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 });
|
||||
}}
|
||||
>
|
||||
<BlueText style={{ fontWeight: '600', fontSize: 16 }}>{loc.lnd.title}</BlueText>
|
||||
@ -587,7 +587,7 @@ export default class WalletTransactions extends Component {
|
||||
<ManageFundsBigButton
|
||||
onPress={() => {
|
||||
console.log('navigating to', this.state.wallet.getLabel());
|
||||
navigate('ManageFunds', { fromSecret: this.state.wallet.getSecret() });
|
||||
navigate('ManageFunds', { fromWallet: this.state.wallet });
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user