From 1d10cd428f798e35f9d83f5a224722a1b654dc29 Mon Sep 17 00:00:00 2001 From: Nelito Junior Date: Mon, 6 Jan 2025 12:18:28 -0300 Subject: [PATCH] refactor(useNetworkForm): update chainId validation and default value handling --- .../src/systems/Network/hooks/useNetworkForm.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/app/src/systems/Network/hooks/useNetworkForm.ts b/packages/app/src/systems/Network/hooks/useNetworkForm.ts index f380393b7..33bc14483 100644 --- a/packages/app/src/systems/Network/hooks/useNetworkForm.ts +++ b/packages/app/src/systems/Network/hooks/useNetworkForm.ts @@ -33,10 +33,8 @@ const schema = yup ) .optional(), chainId: yup - .mixed() - .transform((value) => - value != null && value !== '' ? Number(value) : undefined - ) + .string() + .transform((value) => (value === null ? '' : String(value))) .required('Chain ID is required') .test( 'chainId-match', @@ -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(); @@ -60,7 +62,7 @@ const DEFAULT_VALUES = { name: '', url: '', explorerUrl: '', - chainId: undefined, + chainId: '', }; export type UseNetworkFormReturn = ReturnType;