If invoice object passed, show the UI right away.

This commit is contained in:
Marcos Rodriguez Vélez 2018-12-27 19:26:46 -05:00
parent 5efbd2ca9f
commit 02db2d20eb
2 changed files with 30 additions and 22 deletions

View file

@ -33,7 +33,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>180</string>
<string>181</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSRequiresIPhoneOS</key>

View file

@ -1,3 +1,4 @@
/* global alert */
import React, { Component } from 'react';
import { Animated, StyleSheet, View, TouchableOpacity, Clipboard, Share } from 'react-native';
// import { QRCode } from 'react-native-custom-qr-codes';
@ -24,7 +25,7 @@ export default class LNDViewInvoice extends Component {
this.state = {
invoice,
fromWallet,
isLoading: true,
isLoading: typeof invoice === 'string',
addressText: typeof invoice === 'object' ? invoice.payment_request : invoice,
isFetchingInvoices: false,
};
@ -34,31 +35,37 @@ export default class LNDViewInvoice extends Component {
async componentDidMount() {
this.fetchInvoiceInterval = setInterval(async () => {
if (!this.state.isFetchingInvoices) {
this.setState({ isFetchingInvoices: true });
const userInvoices = JSON.stringify(await this.state.fromWallet.getUserInvoices());
const updatedUserInvoice = JSON.parse(userInvoices).filter(invoice =>
typeof this.state.invoice === 'object'
? invoice.payment_request === this.state.invoice.payment_request
: invoice.payment_request === this.state.invoice,
)[0];
this.setState({ invoice: updatedUserInvoice, isLoading: false });
if (updatedUserInvoice.ispaid) {
this.setState({ isFetchingInvoices: false });
ReactNativeHapticFeedback.trigger('notificationSuccess', false);
clearInterval(this.fetchInvoiceInterval);
this.fetchInvoiceInterval = undefined;
EV(EV.enum.TRANSACTIONS_COUNT_CHANGED);
} else {
const currentDate = new Date();
const now = (currentDate.getTime() / 1000) | 0;
const invoiceExpiration = updatedUserInvoice.timestamp + updatedUserInvoice.expire_time;
if (invoiceExpiration < now && !updatedUserInvoice.ispaid) {
try {
this.setState({ isFetchingInvoices: true });
const userInvoices = JSON.stringify(await this.state.fromWallet.getUserInvoices());
const updatedUserInvoice = JSON.parse(userInvoices).filter(invoice =>
typeof this.state.invoice === 'object'
? invoice.payment_request === this.state.invoice.payment_request
: invoice.payment_request === this.state.invoice,
)[0];
this.setState({ invoice: updatedUserInvoice, isLoading: false });
if (updatedUserInvoice.ispaid) {
this.setState({ isFetchingInvoices: false });
ReactNativeHapticFeedback.trigger('notificationError', false);
ReactNativeHapticFeedback.trigger('notificationSuccess', false);
clearInterval(this.fetchInvoiceInterval);
this.fetchInvoiceInterval = undefined;
EV(EV.enum.TRANSACTIONS_COUNT_CHANGED);
} else {
const currentDate = new Date();
const now = (currentDate.getTime() / 1000) | 0;
const invoiceExpiration = updatedUserInvoice.timestamp + updatedUserInvoice.expire_time;
if (invoiceExpiration < now && !updatedUserInvoice.ispaid) {
this.setState({ isFetchingInvoices: false });
ReactNativeHapticFeedback.trigger('notificationError', false);
clearInterval(this.fetchInvoiceInterval);
this.fetchInvoiceInterval = undefined;
EV(EV.enum.TRANSACTIONS_COUNT_CHANGED);
}
}
} catch (error) {
console.log(error);
alert(error);
this.props.navigation.dismiss();
}
}
}, 5000);
@ -168,5 +175,6 @@ LNDViewInvoice.propTypes = {
navigation: PropTypes.shape({
goBack: PropTypes.function,
getParam: PropTypes.function,
dismiss: PropTypes.function,
}),
};