Skip to content

Commit

Permalink
fix: trigger validation upon owner removal (#1477)
Browse files Browse the repository at this point in the history
* fix: trigger validation upon owner removal

* trigger validation on remove owner. Fetch owners with getValues

* trigger validation only for owners
  • Loading branch information
DiogoSoaress authored Jan 9, 2023
1 parent e1e196f commit 390d780
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/components/new-safe/OwnerRow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/components/new-safe/create/steps/Step2/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ const CreateSafeStep2 = ({
useSyncSafeCreationStep(setStep)

const formMethods = useForm<CreateSafeStep2Form>({
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)

Expand All @@ -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
Expand Down

0 comments on commit 390d780

Please sign in to comment.