From c4d4c865b2c7db22b0092690f409f9cabb07c4be Mon Sep 17 00:00:00 2001 From: Thibaut Sardan Date: Wed, 18 Oct 2023 16:17:37 +0100 Subject: [PATCH] no error if not touched --- packages/ui/src/components/EasySetup/SetIdentity.tsx | 10 ++++++---- packages/ui/src/contexts/NetworkContext.tsx | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/ui/src/components/EasySetup/SetIdentity.tsx b/packages/ui/src/components/EasySetup/SetIdentity.tsx index a44932c9..6ee81739 100644 --- a/packages/ui/src/components/EasySetup/SetIdentity.tsx +++ b/packages/ui/src/components/EasySetup/SetIdentity.tsx @@ -102,6 +102,7 @@ const SetIdentity = ({ className, onSetExtrinsic, from, onSetErrorMessage }: Pro const { api, chainInfo } = useApi() const [identityFields, setIdentityFields] = useState() const chainIdentity = useIdentity(from) + const [hasChangedAtLeastAField, setHasChangedAtLeastAField] = useState(false) const fieldtooLongError = useMemo(() => { const res: (keyof IdentityFields)[] = [] identityFields && @@ -120,13 +121,13 @@ const SetIdentity = ({ className, onSetExtrinsic, from, onSetErrorMessage }: Pro return } - if (!identityFields?.display) { + if (!identityFields?.display && hasChangedAtLeastAField) { onSetErrorMessage('Display name is required') return } onSetErrorMessage('') - }, [fieldtooLongError, identityFields?.display, onSetErrorMessage]) + }, [fieldtooLongError, hasChangedAtLeastAField, identityFields, onSetErrorMessage]) useEffect(() => { if (chainIdentity) { @@ -172,6 +173,7 @@ const SetIdentity = ({ className, onSetExtrinsic, from, onSetErrorMessage }: Pro }, [api, chainInfo, fieldtooLongError, identityFields, onSetErrorMessage, onSetExtrinsic]) const onChangeField = useCallback((field: keyof IdentityFields, value: string) => { + setHasChangedAtLeastAField(true) setIdentityFields((prev) => (prev ? { ...prev, [field]: value } : undefined)) }, []) @@ -187,7 +189,7 @@ const SetIdentity = ({ className, onSetExtrinsic, from, onSetErrorMessage }: Pro fieldName as keyof IdentityFields ) const isFieldError = fieldtooLongError.includes(fieldName as keyof IdentityFields) - const isDiplayAndEmpty = fieldName === 'display' && !value + const isDiplayNameError = fieldName === 'display' && !value && hasChangedAtLeastAField return ( ) diff --git a/packages/ui/src/contexts/NetworkContext.tsx b/packages/ui/src/contexts/NetworkContext.tsx index 9893d2f6..927f9c35 100644 --- a/packages/ui/src/contexts/NetworkContext.tsx +++ b/packages/ui/src/contexts/NetworkContext.tsx @@ -8,13 +8,13 @@ type NetworkContextProps = { children: React.ReactNode | React.ReactNode[] } -export interface IToastContext { +export interface INetworkContext { selectNetwork: (network: string) => void selectedNetworkInfo?: NetworkInfo selectedNetwork?: SupportedNetworks } -const NetworkContext = React.createContext(undefined) +const NetworkContext = React.createContext(undefined) const isSupportedNetwork = (network: string): network is SupportedNetworks => !!networkList[network as SupportedNetworks]