Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
fix: update pay form fiat value on initial set
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfelton committed Jul 11, 2020
1 parent 8e56936 commit 26dc40c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
11 changes: 4 additions & 7 deletions renderer/components/Form/CurrencyFieldGroup.js
Expand Up @@ -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
}

Expand All @@ -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()
}
Expand All @@ -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()
}
Expand Down
9 changes: 4 additions & 5 deletions renderer/components/Pay/Pay.js
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions renderer/components/Pay/PayPanelFooter.js
Expand Up @@ -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
Expand Down

0 comments on commit 26dc40c

Please sign in to comment.