From c0a137a965379fadb6d3859e822f02b5618ef0d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Rodriguez=20Ve=CC=81lez?= Date: Sun, 6 Jan 2019 15:21:04 -0500 Subject: [PATCH] FIX: Fix issue with typing amounts --- BlueComponents.js | 13 +++--- ios/BlueWallet/Info.plist | 2 +- screen/lnd/scanLndInvoice.js | 82 +++++++++++++++++++----------------- 3 files changed, 49 insertions(+), 48 deletions(-) diff --git a/BlueComponents.js b/BlueComponents.js index c1d3da6e4..8e7f972f0 100644 --- a/BlueComponents.js +++ b/BlueComponents.js @@ -1131,14 +1131,12 @@ export class BlueBitcoinAmount extends Component { - this.props.onChangeText( - this.props.unit === BitcoinUnit.BTC - ? text.replace(new RegExp('[^0-9.]'), '', '.') - : text.replace(new RegExp('[^0-9]'), ''), - ) - } + onChangeText={text => { + text = this.props.unit === BitcoinUnit.BTC ? text.replace(/[^0-9.]/g, '') : text.replace(/[^0-9]/g, ''); + this.props.onChangeText(text); + }} placeholder="0" maxLength={10} ref={textInput => (this.textInput = textInput)} @@ -1150,7 +1148,6 @@ export class BlueBitcoinAmount extends Component { fontSize: 36, fontWeight: '600', }} - {...this.props} /> CFBundleVersion - 217 + 218 ITSAppUsesNonExemptEncryption LSRequiresIPhoneOS diff --git a/screen/lnd/scanLndInvoice.js b/screen/lnd/scanLndInvoice.js index ea931b460..e8b8b0ea6 100644 --- a/screen/lnd/scanLndInvoice.js +++ b/screen/lnd/scanLndInvoice.js @@ -71,46 +71,50 @@ export default class ScanLndInvoice extends React.Component { } } - async processInvoice(data) { - if (this.ignoreRead) return; - this.ignoreRead = true; - setTimeout(() => { - this.ignoreRead = false; - }, 6000); + 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(); - } - - data = data.replace('LIGHTNING:', '').replace('lightning:', ''); - console.log(data); - - /** - * @type {LightningCustodianWallet} - */ - let w = this.state.fromWallet; - let decoded; - try { - decoded = await w.decodeInvoice(data); - - let expiresIn = (decoded.timestamp * 1 + decoded.expiry * 1) * 1000; // ms - if (+new Date() > expiresIn) { - expiresIn = 'expired'; - } else { - expiresIn = Math.round((expiresIn - +new Date()) / (60 * 1000)) + ' min'; + if (!this.state.fromWallet) { + alert('Before paying a Lightning invoice, you must first add a Lightning wallet.'); + return this.props.navigation.goBack(); } - Keyboard.dismiss(); - this.setState({ - invoice: data, - decoded, - expiresIn, - destination: data, - isAmountInitiallyEmpty: decoded.num_satoshis === '0', - }); - } catch (Err) { - alert(Err.message); - } + + data = data.replace('LIGHTNING:', '').replace('lightning:', ''); + console.log(data); + + /** + * @type {LightningCustodianWallet} + */ + let w = this.state.fromWallet; + let decoded; + try { + decoded = await w.decodeInvoice(data); + + let expiresIn = (decoded.timestamp * 1 + decoded.expiry * 1) * 1000; // ms + if (+new Date() > expiresIn) { + expiresIn = 'expired'; + } else { + expiresIn = Math.round((expiresIn - +new Date()) / (60 * 1000)) + ' min'; + } + Keyboard.dismiss(); + this.setState({ + invoice: data, + decoded, + expiresIn, + destination: data, + isAmountInitiallyEmpty: decoded.num_satoshis === '0', + isLoading: false, + }); + } catch (Err) { + this.setState({ isLoading: false }); + alert(Err.message); + } + }); } async pay() { @@ -190,7 +194,7 @@ export default class ScanLndInvoice extends React.Component { amount={typeof this.state.decoded === 'object' ? this.state.decoded.num_satoshis : 0} onChangeText={text => { if (typeof this.state.decoded === 'object') { - text = parseInt(text); + text = parseInt(text || 0); let decoded = this.state.decoded; decoded.num_satoshis = text; this.setState({ decoded: decoded });