From 390d78083e8a8757c6c028aedbea68453dd4655f Mon Sep 17 00:00:00 2001 From: Diogo Soares <32431609+DiogoSoaress@users.noreply.github.com> Date: Mon, 9 Jan 2023 08:05:56 +0000 Subject: [PATCH] fix: trigger validation upon owner removal (#1477) * fix: trigger validation upon owner removal * trigger validation on remove owner. Fetch owners with getValues * trigger validation only for owners --- src/components/new-safe/OwnerRow/index.tsx | 3 ++- src/components/new-safe/create/steps/Step2/index.tsx | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/new-safe/OwnerRow/index.tsx b/src/components/new-safe/OwnerRow/index.tsx index 8899c1ca50..f9f4ae34cf 100644 --- a/src/components/new-safe/OwnerRow/index.tsx +++ b/src/components/new-safe/OwnerRow/index.tsx @@ -43,11 +43,12 @@ export const OwnerRow = ({ const validateSafeAddress = useCallback( async (address: string) => { + const owners = getValues('owners') if (owners.filter((owner: NamedAddress) => sameAddress(owner.address, address)).length > 1) { return 'Owner is already added' } }, - [owners], + [getValues], ) const { ens, name, resolving } = useAddressResolver(owner.address) diff --git a/src/components/new-safe/create/steps/Step2/index.tsx b/src/components/new-safe/create/steps/Step2/index.tsx index 8461ed6d06..0ae9e27092 100644 --- a/src/components/new-safe/create/steps/Step2/index.tsx +++ b/src/components/new-safe/create/steps/Step2/index.tsx @@ -43,14 +43,14 @@ const CreateSafeStep2 = ({ useSyncSafeCreationStep(setStep) const formMethods = useForm({ - mode: 'all', + mode: 'onChange', defaultValues: { [CreateSafeStep2Fields.owners]: data.owners, [CreateSafeStep2Fields.threshold]: data.threshold, }, }) - const { handleSubmit, control, watch, formState, getValues, setValue } = formMethods + const { handleSubmit, control, watch, formState, getValues, setValue, trigger } = formMethods const threshold = watch(CreateSafeStep2Fields.threshold) @@ -64,6 +64,7 @@ const CreateSafeStep2 = ({ // Set threshold if it's greater than the number of owners setValue(CreateSafeStep2Fields.threshold, Math.min(threshold, ownerFields.length - 1)) remove(index) + trigger(CreateSafeStep2Fields.owners) } const isDisabled = isWrongChain || !formState.isValid