Skip to content

Commit

Permalink
no error if not touched
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaut committed Oct 18, 2023
1 parent e863faa commit c4d4c86
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions packages/ui/src/components/EasySetup/SetIdentity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const SetIdentity = ({ className, onSetExtrinsic, from, onSetErrorMessage }: Pro
const { api, chainInfo } = useApi()
const [identityFields, setIdentityFields] = useState<IdentityFields | undefined>()
const chainIdentity = useIdentity(from)
const [hasChangedAtLeastAField, setHasChangedAtLeastAField] = useState(false)
const fieldtooLongError = useMemo(() => {
const res: (keyof IdentityFields)[] = []
identityFields &&
Expand All @@ -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) {
Expand Down Expand Up @@ -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))
}, [])

Expand All @@ -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 (
<Grid
item
Expand All @@ -206,7 +208,7 @@ const SetIdentity = ({ className, onSetExtrinsic, from, onSetErrorMessage }: Pro
value={value || ''}
required={required}
helperText={isFieldError && `Field has more than ${MAX_ALLOWED_VAL_LENGTH} chars`}
error={isFieldError || isDiplayAndEmpty}
error={isFieldError || isDiplayNameError}
/>
</Grid>
)
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/contexts/NetworkContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<IToastContext | undefined>(undefined)
const NetworkContext = React.createContext<INetworkContext | undefined>(undefined)
const isSupportedNetwork = (network: string): network is SupportedNetworks =>
!!networkList[network as SupportedNetworks]

Expand Down

0 comments on commit c4d4c86

Please sign in to comment.