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:
parent
6bf81df271
commit
63d88865e5
|
@ -133,6 +133,7 @@ const SendModal = ({
|
|||
|
||||
{activeScreen === 'sendFunds' && (
|
||||
<SendFunds
|
||||
initialValues={tx as ReviewTxProp}
|
||||
onClose={onClose}
|
||||
onReview={handleTxCreation}
|
||||
recipientAddress={recipientAddress}
|
||||
|
|
|
@ -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}
|
||||
>
|
||||
|
|
Loading…
Reference in New Issue