From 0acf574dd7bdfa26db6cef1d99ae21e6fecdff93 Mon Sep 17 00:00:00 2001 From: katspaugh <381895+katspaugh@users.noreply.github.com> Date: Sat, 23 Apr 2022 15:34:37 +0200 Subject: [PATCH] Fix SendAssetsForm (#24) --- components/tx/ReviewTx/index.tsx | 13 +++---------- components/tx/SendAssetsForm/index.tsx | 15 ++++++++------- components/tx/TxModal/index.tsx | 12 ++++++------ components/tx/TxStepper/index.tsx | 6 +++--- 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/components/tx/ReviewTx/index.tsx b/components/tx/ReviewTx/index.tsx index 05485e5d5b..47fc2867d6 100644 --- a/components/tx/ReviewTx/index.tsx +++ b/components/tx/ReviewTx/index.tsx @@ -51,9 +51,7 @@ const ReviewTx = ({ register, handleSubmit, formState: { errors }, - } = useForm({ - defaultValues: { nonce: safeGas?.recommendedNonce || 0 }, - }) + } = useForm() const onFormSubmit = async (data: ReviewTxForm) => { if (!txParams) return @@ -73,12 +71,6 @@ const ReviewTx = ({ } } - const validateNonce = (userNonce: number) => { - if (!Number.isInteger(userNonce)) { - return 'Nonce must be a number' - } - } - return (
Review transaction @@ -92,9 +84,10 @@ const ReviewTx = ({ error={!!errors.nonce} helperText={errors.nonce?.message} type="number" + key={safeGas?.recommendedNonce} + defaultValue={safeGas?.recommendedNonce} {...register('nonce', { valueAsNumber: true, // Set field to number type to auto parseInt - validate: validateNonce, required: true, })} /> diff --git a/components/tx/SendAssetsForm/index.tsx b/components/tx/SendAssetsForm/index.tsx index 97f56ab362..b500ae1904 100644 --- a/components/tx/SendAssetsForm/index.tsx +++ b/components/tx/SendAssetsForm/index.tsx @@ -14,7 +14,12 @@ export type SendAssetsFormData = { amount: string } -const SendAssetsForm = ({ onSubmit }: { onSubmit: (formData: SendAssetsFormData) => void }): ReactElement => { +type SendAssetsFormProps = { + formData?: SendAssetsFormData + onSubmit: (formData: SendAssetsFormData) => void +} + +const SendAssetsForm = ({ onSubmit, formData }: SendAssetsFormProps): ReactElement => { const balances = useBalances() const { @@ -23,11 +28,7 @@ const SendAssetsForm = ({ onSubmit }: { onSubmit: (formData: SendAssetsFormData) getValues, formState: { errors }, } = useForm({ - defaultValues: { - recepient: '', - tokenAddress: '', - amount: '', - }, + defaultValues: formData, }) const validateAmount = (amount: string) => { @@ -60,7 +61,7 @@ const SendAssetsForm = ({ onSubmit }: { onSubmit: (formData: SendAssetsFormData)