Skip to content

Commit

Permalink
refactor(useNetworkForm): update chainId validation and default value…
Browse files Browse the repository at this point in the history
… handling
  • Loading branch information
nelitow committed Jan 6, 2025
1 parent 4da0b0a commit 1d10cd4
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/app/src/systems/Network/hooks/useNetworkForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ const schema = yup
)
.optional(),
chainId: yup
.mixed<string | number>()
.transform((value) =>
value != null && value !== '' ? Number(value) : undefined
)
.string()
.transform((value) => (value === null ? '' : String(value)))
.required('Chain ID is required')
.test(
'chainId-match',
Expand All @@ -51,7 +49,11 @@ const schema = yup
.test(
'is-numbers-only',
'Chain ID must contain only numbers',
(value) => value == null || Number.isInteger(value)
(value) => {
if (!value) return true;
const num = Number(value);
return !Number.isNaN(num) && Number.isInteger(num);
}
),
})
.required();
Expand All @@ -60,7 +62,7 @@ const DEFAULT_VALUES = {
name: '',
url: '',
explorerUrl: '',
chainId: undefined,
chainId: '',
};

export type UseNetworkFormReturn = ReturnType<typeof useNetworkForm>;
Expand Down

0 comments on commit 1d10cd4

Please sign in to comment.