ADD: Same success screen from onchain tx now used for offchain

This commit is contained in:
Marcos Rodriguez Vélez 2019-01-31 19:59:49 -05:00
parent 928ae7c307
commit a86bc1258d
3 changed files with 55 additions and 46 deletions

View file

@ -180,6 +180,15 @@ const CreateWalletStackNavigator = createStackNavigator({
}, },
}); });
const LightningScanInvoiceStackNavigator = createStackNavigator({
ScanLndInvoice: {
screen: ScanLndInvoice,
},
Success: {
screen: Success,
},
});
const MainBottomTabs = createStackNavigator( const MainBottomTabs = createStackNavigator(
{ {
Wallets: { Wallets: {
@ -236,7 +245,10 @@ const MainBottomTabs = createStackNavigator(
}, },
}, },
ScanLndInvoice: { ScanLndInvoice: {
screen: ScanLndInvoice, screen: LightningScanInvoiceStackNavigator,
navigationOptions: {
header: null,
},
}, },
ScanQrAddress: { ScanQrAddress: {
screen: sendScanQrAddress, screen: sendScanQrAddress,

View file

@ -72,12 +72,6 @@ export default class ScanLndInvoice extends React.Component {
processInvoice = data => { processInvoice = data => {
this.setState({ isLoading: true }, async () => { this.setState({ isLoading: true }, async () => {
if (this.ignoreRead) return;
this.ignoreRead = true;
setTimeout(() => {
this.ignoreRead = false;
}, 6000);
if (!this.state.fromWallet) { if (!this.state.fromWallet) {
alert('Before paying a Lightning invoice, you must first add a Lightning wallet.'); alert('Before paying a Lightning invoice, you must first add a Lightning wallet.');
return this.props.navigation.goBack(); return this.props.navigation.goBack();
@ -149,11 +143,8 @@ export default class ScanLndInvoice extends React.Component {
return alert(loc.lnd.sameWalletAsInvoiceError); return alert(loc.lnd.sameWalletAsInvoiceError);
} }
let start = +new Date();
let end;
try { try {
await fromWallet.payInvoice(this.state.invoice, this.state.decoded.num_satoshis); await fromWallet.payInvoice(this.state.invoice, this.state.decoded.num_satoshis);
end = +new Date();
} catch (Err) { } catch (Err) {
console.log(Err.message); console.log(Err.message);
this.setState({ isLoading: false }); this.setState({ isLoading: false });
@ -161,11 +152,12 @@ export default class ScanLndInvoice extends React.Component {
return alert('Error'); return alert('Error');
} }
console.log('payInvoice took', (end - start) / 1000, 'sec');
EV(EV.enum.REMOTE_TRANSACTIONS_COUNT_CHANGED); // someone should fetch txs EV(EV.enum.REMOTE_TRANSACTIONS_COUNT_CHANGED); // someone should fetch txs
this.props.navigation.navigate('Success', {
alert('Success'); amount: this.state.decoded.num_satoshis,
this.props.navigation.goBack(); amountUnit: BitcoinUnit.SATS,
dismissModal: () => this.props.navigation.dismiss(),
});
}, },
); );
} }
@ -237,24 +229,26 @@ export default class ScanLndInvoice extends React.Component {
)} )}
<BlueSpacing20 /> <BlueSpacing20 />
<BlueSpacing20 /> <BlueSpacing20 />
{this.state.isLoading ? ( <BlueCard>
<View> {this.state.isLoading ? (
<ActivityIndicator /> <View>
</View> <ActivityIndicator />
) : ( </View>
<BlueButton ) : (
icon={{ <BlueButton
name: 'bolt', icon={{
type: 'font-awesome', name: 'bolt',
color: BlueApp.settings.buttonTextColor, type: 'font-awesome',
}} color: BlueApp.settings.buttonTextColor,
title={'Pay'} }}
onPress={() => { title={'Pay'}
this.pay(); onPress={() => {
}} this.pay();
disabled={this.shouldDisablePayButton()} }}
/> disabled={this.shouldDisablePayButton()}
)} />
)}
</BlueCard>
</BlueCard> </BlueCard>
</SafeBlueArea> </SafeBlueArea>
</TouchableWithoutFeedback> </TouchableWithoutFeedback>

View file

@ -18,7 +18,8 @@ export default class Success extends Component {
this.state = { this.state = {
amount: props.navigation.getParam('amount'), amount: props.navigation.getParam('amount'),
fee: props.navigation.getParam('fee'), fee: props.navigation.getParam('fee') || 0,
amountUnit: props.navigation.getParam('amountUnit') || BitcoinUnit.BTC,
}; };
} }
@ -51,21 +52,23 @@ export default class Success extends Component {
alignSelf: 'flex-end', alignSelf: 'flex-end',
}} }}
> >
{' ' + BitcoinUnit.BTC} {' ' + this.state.amountUnit}
</Text> </Text>
</View> </View>
<Text {this.state.fee > 0 && (
style={{ <Text
color: '#37c0a1', style={{
fontSize: 14, color: '#37c0a1',
marginHorizontal: 4, fontSize: 14,
paddingBottom: 6, marginHorizontal: 4,
fontWeight: '500', paddingBottom: 6,
alignSelf: 'center', fontWeight: '500',
}} alignSelf: 'center',
> }}
{loc.send.create.fee}: {loc.formatBalance(this.state.fee, BitcoinUnit.SATS)} >
</Text> {loc.send.create.fee}: {loc.formatBalance(this.state.fee, BitcoinUnit.SATS)}
</Text>
)}
</BlueCard> </BlueCard>
<View <View
style={{ style={{