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

Commit

Permalink
refactor: fetching form values from form state
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfelton committed May 14, 2020
1 parent 22b92e9 commit 2fae06e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 5 additions & 4 deletions renderer/components/Form/LightningInvoiceInput.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useCallback } from 'react'
import PropTypes from 'prop-types'
import { FormattedMessage, useIntl } from 'react-intl'
import { useFieldState } from 'informed'
import { useFormState } from 'informed'
import { isOnchain, isBolt11, isPubkey, decodePayReq } from '@zap/utils/crypto'
import { Message } from 'components/UI'
import TextArea from './TextArea'
Expand Down Expand Up @@ -43,8 +43,9 @@ const validate = (intl, network, chain, value) => {
const LightningInvoiceInput = props => {
const { network, chain, field } = props
const intl = useIntl()
const fieldState = useFieldState(field)
const { value } = fieldState
const { values, errors } = useFormState()
const value = values && values[field]
const error = errors && errors[field]
let chainName = isBolt11(value, chain, network) || isPubkey(value) ? 'lightning' : chain
if (network !== 'mainnet') {
chainName += ` (${network})`
Expand All @@ -59,7 +60,7 @@ const LightningInvoiceInput = props => {
return (
<>
<TextArea mask={mask} validate={doValidate} {...props} validateOnBlur validateOnChange />
{value && !fieldState.error && (
{value && !error && (
<Message mt={2} variant="success">
<FormattedMessage
{...messages[isPubkey(value) ? 'valid_pubkey' : 'valid_request']}
Expand Down
6 changes: 4 additions & 2 deletions renderer/components/Pay/Pay.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ class Pay extends React.Component {
const { cryptoUnit } = this.props
// Get crypto amount from the form and default to zero if it hasn't been set yet
// otherwise you can end-up with amount equal to undefined
const amount = this.formApi.getValue('amountCrypto') || 0

const {
values: { amountCrypto = 0 },
} = this.formApi.getState()
const amount = amountCrypto
return getAmountInSats(amount, cryptoUnit, invoice)
}

Expand Down

0 comments on commit 2fae06e

Please # to comment.