From ae583a58476ceacbf09bb02436d03c7b2ee154a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Wed, 11 Jul 2018 07:58:10 +0200 Subject: [PATCH] Fix input to take an ?Error for display error this allow error of Input to be translatable in errors.yml --- src/components/TranslatedError.js | 5 ++++- src/components/base/Input/index.js | 2 +- src/components/modals/AccountSettingRenderBody.js | 6 ++++-- src/components/modals/Send/fields/RecipientField.js | 11 ++++++++++- static/i18n/en/errors.yml | 2 ++ 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/components/TranslatedError.js b/src/components/TranslatedError.js index fe68cd6e..d5e8257c 100644 --- a/src/components/TranslatedError.js +++ b/src/components/TranslatedError.js @@ -24,7 +24,10 @@ class TranslatedError extends PureComponent { if (!error) return null if (typeof error !== 'object') { // this case should not happen (it is supposed to be a ?Error) - logger.critical(error) + logger.critical(`TranslatedError invalid usage: ${String(error)}`) + if (typeof error === 'string') { + return error // TMP in case still used somewhere + } return null } if (error.name) { diff --git a/src/components/base/Input/index.js b/src/components/base/Input/index.js index 44ac36cc..5cd59dca 100644 --- a/src/components/base/Input/index.js +++ b/src/components/base/Input/index.js @@ -87,7 +87,7 @@ type Props = { renderLeft?: any, renderRight?: any, containerProps?: Object, - error?: string | boolean, + error?: ?Error | boolean, small?: boolean, editInPlace?: boolean, } diff --git a/src/components/modals/AccountSettingRenderBody.js b/src/components/modals/AccountSettingRenderBody.js index 6832a354..a1126a98 100644 --- a/src/components/modals/AccountSettingRenderBody.js +++ b/src/components/modals/AccountSettingRenderBody.js @@ -214,7 +214,7 @@ class HelperComp extends PureComponent { maxLength={MAX_ACCOUNT_NAME_SIZE} onChange={this.handleChangeName} onFocus={e => this.handleFocus(e, 'accountName')} - error={accountNameError && t('app:account.settings.accountName.error')} + error={accountNameError && new Error(t('app:account.settings.accountName.error'))} /> @@ -251,7 +251,9 @@ class HelperComp extends PureComponent { onChange={this.handleChangeEndpointConfig} onFocus={e => this.handleFocus(e, 'endpointConfig')} error={ - endpointConfigError ? t('app:account.settings.endpointConfig.error') : false + endpointConfigError + ? new Error(t('app:account.settings.endpointConfig.error')) + : null } /> diff --git a/src/components/modals/Send/fields/RecipientField.js b/src/components/modals/Send/fields/RecipientField.js index d1615bea..67c69e60 100644 --- a/src/components/modals/Send/fields/RecipientField.js +++ b/src/components/modals/Send/fields/RecipientField.js @@ -9,6 +9,7 @@ import Box from 'components/base/Box' import LabelWithExternalIcon from 'components/base/LabelWithExternalIcon' import RecipientAddress from 'components/RecipientAddress' import { track } from 'analytics/segment' +import { createCustomErrorClass } from 'helpers/errors' type Props = { t: T, @@ -19,6 +20,8 @@ type Props = { autoFocus?: boolean, } +const InvalidAddress = createCustomErrorClass('InvalidAddress') + class RecipientField extends Component, { isValid: boolean }> { state = { isValid: true, @@ -79,7 +82,13 @@ class RecipientField extends Component, { isVali diff --git a/static/i18n/en/errors.yml b/static/i18n/en/errors.yml index 27cdc89d..ff88bdff 100644 --- a/static/i18n/en/errors.yml +++ b/static/i18n/en/errors.yml @@ -103,3 +103,5 @@ WrongDeviceForAccount: DeviceAppVerifyNotSupported: title: Open Manager to update this App description: The app verification is not supported +InvalidAddress: + title: 'This is not a valid {{currencyName}} address'