Browse Source
Merge pull request #1040 from gre/fix-input-to-take-error
Fix input to take an ?Error for display error
master
Gaëtan Renaudeau
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with
21 additions and
5 deletions
-
src/components/TranslatedError.js
-
src/components/base/Input/index.js
-
src/components/modals/AccountSettingRenderBody.js
-
src/components/modals/Send/fields/RecipientField.js
-
static/i18n/en/errors.yml
|
|
@ -24,7 +24,10 @@ class TranslatedError extends PureComponent<Props> { |
|
|
|
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) { |
|
|
|
|
|
@ -87,7 +87,7 @@ type Props = { |
|
|
|
renderLeft?: any, |
|
|
|
renderRight?: any, |
|
|
|
containerProps?: Object, |
|
|
|
error?: string | boolean, |
|
|
|
error?: ?Error | boolean, |
|
|
|
small?: boolean, |
|
|
|
editInPlace?: boolean, |
|
|
|
} |
|
|
|
|
|
@ -214,7 +214,7 @@ class HelperComp extends PureComponent<Props, State> { |
|
|
|
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'))} |
|
|
|
/> |
|
|
|
</Box> |
|
|
|
</Container> |
|
|
@ -251,7 +251,9 @@ class HelperComp extends PureComponent<Props, State> { |
|
|
|
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 |
|
|
|
} |
|
|
|
/> |
|
|
|
</Box> |
|
|
|
|
|
@ -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<Transaction> = { |
|
|
|
t: T, |
|
|
@ -19,6 +20,8 @@ type Props<Transaction> = { |
|
|
|
autoFocus?: boolean, |
|
|
|
} |
|
|
|
|
|
|
|
const InvalidAddress = createCustomErrorClass('InvalidAddress') |
|
|
|
|
|
|
|
class RecipientField<Transaction> extends Component<Props<Transaction>, { isValid: boolean }> { |
|
|
|
state = { |
|
|
|
isValid: true, |
|
|
@ -79,7 +82,13 @@ class RecipientField<Transaction> extends Component<Props<Transaction>, { isVali |
|
|
|
<RecipientAddress |
|
|
|
autoFocus={autoFocus} |
|
|
|
withQrCode |
|
|
|
error={!value || isValid ? null : `This is not a valid ${account.currency.name} address`} |
|
|
|
error={ |
|
|
|
!value || isValid |
|
|
|
? null |
|
|
|
: new InvalidAddress(null, { |
|
|
|
currencyName: account.currency.name, |
|
|
|
}) |
|
|
|
} |
|
|
|
value={value} |
|
|
|
onChange={this.onChange} |
|
|
|
/> |
|
|
|
|
|
@ -100,3 +100,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' |
|
|
|