From f358896c636c7a404e2ca871257bd85d9c00ae45 Mon Sep 17 00:00:00 2001 From: Thibaut Sardan <33178835+Tbaut@users.noreply.github.com> Date: Fri, 11 Sep 2020 15:22:27 +0200 Subject: [PATCH] Translate error and warning messages (#3663) * translate error messages * cater for unexpected error --- packages/page-accounts/src/modals/Create.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/page-accounts/src/modals/Create.tsx b/packages/page-accounts/src/modals/Create.tsx index a8f64f1c6e..3a5e6ba3bf 100644 --- a/packages/page-accounts/src/modals/Create.tsx +++ b/packages/page-accounts/src/modals/Create.tsx @@ -64,17 +64,17 @@ function deriveValidate (seed: string, seedType: SeedType, derivePath: string, p // show a warning in case the password contains an unintended / character if (password?.includes('/')) { - result = { warning: 'Your password contains at least one "/" character. Disregard this warning if it is intended.' }; + result = { warning: 'WARNING_SLASH_PASSWORD' }; } // we don't allow soft for ed25519 if (pairType === 'ed25519' && path.some(({ isSoft }): boolean => isSoft)) { - return { ...result, error: 'Soft derivation paths are not allowed on ed25519' }; + return { ...result, error: 'SOFT_NOT_ALLOWED' }; } // we don't allow password for hex seed if (seedType === 'raw' && password) { - return { ...result, error: 'Password are ignored for hex seed' }; + return { ...result, error: 'PASSWORD_IGNORED' }; } return result; @@ -189,6 +189,11 @@ function Create ({ className = '', onClose, onStatusChange, seed: propsSeed, typ const [{ isNameValid, name }, setName] = useState({ isNameValid: false, name: '' }); const [{ isPasswordValid, password }, setPassword] = useState({ isPasswordValid: false, password: '' }); const isValid = !!address && !deriveValidation?.error && isNameValid && isPasswordValid && isSeedValid; + const errorIndex: Record = useMemo(() => ({ + PASSWORD_IGNORED: t('Password are ignored for hex seed'), + SOFT_NOT_ALLOWED: t('Soft derivation paths are not allowed on ed25519'), + WARNING_SLASH_PASSWORD: t('Your password contains at least one "/" character. Disregard this warning if it is intended.') + }), [t]); const seedOpt = useMemo(() => ( isDevelopment @@ -381,10 +386,10 @@ function Create ({ className = '', onClose, onStatusChange, seed: propsSeed, typ value={derivePath} /> {deriveValidation?.error && ( -
{deriveValidation.error}
+
{errorIndex[deriveValidation.error] || deriveValidation.error}
)} {deriveValidation?.warning && ( -
{deriveValidation.warning}
+
{errorIndex[deriveValidation.warning]}
)}