From 26dc40cb2e15b03db10eae67cb77c03c730a0b9a Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Sat, 11 Jul 2020 12:23:05 +0200 Subject: [PATCH] fix: update pay form fiat value on initial set --- renderer/components/Form/CurrencyFieldGroup.js | 11 ++++------- renderer/components/Pay/Pay.js | 9 ++++----- renderer/components/Pay/PayPanelFooter.js | 4 ++++ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/renderer/components/Form/CurrencyFieldGroup.js b/renderer/components/Form/CurrencyFieldGroup.js index 055a0d6175f..f2202a0d533 100644 --- a/renderer/components/Form/CurrencyFieldGroup.js +++ b/renderer/components/Form/CurrencyFieldGroup.js @@ -46,11 +46,8 @@ const CurrencyFieldGroup = React.forwardRef( blockUpdates.current = true } - // informed calls onValueChange multiple time during value updates - // because of masks and patterns applied on top of UI elements - // give value a chance to settle before enabling updates again - const unblockLinkedUpdates = async () => { - await Promise.resolve() + // Enable updates of linked form values. + const unblockLinkedUpdates = () => { blockUpdates.current = false } @@ -70,7 +67,7 @@ const CurrencyFieldGroup = React.forwardRef( const lastPrice = currentTicker[fiatCurrency] const fiatValue = convert(cryptoUnit, 'fiat', value, lastPrice) formApi.setValue('amountFiat', fiatValue) - await unblockLinkedUpdates() + unblockLinkedUpdates() } onChange && onChange() } @@ -86,7 +83,7 @@ const CurrencyFieldGroup = React.forwardRef( const lastPrice = currentTicker[fiatCurrency] const cryptoValue = convert('fiat', cryptoUnit, value, lastPrice) formApi.setValue('amountCrypto', cryptoValue) - await unblockLinkedUpdates() + unblockLinkedUpdates() } onChange && onChange() } diff --git a/renderer/components/Pay/Pay.js b/renderer/components/Pay/Pay.js index 83976383c21..348b7035955 100644 --- a/renderer/components/Pay/Pay.js +++ b/renderer/components/Pay/Pay.js @@ -121,11 +121,10 @@ class Pay extends React.Component { const isNowBip21 = bip21decoded && bip21decoded !== prevState.bip21decoded if (currentStep === PAY_FORM_STEPS.address && isNowBip21) { this.formApi.reset() - this.formApi.setValue('payReq', bip21decoded.address) - this.formApi.setValue( - 'amountCrypto', - convert('btc', cryptoUnit, get(bip21decoded, 'options.amount')) - ) + this.formApi.setValues({ + payReq: bip21decoded.address, + amountCrypto: convert('btc', cryptoUnit, get(bip21decoded, 'options.amount')), + }) this.formApi.submitForm() return } diff --git a/renderer/components/Pay/PayPanelFooter.js b/renderer/components/Pay/PayPanelFooter.js index 994b3811f0b..bb97cc9010f 100644 --- a/renderer/components/Pay/PayPanelFooter.js +++ b/renderer/components/Pay/PayPanelFooter.js @@ -15,6 +15,10 @@ const isEnoughFunds = props => { // convert entered amount to satoshis const { amountInSats, channelBalance, invoice, paymentType, walletBalanceConfirmed } = props + if (amountInSats === 'NaN') { + return true + } + // Determine whether we have enough funds available. let hasEnoughFunds = true const isBolt11 = paymentType === PAYMENT_TYPES.bolt11