Bugfix - Back button in modal resets form (#2075)

* Use initialValues on SendFunds modal

Co-authored-by: Daniel Sanchez <daniel.sanchez@gnosis.pm>
This commit is contained in:
Mati Dastugue 2021-03-24 05:44:20 -03:00 committed by GitHub
parent 6bf81df271
commit 63d88865e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -133,6 +133,7 @@ const SendModal = ({
{activeScreen === 'sendFunds' && (
<SendFunds
initialValues={tx as ReviewTxProp}
onClose={onClose}
onReview={handleTxCreation}
recipientAddress={recipientAddress}

View File

@ -68,6 +68,7 @@ export type SendFundsTx = {
}
type SendFundsProps = {
initialValues: SendFundsTx
onClose: () => void
onReview: (txInfo: unknown) => void
recipientAddress?: string
@ -80,6 +81,7 @@ const InputAdornmentChildSymbol = ({ symbol }: { symbol?: string }): ReactElemen
}
const SendFunds = ({
initialValues,
onClose,
onReview,
recipientAddress,
@ -93,12 +95,14 @@ const SendFunds = ({
const defaultEntry = { address: recipientAddress || '', name: '' }
// if there's nothing to lookup for, we return the default entry
if (!recipientAddress) {
if (!initialValues?.recipientAddress && !recipientAddress) {
return defaultEntry
}
// if there's something to lookup for, `initialValues` has precedence over `recipientAddress`
const predefinedAddress = initialValues?.recipientAddress ?? recipientAddress
const addressBookEntry = addressBook.find(({ address }) => {
return sameAddress(recipientAddress, address)
return sameAddress(predefinedAddress, address)
})
// if found in the Address Book, then we return the entry
@ -170,7 +174,11 @@ const SendFunds = ({
<Hairline />
<GnoForm
formMutators={formMutators}
initialValues={{ amount, recipientAddress, token: selectedToken }}
initialValues={{
amount: initialValues?.amount || amount,
recipientAddress: initialValues.recipientAddress || recipientAddress,
token: initialValues?.token || selectedToken,
}}
onSubmit={handleSubmit}
validation={sendFundsValidation}
>