From baee0855c5a467dd685a6353ba455a498e2bcea0 Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Fri, 26 Apr 2019 12:10:18 +0200 Subject: [PATCH] add gas price and nonce l10n --- .../ethereum/SendFormValidationActions.js | 59 +++++++++++++++---- .../views/Account/Send/validation.messages.js | 36 +++++++++++ 2 files changed, 83 insertions(+), 12 deletions(-) diff --git a/src/actions/ethereum/SendFormValidationActions.js b/src/actions/ethereum/SendFormValidationActions.js index e088d1bb..8a3ef2b7 100644 --- a/src/actions/ethereum/SendFormValidationActions.js +++ b/src/actions/ethereum/SendFormValidationActions.js @@ -357,21 +357,33 @@ export const gasLimitValidation = ($state: State): PayloadAction => ( /* * Gas price value validation */ -export const gasPriceValidation = ($state: State): PayloadAction => (): State => { +export const gasPriceValidation = ($state: State): PayloadAction => ( + dispatch: Dispatch, + getState: GetState +): State => { const state = { ...$state }; if (!state.touched.gasPrice) return state; + // get react-intl imperative api + const { language, messages } = getState().wallet; + const intlProvider = new IntlProvider({ language, messages }); + const { intl } = intlProvider.getChildContext(); + const { gasPrice } = state; if (gasPrice.length < 1) { - state.errors.gasPrice = 'Gas price is not set'; + // state.errors.gasPrice = 'Gas price is not set'; + state.errors.gasPrice = intl.formatMessage(l10nMessages.TR_GAS_PRICE_IS_NOT_SET); } else if (gasPrice.length > 0 && !validators.isNumber(gasPrice)) { - state.errors.gasPrice = 'Gas price is not a number'; + // state.errors.gasPrice = 'Gas price is not a number'; + state.errors.gasPrice = intl.formatMessage(l10nMessages.TR_GAS_PRICE_IS_NOT_A_NUMBER); } else { const gp: BigNumber = new BigNumber(gasPrice); if (gp.isGreaterThan(1000)) { - state.warnings.gasPrice = 'Gas price is too high'; + // state.warnings.gasPrice = 'Gas price is too high'; + state.warnings.gasPrice = intl.formatMessage(l10nMessages.TR_GAS_PRICE_IS_TOO_HIGH); } else if (gp.isLessThanOrEqualTo('0')) { - state.errors.gasPrice = 'Gas price is too low'; + // state.errors.gasPrice = 'Gas price is too low'; + state.errors.gasPrice = intl.formatMessage(l10nMessages.TR_GAS_PRICE_IS_TOO_LOW); } } return state; @@ -387,33 +399,56 @@ export const nonceValidation = ($state: State): PayloadAction => ( const state = { ...$state }; if (!state.touched.nonce) return state; + // get react-intl imperative api + const { language, messages } = getState().wallet; + const intlProvider = new IntlProvider({ language, messages }); + const { intl } = intlProvider.getChildContext(); + const { account } = getState().selectedAccount; if (!account || account.networkType !== 'ethereum') return state; const { nonce } = state; if (nonce.length < 1) { - state.errors.nonce = 'Nonce is not set'; + // state.errors.nonce = 'Nonce is not set'; + state.errors.nonce = intl.formatMessage(l10nMessages.TR_NONCE_IS_NOT_SET); } else if (!validators.isAbs(nonce)) { - state.errors.nonce = 'Nonce is not a valid number'; + // state.errors.nonce = 'Nonce is not a valid number'; + state.errors.nonce = intl.formatMessage(l10nMessages.TR_NONCE_IS_NOT_A_NUMBER); } else { const n: BigNumber = new BigNumber(nonce); if (n.isLessThan(account.nonce)) { - state.warnings.nonce = 'Nonce is lower than recommended'; + // state.warnings.nonce = 'Nonce is lower than recommended'; + state.warnings.nonce = intl.formatMessage( + l10nMessages.TR_NONCE_IS_LOWER_THAN_RECOMMENDED + ); } else if (n.isGreaterThan(account.nonce)) { - state.warnings.nonce = 'Nonce is greater than recommended'; + // state.warnings.nonce = 'Nonce is greater than recommended'; + state.warnings.nonce = intl.formatMessage( + l10nMessages.TR_NONCE_IS_GREATER_THAN_RECOMMENDED + ); } } return state; }; /* - * Gas price value validation + * Data validation */ -export const dataValidation = ($state: State): PayloadAction => (): State => { +export const dataValidation = ($state: State): PayloadAction => ( + dispatch: Dispatch, + getState: GetState +): State => { const state = { ...$state }; if (!state.touched.data || state.data.length === 0) return state; + + // get react-intl imperative api + const { language, messages } = getState().wallet; + const intlProvider = new IntlProvider({ language, messages }); + const { intl } = intlProvider.getChildContext(); + if (!ethUtils.isHex(state.data)) { - state.errors.data = 'Data is not valid hexadecimal'; + // state.errors.data = 'Data is not valid hexadecimal'; + state.errors.data = intl.formatMessage(l10nMessages.TR_DATA_IS_NOT_VALID_HEX); } return state; }; diff --git a/src/views/Wallet/views/Account/Send/validation.messages.js b/src/views/Wallet/views/Account/Send/validation.messages.js index fd8880ae..a2a09450 100644 --- a/src/views/Wallet/views/Account/Send/validation.messages.js +++ b/src/views/Wallet/views/Account/Send/validation.messages.js @@ -55,6 +55,42 @@ const definedMessages: Messages = defineMessages({ id: 'TR_GAS_LIMIT_IS_BELOW_RECOMMENDED', defaultMessage: 'Gas limit is below recommended', }, + TR_GAS_PRICE_IS_NOT_A_NUMBER: { + id: 'TR_GAS_PRICE_IS_NOT_A_NUMBER', + defaultMessage: 'Gas price is not a number', + }, + TR_GAS_PRICE_IS_NOT_SET: { + id: 'TR_GAS_PRICE_IS_NOT_SET', + defaultMessage: 'Gas price is not set', + }, + TR_GAS_PRICE_IS_TOO_LOW: { + id: 'TR_GAS_PRICE_IS_TOO_LOW', + defaultMessage: 'Gas price is too low', + }, + TR_GAS_PRICE_IS_TOO_HIGH: { + id: 'TR_GAS_PRICE_IS_TOO_HIGH', + defaultMessage: 'Gas price is too high', + }, + TR_NONCE_IS_NOT_A_NUMBER: { + id: 'TR_NONCE_IS_NOT_A_NUMBER', + defaultMessage: 'Nonce is not a valid number', + }, + TR_NONCE_IS_NOT_SET: { + id: 'TR_NONCE_IS_NOT_SET', + defaultMessage: 'Nonce is not set', + }, + TR_NONCE_IS_GREATER_THAN_RECOMMENDED: { + id: 'TR_NONCE_IS_GREATER_THAN_RECOMMENDED', + defaultMessage: 'Nonce is greater than recommended', + }, + TR_NONCE_IS_LOWER_THAN_RECOMMENDED: { + id: 'TR_NONCE_IS_LOWER_THAN_RECOMMENDED', + defaultMessage: 'Nonce is lower than recommended', + }, + TR_DATA_IS_NOT_VALID_HEX: { + id: 'TR_DATA_IS_NOT_VALID_HEX', + defaultMessage: 'Data is not valid hexadecimal', + }, }); export default definedMessages;