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(
{
Wallets: {
@ -236,7 +245,10 @@ const MainBottomTabs = createStackNavigator(
},
},
ScanLndInvoice: {
screen: ScanLndInvoice,
screen: LightningScanInvoiceStackNavigator,
navigationOptions: {
header: null,
},
},
ScanQrAddress: {
screen: sendScanQrAddress,

View file

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

View file

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