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' && ( {activeScreen === 'sendFunds' && (
<SendFunds <SendFunds
initialValues={tx as ReviewTxProp}
onClose={onClose} onClose={onClose}
onReview={handleTxCreation} onReview={handleTxCreation}
recipientAddress={recipientAddress} recipientAddress={recipientAddress}

View File

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