From fd643418b530179bf1539fa1b751261ebcbf81e9 Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Thu, 25 Apr 2019 16:02:38 +0200 Subject: [PATCH 01/17] add messages for device status --- src/components/DeviceHeader/index.js | 8 ++- src/components/DeviceHeader/index.messages.js | 63 +++++++++++++++++++ src/utils/__tests__/device.test.js | 11 ---- src/utils/device.js | 42 ++++++++----- 4 files changed, 96 insertions(+), 28 deletions(-) create mode 100644 src/components/DeviceHeader/index.messages.js diff --git a/src/components/DeviceHeader/index.js b/src/components/DeviceHeader/index.js index 3f3a7350..ce10788c 100644 --- a/src/components/DeviceHeader/index.js +++ b/src/components/DeviceHeader/index.js @@ -1,9 +1,9 @@ -// TODO: l10n for device status import React from 'react'; import styled, { css } from 'styled-components'; import PropTypes from 'prop-types'; import { getStatusColor, getStatusName, getStatus } from 'utils/device'; import { TrezorImage, colors } from 'trezor-ui-components'; +import { injectIntl } from 'react-intl'; import { FONT_SIZE, FONT_WEIGHT } from 'config/variables'; @@ -102,6 +102,7 @@ const DeviceHeader = ({ isSelected = false, className, testId, + intl, }) => { const status = getStatus(device); return ( @@ -123,7 +124,7 @@ const DeviceHeader = ({ {device.instanceLabel} - {getStatusName(status)} + {getStatusName(status, intl)} {icon && !disabled && isAccessible && icon} @@ -141,6 +142,7 @@ DeviceHeader.propTypes = { onClickWrapper: PropTypes.func.isRequired, className: PropTypes.string, testId: PropTypes.string, + intl: PropTypes.any, }; -export default DeviceHeader; +export default injectIntl(DeviceHeader); diff --git a/src/components/DeviceHeader/index.messages.js b/src/components/DeviceHeader/index.messages.js new file mode 100644 index 00000000..dba5b890 --- /dev/null +++ b/src/components/DeviceHeader/index.messages.js @@ -0,0 +1,63 @@ +/* @flow */ +import { defineMessages } from 'react-intl'; +import type { Messages } from 'flowtype/npm/react-intl'; + +const definedMessages: Messages = defineMessages({ + TR_CONNECTED: { + id: 'TR_CONNECTED', + defaultMessage: 'Connected', + description: 'Device status', + }, + TR_CONNECTED_BOOTLOADER: { + id: 'TR_CONNECTED_BOOTLOADER', + defaultMessage: 'Connected (bootloader mode)', + description: 'Device status', + }, + TR_CONNECTED_NOT_INITIALIZED: { + id: 'TR_CONNECTED', + defaultMessage: 'Connected (not initialized)', + description: 'Device status', + }, + TR_CONNECTED_SEEDLESS: { + id: 'TR_CONNECTED_SEEDLESS', + defaultMessage: 'Connected (seedless mode)', + description: 'Device status', + }, + TR_CONNECTED_UPDATE_REQUIRED: { + id: 'TR_CONNECTED_UPDATE_REQUIRED', + defaultMessage: 'Connected (update required)', + description: 'Device status', + }, + TR_CONNECTED_UPDATE_RECOMMENDED: { + id: 'TR_CONNECTED_UPDATE_RECOMMENDED', + defaultMessage: 'Connected (update recommended)', + description: 'Device status', + }, + TR_USED_IN_ANOTHER_WINDOW: { + id: 'TR_USED_IN_ANOTHER_WINDOW', + defaultMessage: 'Used in other window', + description: 'Device status', + }, + TR_UNAVAILABLE: { + id: 'TR_UNAVAILABLE', + defaultMessage: 'Unavailable', + description: 'Device status', + }, + TR_UNREADABLE: { + id: 'TR_UNREADABLE', + defaultMessage: 'Unreadable', + description: 'Device status', + }, + TR_DISCONNECTED: { + id: 'TR_DISCONNECTED', + defaultMessage: 'Disconnected', + description: 'Device status', + }, + TR_STATUS_UNKNOWN: { + id: 'TR_STATUS_UNKNOWN', + defaultMessage: 'Status unknown', + description: 'Device status', + }, +}); + +export default definedMessages; diff --git a/src/utils/__tests__/device.test.js b/src/utils/__tests__/device.test.js index deac57d6..1cbc2c91 100644 --- a/src/utils/__tests__/device.test.js +++ b/src/utils/__tests__/device.test.js @@ -76,15 +76,4 @@ describe('device utils', () => { expect(utils.getStatusColor('disconnected')).toBe(colors.ERROR_PRIMARY); expect(utils.getStatusColor('unavailable')).toBe(colors.ERROR_PRIMARY); }); - - it('get status name', () => { - expect(utils.getStatusName(0)).toBe('Status unknown'); - expect(utils.getStatusName(null)).toBe('Status unknown'); - expect(utils.getStatusName('sdsdsdsd')).toBe('Status unknown'); - expect(utils.getStatusName('used-in-other-window')).toBe('Used in other window'); - expect(utils.getStatusName('connected')).toBe('Connected'); - expect(utils.getStatusName('unacquired')).toBe('Used in other window'); - expect(utils.getStatusName('disconnected')).toBe('Disconnected'); - expect(utils.getStatusName('unavailable')).toBe('Unavailable'); - }); }); diff --git a/src/utils/device.js b/src/utils/device.js index 18b4fef2..b75c20fc 100644 --- a/src/utils/device.js +++ b/src/utils/device.js @@ -1,10 +1,12 @@ /* @flow */ import { colors } from 'trezor-ui-components'; - +import type { IntlShape } from 'react-intl'; import type { Device } from 'trezor-connect'; import type { TrezorDevice, State } from 'flowtype'; +import l10nMessages from 'components/DeviceHeader/index.messages'; + type Transport = $ElementType<$ElementType, 'transport'>; export const getStatus = (device: TrezorDevice): string => { @@ -48,32 +50,44 @@ export const getStatus = (device: TrezorDevice): string => { return 'unknown'; }; -export const getStatusName = (deviceStatus: string): string => { +export const getStatusName = (deviceStatus: string, intl: IntlShape): string => { switch (deviceStatus) { case 'connected': - return 'Connected'; + // return 'Connected'; + return intl.formatMessage(l10nMessages.TR_CONNECTED); case 'disconnected': - return 'Disconnected'; + // return 'Disconnected'; + return intl.formatMessage(l10nMessages.TR_DISCONNECTED); case 'bootloader': - return 'Connected (bootloader mode)'; + // return 'Connected (bootloader mode)'; + return intl.formatMessage(l10nMessages.TR_CONNECTED_BOOTLOADER); case 'initialize': - return 'Connected (not initialized)'; + // return 'Connected (not initialized)'; + return intl.formatMessage(l10nMessages.TR_CONNECTED_NOT_INITIALIZED); case 'seedless': - return 'Connected (seedless mode)'; + // return 'Connected (seedless mode)'; + return intl.formatMessage(l10nMessages.TR_CONNECTED_SEEDLESS); case 'firmware-required': - return 'Connected (update required)'; + // return 'Connected (update required)'; + return intl.formatMessage(l10nMessages.TR_CONNECTED_UPDATE_REQUIRED); case 'firmware-recommended': - return 'Connected (update recommended)'; + // return 'Connected (update recommended)'; + return intl.formatMessage(l10nMessages.TR_CONNECTED_UPDATE_RECOMMENDED); case 'used-in-other-window': - return 'Used in other window'; + // return 'Used in other window'; + return intl.formatMessage(l10nMessages.TR_USED_IN_ANOTHER_WINDOW); case 'unacquired': - return 'Used in other window'; + // return 'Used in other window'; + return intl.formatMessage(l10nMessages.TR_USED_IN_ANOTHER_WINDOW); case 'unavailable': - return 'Unavailable'; + // return 'Unavailable'; + return intl.formatMessage(l10nMessages.TR_UNAVAILABLE); case 'unreadable': - return 'Unreadable'; + // return 'Unreadable'; + return intl.formatMessage(l10nMessages.TR_UNREADABLE); default: - return 'Status unknown'; + // return 'Status unknown'; + return intl.formatMessage(l10nMessages.TR_STATUS_UNKNOWN); } }; From 8cef01388e24eff743ac3f02303eae1ca3250817 Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Thu, 25 Apr 2019 17:55:29 +0200 Subject: [PATCH 02/17] add l10n for address and amount inputs --- .../ethereum/SendFormValidationActions.js | 61 +++++++++++++++---- .../views/Account/Send/validation.messages.js | 44 +++++++++++++ 2 files changed, 92 insertions(+), 13 deletions(-) create mode 100644 src/views/Wallet/views/Account/Send/validation.messages.js diff --git a/src/actions/ethereum/SendFormValidationActions.js b/src/actions/ethereum/SendFormValidationActions.js index c213710d..f857bb28 100644 --- a/src/actions/ethereum/SendFormValidationActions.js +++ b/src/actions/ethereum/SendFormValidationActions.js @@ -5,13 +5,14 @@ import EthereumjsUtil from 'ethereumjs-util'; import EthereumjsUnits from 'ethereumjs-units'; import { findDevice, getPendingAmount, findToken } from 'reducers/utils'; import { toFiatCurrency } from 'utils/fiatConverter'; +import { IntlProvider } from 'react-intl'; import * as SEND from 'actions/constants/send'; import * as ethUtils from 'utils/ethUtils'; import * as validators from 'utils/validators'; import type { Dispatch, GetState, PayloadAction } from 'flowtype'; import type { State, FeeLevel } from 'reducers/SendFormEthereumReducer'; - +import l10nMessages from 'views/Wallet/views/Account/Send/validation.messages'; /* * Called from SendFormActions.observe * Reaction for WEB3.GAS_PRICE_UPDATED action @@ -143,21 +144,32 @@ export const updateCustomFeeLabel = ($state: State): PayloadAction => (): /* * Address value validation */ -export const addressValidation = ($state: State): PayloadAction => (): State => { +export const addressValidation = ($state: State): PayloadAction => ( + dispatch: Dispatch, + getState: GetState +): State => { + // get react-intl imperative api + const { language, messages } = getState().wallet; + const intlProvider = new IntlProvider({ language, messages }); + const { intl } = intlProvider.getChildContext(); + const state = { ...$state }; if (!state.touched.address) return state; const { address } = state; if (address.length < 1) { - state.errors.address = 'Address is not set'; + // state.errors.address = 'Address is not set'; + state.errors.address = intl.formatMessage(l10nMessages.TR_ADDRESS_IS_NOT_SET); } else if (!EthereumjsUtil.isValidAddress(address)) { - state.errors.address = 'Address is not valid'; + // state.errors.address = 'Address is not valid'; + state.errors.address = intl.formatMessage(l10nMessages.TR_ADDRESS_IS_NOT_VALID); } else if ( validators.hasUppercase(address) && !EthereumjsUtil.isValidChecksumAddress(address) ) { - state.errors.address = 'Address is not a valid checksum'; + // state.errors.address = 'Address is not a valid checksum'; + state.errors.address = intl.formatMessage(l10nMessages.TR_ADDRESS_CHECKSUM_IS_NOT_VALID); } return state; }; @@ -229,11 +241,18 @@ export const amountValidation = ($state: State): PayloadAction => ( const { account, tokens, pending } = getState().selectedAccount; if (!account) return state; + // get react-intl imperative api + const { language, messages } = getState().wallet; + const intlProvider = new IntlProvider({ language, messages }); + const { intl } = intlProvider.getChildContext(); + const { amount } = state; if (amount.length < 1) { - state.errors.amount = 'Amount is not set'; + // state.errors.amount = 'Amount is not set'; + state.errors.amount = intl.formatMessage(l10nMessages.TR_AMOUNT_IS_NOT_SET); } else if (amount.length > 0 && !validators.isNumber(amount)) { - state.errors.amount = 'Amount is not a number'; + // state.errors.amount = 'Amount is not a number'; + state.errors.amount = intl.formatMessage(l10nMessages.TR_AMOUNT_IS_NOT_A_NUMBER); } else { const isToken: boolean = state.currency !== state.networkSymbol; const pendingAmount: BigNumber = getPendingAmount(pending, state.currency, isToken); @@ -248,26 +267,42 @@ export const amountValidation = ($state: State): PayloadAction => ( if (!token) return state; if (!validators.hasDecimals(state.amount, parseInt(token.decimals, 0))) { - state.errors.amount = `Maximum ${token.decimals} decimals allowed`; + // state.errors.amount = `Maximum ${token.decimals} decimals allowed`; + state.errors.amount = intl.formatMessage(l10nMessages.TR_MAXIMUM_DECIMALS_ALLOWED, { + decimals: token.decimals, + }); } else if (new BigNumber(state.total).isGreaterThan(account.balance)) { - state.errors.amount = `Not enough ${state.networkSymbol} to cover transaction fee`; + state.errors.amount = intl.formatMessage( + l10nMessages.TR_NOT_ENOUGH_FUNDS_TO_COVER_TRANSACTION, + { + networkSymbol: state.networkSymbol, + } + ); + // state.errors.amount = `Not enough ${state.networkSymbol} to cover transaction fee`; } else if ( new BigNumber(state.amount).isGreaterThan( new BigNumber(token.balance).minus(pendingAmount) ) ) { - state.errors.amount = 'Not enough funds'; + // state.errors.amount = 'Not enough funds'; + state.errors.amount = intl.formatMessage(l10nMessages.TR_NOT_ENOUGH_FUNDS); } else if (new BigNumber(state.amount).isLessThanOrEqualTo('0')) { - state.errors.amount = 'Amount is too low'; + // TODO: this is never gonna happen! It will fail in second if condiftion (isNumber validation) + // state.errors.amount = 'Amount is too low'; + state.errors.amount = intl.formatMessage(l10nMessages.TR_AMOUNT_IS_TOO_LOW); } } else if (!validators.hasDecimals(state.amount, 18)) { - state.errors.amount = 'Maximum 18 decimals allowed'; + // state.errors.amount = 'Maximum 18 decimals allowed'; + state.errors.amount = intl.formatMessage(l10nMessages.TR_MAXIMUM_DECIMALS_ALLOWED, { + decimals: 18, + }); } else if ( new BigNumber(state.total).isGreaterThan( new BigNumber(account.balance).minus(pendingAmount) ) ) { - state.errors.amount = 'Not enough funds'; + // state.errors.amount = 'Not enough funds'; + state.errors.amount = intl.formatMessage(l10nMessages.TR_NOT_ENOUGH_FUNDS); } } return state; diff --git a/src/views/Wallet/views/Account/Send/validation.messages.js b/src/views/Wallet/views/Account/Send/validation.messages.js new file mode 100644 index 00000000..a9e020e3 --- /dev/null +++ b/src/views/Wallet/views/Account/Send/validation.messages.js @@ -0,0 +1,44 @@ +/* @flow */ +import { defineMessages } from 'react-intl'; +import type { Messages } from 'flowtype/npm/react-intl'; + +const definedMessages: Messages = defineMessages({ + TR_AMOUNT_IS_NOT_SET: { + id: 'TR_AMOUNT_IS_NOT_SET', + defaultMessage: 'Amount is not set', + }, + TR_AMOUNT_IS_NOT_A_NUMBER: { + id: 'TR_AMOUNT_IS_NOT_A_NUMBER', + defaultMessage: 'Amount is not a number', + }, + TR_MAXIMUM_DECIMALS_ALLOWED: { + id: 'TR_AMOUNT_IS_NOT_A_NUMBER', + defaultMessage: 'Maximum {decimals} decimals allowed', + }, + TR_NOT_ENOUGH_FUNDS_TO_COVER_TRANSACTION: { + id: 'TR_NOT_ENOUGH_FUNDS_TO_COVER_TRANSACTION', + defaultMessage: 'Not enough {networkSymbol} to cover transaction fee', + }, + TR_NOT_ENOUGH_FUNDS: { + id: 'TR_NOT_ENOUGH_FUNDS', + defaultMessage: 'Not enough funds', + }, + TR_AMOUNT_IS_TOO_LOW: { + id: 'TR_AMOUNT_IS_TOO_LOW', + defaultMessage: 'Amount is too low', + }, + TR_ADDRESS_IS_NOT_SET: { + id: 'TR_ADDRESS_IS_NOT_SET', + defaultMessage: 'Address is not set', + }, + TR_ADDRESS_IS_NOT_VALID: { + id: 'TR_ADDRESS_IS_NOT_VALID', + defaultMessage: 'Address is not valid', + }, + TR_ADDRESS_CHECKSUM_IS_NOT_VALID: { + id: 'TR_ADDRESS_CHECKSUM_IS_NOT_VALID', + defaultMessage: 'Address checksum is not valid', + }, +}); + +export default definedMessages; From 5000ea65e48dcda2ce990d4590b07872a5d852b9 Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Thu, 25 Apr 2019 18:07:41 +0200 Subject: [PATCH 03/17] add gas limit validation messages --- .../ethereum/SendFormValidationActions.js | 19 +++++++++++++++---- .../views/Account/Send/validation.messages.js | 16 ++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/actions/ethereum/SendFormValidationActions.js b/src/actions/ethereum/SendFormValidationActions.js index f857bb28..e088d1bb 100644 --- a/src/actions/ethereum/SendFormValidationActions.js +++ b/src/actions/ethereum/SendFormValidationActions.js @@ -321,15 +321,23 @@ export const gasLimitValidation = ($state: State): PayloadAction => ( const { network } = getState().selectedAccount; if (!network) return state; + // get react-intl imperative api + const { language, messages } = getState().wallet; + const intlProvider = new IntlProvider({ language, messages }); + const { intl } = intlProvider.getChildContext(); + const { gasLimit } = state; if (gasLimit.length < 1) { - state.errors.gasLimit = 'Gas limit is not set'; + // state.errors.gasLimit = 'Gas limit is not set'; + state.errors.gasLimit = intl.formatMessage(l10nMessages.TR_GAS_LIMIT_IS_NOT_SET); } else if (gasLimit.length > 0 && !validators.isNumber(gasLimit)) { - state.errors.gasLimit = 'Gas limit is not a number'; + // state.errors.gasLimit = 'Gas limit is not a number'; + state.errors.gasLimit = intl.formatMessage(l10nMessages.TR_GAS_LIMIT_IS_NOT_A_NUMBER); } else { const gl: BigNumber = new BigNumber(gasLimit); if (gl.isLessThan(1)) { - state.errors.gasLimit = 'Gas limit is too low'; + // state.errors.gasLimit = 'Gas limit is too low'; + state.errors.gasLimit = intl.formatMessage(l10nMessages.TR_GAS_LIMIT_IS_TOO_LOW); } else if ( gl.isLessThan( state.currency !== state.networkSymbol @@ -337,7 +345,10 @@ export const gasLimitValidation = ($state: State): PayloadAction => ( : network.defaultGasLimit ) ) { - state.warnings.gasLimit = 'Gas limit is below recommended'; + // state.warnings.gasLimit = 'Gas limit is below recommended'; + state.warnings.gasLimit = intl.formatMessage( + l10nMessages.TR_GAS_LIMIT_IS_BELOW_RECOMMENDED + ); } } 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 a9e020e3..fd8880ae 100644 --- a/src/views/Wallet/views/Account/Send/validation.messages.js +++ b/src/views/Wallet/views/Account/Send/validation.messages.js @@ -39,6 +39,22 @@ const definedMessages: Messages = defineMessages({ id: 'TR_ADDRESS_CHECKSUM_IS_NOT_VALID', defaultMessage: 'Address checksum is not valid', }, + TR_GAS_LIMIT_IS_NOT_SET: { + id: 'TR_GAS_LIMIT_IS_NOT_SET', + defaultMessage: 'Gas limit is not set', + }, + TR_GAS_LIMIT_IS_NOT_A_NUMBER: { + id: 'TR_GAS_LIMIT_IS_NOT_A_NUMBER', + defaultMessage: 'Gas limit is not a number', + }, + TR_GAS_LIMIT_IS_TOO_LOW: { + id: 'TR_GAS_LIMIT_IS_TOO_LOW', + defaultMessage: 'Gas limit is too low', + }, + TR_GAS_LIMIT_IS_BELOW_RECOMMENDED: { + id: 'TR_GAS_LIMIT_IS_BELOW_RECOMMENDED', + defaultMessage: 'Gas limit is below recommended', + }, }); export default definedMessages; From baee0855c5a467dd685a6353ba455a498e2bcea0 Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Fri, 26 Apr 2019 12:10:18 +0200 Subject: [PATCH 04/17] 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; From d84af20a73703230931eb4db2b9d3e423ef2c498 Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Mon, 29 Apr 2019 11:59:15 +0200 Subject: [PATCH 05/17] move MessageDescriptor export --- src/components/DeviceHeader/index.messages.js | 2 +- src/components/Footer/index.messages.js | 2 +- src/components/Header/index.messages.js | 2 +- src/components/Log/index.messages.js | 2 +- .../modals/QrModal/index.messages.js | 2 +- .../modals/confirm/Action/index.messages.js | 2 +- .../modals/confirm/Address/index.messages.js | 2 +- .../modals/confirm/SignTx/index.messages.js | 2 +- .../UnverifiedAddress/index.messages.js | 2 +- .../modals/device/Forget/index.messages.js | 2 +- .../modals/device/Remember/index.messages.js | 2 +- .../device/WalletType/index.messages.js | 2 +- .../modals/device/common.messages.js | 2 +- .../modals/external/Cardano/index.messages.js | 2 +- .../modals/external/Nem/index.messages.js | 2 +- .../modals/external/Stellar/index.messages.js | 2 +- .../modals/external/Tezos/index.messages.js | 2 +- .../modals/external/common.messages.js | 2 +- .../passphrase/Passphrase/index.messages.js | 2 +- .../modals/pin/Invalid/index.messages.js | 2 +- .../modals/pin/Pin/index.messages.js | 2 +- .../components/OnlineStatus/index.messages.js | 2 +- .../components/UpdateBridge/index.messages.js | 2 +- .../UpdateFirmware/index.messages.js | 2 +- .../components/Account/index.messages.js | 2 +- .../components/Static/index.messages.js | 2 +- src/flowtype/index.js | 3 +++ src/flowtype/npm/react-intl.js | 14 ------------ src/support/ConnectedIntlProvider.js | 14 ++++++++++++ .../BetaDisclaimer/index.messages.js | 2 +- .../BrowserNotSupported/index.messages.js | 2 +- .../ConnectDevice/index.messages.js | 2 +- .../views/InstallBridge/index.messages.js | 2 +- .../FirmwareUnsupported/index.messages.js | 2 +- .../components/Content/index.messages.js | 2 +- .../components/AccountMenu/index.messages.js | 2 +- .../components/CoinMenu/index.messages.js | 2 +- .../components/MenuItems/index.messages.js | 2 +- .../components/DeviceMenu/index.messages.js | 2 +- .../LeftNavigation/index.messages.js | 2 +- .../TopNavigationAccount/index.messages.js | 2 +- .../views/Account/Receive/common.messages.js | 2 +- .../VerifyAddressTooltip/index.messages.js | 2 +- .../Receive/ethereum/index.messages.js | 2 +- .../Account/Receive/ripple/index.messages.js | 2 +- .../components/AdvancedForm/index.messages.js | 2 +- .../Account/Send/ethereum/index.messages.js | 22 ++++++++++++++++++- .../components/AdvancedForm/index.messages.js | 2 +- .../Account/Send/ripple/index.messages.js | 2 +- .../views/Account/Send/validation.messages.js | 2 +- .../Account/SignVerify/index.messages.js | 2 +- .../views/Account/Summary/common.messages.js | 2 +- .../AddTokenMessage/index.messages.js | 2 +- .../components/Balance/index.messages.js | 2 +- .../Wallet/views/Account/common.messages.js | 2 +- .../Wallet/views/Acquire/index.messages.js | 2 +- .../Wallet/views/Bootloader/index.messages.js | 2 +- .../Wallet/views/Dashboard/index.messages.js | 2 +- .../views/FirmwareUpdate/index.messages.js | 2 +- .../Wallet/views/Initialize/index.messages.js | 2 +- .../Wallet/views/NoBackup/index.messages.js | 2 +- .../Wallet/views/Seedless/index.messages.js | 2 +- .../views/UnreadableDevice/index.messages.js | 2 +- .../views/WalletSettings/index.messages.js | 2 +- src/views/common.messages.js | 2 +- 65 files changed, 99 insertions(+), 76 deletions(-) delete mode 100644 src/flowtype/npm/react-intl.js diff --git a/src/components/DeviceHeader/index.messages.js b/src/components/DeviceHeader/index.messages.js index dba5b890..d5058a07 100644 --- a/src/components/DeviceHeader/index.messages.js +++ b/src/components/DeviceHeader/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_CONNECTED: { diff --git a/src/components/Footer/index.messages.js b/src/components/Footer/index.messages.js index f5e1efb8..19542e56 100644 --- a/src/components/Footer/index.messages.js +++ b/src/components/Footer/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_TERMS: { diff --git a/src/components/Header/index.messages.js b/src/components/Header/index.messages.js index d9f5f048..1e4adb0a 100644 --- a/src/components/Header/index.messages.js +++ b/src/components/Header/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_MENU: { diff --git a/src/components/Log/index.messages.js b/src/components/Log/index.messages.js index 702d677c..11e6711b 100644 --- a/src/components/Log/index.messages.js +++ b/src/components/Log/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_ATTENTION_COLON_THE_LOG_CONTAINS: { diff --git a/src/components/modals/QrModal/index.messages.js b/src/components/modals/QrModal/index.messages.js index 2b188323..99582c0a 100644 --- a/src/components/modals/QrModal/index.messages.js +++ b/src/components/modals/QrModal/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_SCAN_QR_CODE: { diff --git a/src/components/modals/confirm/Action/index.messages.js b/src/components/modals/confirm/Action/index.messages.js index d98eed09..0d675228 100644 --- a/src/components/modals/confirm/Action/index.messages.js +++ b/src/components/modals/confirm/Action/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_CONFIRM_ACTION_ON_YOUR: { diff --git a/src/components/modals/confirm/Address/index.messages.js b/src/components/modals/confirm/Address/index.messages.js index c1d0f4b3..854523ee 100644 --- a/src/components/modals/confirm/Address/index.messages.js +++ b/src/components/modals/confirm/Address/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_CONFIRM_ADDRESS_ON_TREZOR: { diff --git a/src/components/modals/confirm/SignTx/index.messages.js b/src/components/modals/confirm/SignTx/index.messages.js index a712178e..8c402546 100644 --- a/src/components/modals/confirm/SignTx/index.messages.js +++ b/src/components/modals/confirm/SignTx/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_CONFIRM_TRANSACTION_ON: { diff --git a/src/components/modals/confirm/UnverifiedAddress/index.messages.js b/src/components/modals/confirm/UnverifiedAddress/index.messages.js index 2d178924..9390b84b 100644 --- a/src/components/modals/confirm/UnverifiedAddress/index.messages.js +++ b/src/components/modals/confirm/UnverifiedAddress/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_DEVICE_LABEL_IS_NOT_CONNECTED: { diff --git a/src/components/modals/device/Forget/index.messages.js b/src/components/modals/device/Forget/index.messages.js index 44009d1a..f8ee3434 100644 --- a/src/components/modals/device/Forget/index.messages.js +++ b/src/components/modals/device/Forget/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_DONT_FORGET: { diff --git a/src/components/modals/device/Remember/index.messages.js b/src/components/modals/device/Remember/index.messages.js index 01527d70..a6c94261 100644 --- a/src/components/modals/device/Remember/index.messages.js +++ b/src/components/modals/device/Remember/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_WOULD_YOU_LIKE_TREZOR_WALLET_TO: { diff --git a/src/components/modals/device/WalletType/index.messages.js b/src/components/modals/device/WalletType/index.messages.js index 4a44e42e..d922ebf5 100644 --- a/src/components/modals/device/WalletType/index.messages.js +++ b/src/components/modals/device/WalletType/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_SELECT_WALLET_TYPE_FOR: { diff --git a/src/components/modals/device/common.messages.js b/src/components/modals/device/common.messages.js index dba13e76..1af408eb 100644 --- a/src/components/modals/device/common.messages.js +++ b/src/components/modals/device/common.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_FORGET_LABEL: { diff --git a/src/components/modals/external/Cardano/index.messages.js b/src/components/modals/external/Cardano/index.messages.js index 46e56145..346ace8d 100644 --- a/src/components/modals/external/Cardano/index.messages.js +++ b/src/components/modals/external/Cardano/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_CARDANO_WALLET: { diff --git a/src/components/modals/external/Nem/index.messages.js b/src/components/modals/external/Nem/index.messages.js index 73edae65..84b4a42b 100644 --- a/src/components/modals/external/Nem/index.messages.js +++ b/src/components/modals/external/Nem/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_NEM_WALLET: { diff --git a/src/components/modals/external/Stellar/index.messages.js b/src/components/modals/external/Stellar/index.messages.js index 1708c8a4..f8d8e636 100644 --- a/src/components/modals/external/Stellar/index.messages.js +++ b/src/components/modals/external/Stellar/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_STELLAR_WALLET: { diff --git a/src/components/modals/external/Tezos/index.messages.js b/src/components/modals/external/Tezos/index.messages.js index 9e45f267..f0903fc3 100644 --- a/src/components/modals/external/Tezos/index.messages.js +++ b/src/components/modals/external/Tezos/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_TEZOS_WALLET: { diff --git a/src/components/modals/external/common.messages.js b/src/components/modals/external/common.messages.js index 85079861..a9fc3939 100644 --- a/src/components/modals/external/common.messages.js +++ b/src/components/modals/external/common.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_YOU_WILL_BE_REDIRECTED_TO_EXTERNAL: { diff --git a/src/components/modals/passphrase/Passphrase/index.messages.js b/src/components/modals/passphrase/Passphrase/index.messages.js index 1c059114..4f6e14f0 100644 --- a/src/components/modals/passphrase/Passphrase/index.messages.js +++ b/src/components/modals/passphrase/Passphrase/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_ENTER_DEVICE_PASSPHRASE: { diff --git a/src/components/modals/pin/Invalid/index.messages.js b/src/components/modals/pin/Invalid/index.messages.js index 96c2deac..9894590d 100644 --- a/src/components/modals/pin/Invalid/index.messages.js +++ b/src/components/modals/pin/Invalid/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_ENTERED_PIN_NOT_CORRECT: { diff --git a/src/components/modals/pin/Pin/index.messages.js b/src/components/modals/pin/Pin/index.messages.js index 05a0d9d9..7cde70d2 100644 --- a/src/components/modals/pin/Pin/index.messages.js +++ b/src/components/modals/pin/Pin/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_THE_PIN_LAYOUT_IS_DISPLAYED_ON: { diff --git a/src/components/notifications/App/components/OnlineStatus/index.messages.js b/src/components/notifications/App/components/OnlineStatus/index.messages.js index 2ea38151..0292a737 100644 --- a/src/components/notifications/App/components/OnlineStatus/index.messages.js +++ b/src/components/notifications/App/components/OnlineStatus/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_YOU_WERE_DISCONNECTED_DOT: { diff --git a/src/components/notifications/App/components/UpdateBridge/index.messages.js b/src/components/notifications/App/components/UpdateBridge/index.messages.js index f7d108ec..bf12a26f 100644 --- a/src/components/notifications/App/components/UpdateBridge/index.messages.js +++ b/src/components/notifications/App/components/UpdateBridge/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_NEW_TREZOR_BRIDGE_IS_AVAILABLE: { diff --git a/src/components/notifications/App/components/UpdateFirmware/index.messages.js b/src/components/notifications/App/components/UpdateFirmware/index.messages.js index 9984065e..feca1eb7 100644 --- a/src/components/notifications/App/components/UpdateFirmware/index.messages.js +++ b/src/components/notifications/App/components/UpdateFirmware/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_NEW_TREZOR_FIRMWARE_IS_AVAILABLE_DOT: { diff --git a/src/components/notifications/Context/components/Account/index.messages.js b/src/components/notifications/Context/components/Account/index.messages.js index 9090e6d2..436faa00 100644 --- a/src/components/notifications/Context/components/Account/index.messages.js +++ b/src/components/notifications/Context/components/Account/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_CONNECT_TO_BACKEND: { diff --git a/src/components/notifications/Context/components/Static/index.messages.js b/src/components/notifications/Context/components/Static/index.messages.js index 2fea53b3..ee7eec29 100644 --- a/src/components/notifications/Context/components/Static/index.messages.js +++ b/src/components/notifications/Context/components/Static/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_MINIMUM_ACCOUNT_RESERVE_REQUIRED: { diff --git a/src/flowtype/index.js b/src/flowtype/index.js index e91fa06d..e56564df 100644 --- a/src/flowtype/index.js +++ b/src/flowtype/index.js @@ -163,6 +163,9 @@ export type { Token } from 'reducers/TokensReducer'; export type { Web3Instance } from 'reducers/Web3Reducer'; export type { BlockchainFeeLevel } from 'reducers/BlockchainReducer'; +export type { MessageDescriptor } from 'support/ConnectedIntlProvider'; // this service has no action file, all is written inside one file +export type { Messages } from 'support/ConnectedIntlProvider'; // this service has no action file, all is written inside one file + export type Accounts = $ElementType; export type LocalStorage = $ElementType; export type Config = $PropertyType<$ElementType, 'config'>; diff --git a/src/flowtype/npm/react-intl.js b/src/flowtype/npm/react-intl.js deleted file mode 100644 index 85b77ec3..00000000 --- a/src/flowtype/npm/react-intl.js +++ /dev/null @@ -1,14 +0,0 @@ -export type MessageDescriptor = { - // A unique, stable identifier for the message - id: string, - - // The default message (probably in English) - defaultMessage: string, - - // Context for the translator about how it's used in the UI - description?: string | object, -}; - -export type Messages = { - [key: string]: MessageDescriptor -}; \ No newline at end of file diff --git a/src/support/ConnectedIntlProvider.js b/src/support/ConnectedIntlProvider.js index 547ebaa0..e216072d 100644 --- a/src/support/ConnectedIntlProvider.js +++ b/src/support/ConnectedIntlProvider.js @@ -56,6 +56,20 @@ type Props = {| ...StateProps, |}; +export type MessageDescriptor = { + // A unique, stable identifier for the message + id: string, + // The default message (probably in English) + defaultMessage: string, + // Context for the translator about how it's used in the UI + description?: string, + values: { [key: string]: any }, +}; + +export type Messages = { + [key: string]: MessageDescriptor, +}; + const mapStateToProps = (state: State): StateProps => ({ locale: state.wallet.language, messages: state.wallet.messages, diff --git a/src/views/Landing/components/BetaDisclaimer/index.messages.js b/src/views/Landing/components/BetaDisclaimer/index.messages.js index e04f0148..bb6aa506 100644 --- a/src/views/Landing/components/BetaDisclaimer/index.messages.js +++ b/src/views/Landing/components/BetaDisclaimer/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_YOU_ARE_OPENING_TREZOR_BETA_WALLET: { diff --git a/src/views/Landing/components/BrowserNotSupported/index.messages.js b/src/views/Landing/components/BrowserNotSupported/index.messages.js index f6df97c4..e2090ff0 100644 --- a/src/views/Landing/components/BrowserNotSupported/index.messages.js +++ b/src/views/Landing/components/BrowserNotSupported/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_YOUR_BROWSER_IS_NOT_SUPPORTED: { diff --git a/src/views/Landing/components/ConnectDevice/index.messages.js b/src/views/Landing/components/ConnectDevice/index.messages.js index 262ea5c8..e704ed1f 100644 --- a/src/views/Landing/components/ConnectDevice/index.messages.js +++ b/src/views/Landing/components/ConnectDevice/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_TREZOR_WALLET_IS_AN_EASY_DASH: { diff --git a/src/views/Landing/views/InstallBridge/index.messages.js b/src/views/Landing/views/InstallBridge/index.messages.js index 296b01a5..c75f0e23 100644 --- a/src/views/Landing/views/InstallBridge/index.messages.js +++ b/src/views/Landing/views/InstallBridge/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_NEW_COMMUNICATION_TOOL: { diff --git a/src/views/Wallet/components/Content/components/FirmwareUnsupported/index.messages.js b/src/views/Wallet/components/Content/components/FirmwareUnsupported/index.messages.js index a0cc5d2d..7c3789f6 100644 --- a/src/views/Wallet/components/Content/components/FirmwareUnsupported/index.messages.js +++ b/src/views/Wallet/components/Content/components/FirmwareUnsupported/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_FIND_OUT_MORE_INFO: { diff --git a/src/views/Wallet/components/Content/index.messages.js b/src/views/Wallet/components/Content/index.messages.js index d5172823..f69f2e0a 100644 --- a/src/views/Wallet/components/Content/index.messages.js +++ b/src/views/Wallet/components/Content/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_INITIALIZING_ACCOUNTS: { diff --git a/src/views/Wallet/components/LeftNavigation/components/AccountMenu/index.messages.js b/src/views/Wallet/components/LeftNavigation/components/AccountMenu/index.messages.js index acb31062..e438e275 100644 --- a/src/views/Wallet/components/LeftNavigation/components/AccountMenu/index.messages.js +++ b/src/views/Wallet/components/LeftNavigation/components/AccountMenu/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_TO_ADD_A_NEW_ACCOUNT_LAST: { diff --git a/src/views/Wallet/components/LeftNavigation/components/CoinMenu/index.messages.js b/src/views/Wallet/components/LeftNavigation/components/CoinMenu/index.messages.js index fa837418..2117247b 100644 --- a/src/views/Wallet/components/LeftNavigation/components/CoinMenu/index.messages.js +++ b/src/views/Wallet/components/LeftNavigation/components/CoinMenu/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_OTHER_COINS: { diff --git a/src/views/Wallet/components/LeftNavigation/components/DeviceMenu/components/MenuItems/index.messages.js b/src/views/Wallet/components/LeftNavigation/components/DeviceMenu/components/MenuItems/index.messages.js index 69b1a565..7dce5a05 100644 --- a/src/views/Wallet/components/LeftNavigation/components/DeviceMenu/components/MenuItems/index.messages.js +++ b/src/views/Wallet/components/LeftNavigation/components/DeviceMenu/components/MenuItems/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_CHANGE_WALLET_TYPE: { diff --git a/src/views/Wallet/components/LeftNavigation/components/DeviceMenu/index.messages.js b/src/views/Wallet/components/LeftNavigation/components/DeviceMenu/index.messages.js index 3f8a287b..76d9d476 100644 --- a/src/views/Wallet/components/LeftNavigation/components/DeviceMenu/index.messages.js +++ b/src/views/Wallet/components/LeftNavigation/components/DeviceMenu/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({}); diff --git a/src/views/Wallet/components/LeftNavigation/index.messages.js b/src/views/Wallet/components/LeftNavigation/index.messages.js index 7a006bc9..5843f378 100644 --- a/src/views/Wallet/components/LeftNavigation/index.messages.js +++ b/src/views/Wallet/components/LeftNavigation/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_YOU_ARE_IN_YOUR_STANDARD_WALLET: { diff --git a/src/views/Wallet/components/TopNavigationAccount/index.messages.js b/src/views/Wallet/components/TopNavigationAccount/index.messages.js index 17b909fa..31571ad9 100644 --- a/src/views/Wallet/components/TopNavigationAccount/index.messages.js +++ b/src/views/Wallet/components/TopNavigationAccount/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_NAV_SUMMARY: { diff --git a/src/views/Wallet/views/Account/Receive/common.messages.js b/src/views/Wallet/views/Account/Receive/common.messages.js index b4e63d1e..df71b3e8 100644 --- a/src/views/Wallet/views/Account/Receive/common.messages.js +++ b/src/views/Wallet/views/Account/Receive/common.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_CHECK_ADDRESS_ON_TREZOR: { diff --git a/src/views/Wallet/views/Account/Receive/components/VerifyAddressTooltip/index.messages.js b/src/views/Wallet/views/Account/Receive/components/VerifyAddressTooltip/index.messages.js index 84deb9a1..c9b5c992 100644 --- a/src/views/Wallet/views/Account/Receive/components/VerifyAddressTooltip/index.messages.js +++ b/src/views/Wallet/views/Account/Receive/components/VerifyAddressTooltip/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_UNVERIFIED_ADDRESS_COMMA_CONNECT: { diff --git a/src/views/Wallet/views/Account/Receive/ethereum/index.messages.js b/src/views/Wallet/views/Account/Receive/ethereum/index.messages.js index a93d4675..43b2a929 100644 --- a/src/views/Wallet/views/Account/Receive/ethereum/index.messages.js +++ b/src/views/Wallet/views/Account/Receive/ethereum/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_RECEIVE_ETHEREUM_OR_TOKENS: { diff --git a/src/views/Wallet/views/Account/Receive/ripple/index.messages.js b/src/views/Wallet/views/Account/Receive/ripple/index.messages.js index 7f1cf34a..6bb92351 100644 --- a/src/views/Wallet/views/Account/Receive/ripple/index.messages.js +++ b/src/views/Wallet/views/Account/Receive/ripple/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_RECEIVE_RIPPLE: { diff --git a/src/views/Wallet/views/Account/Send/ethereum/components/AdvancedForm/index.messages.js b/src/views/Wallet/views/Account/Send/ethereum/components/AdvancedForm/index.messages.js index 1c66e01d..a925876b 100644 --- a/src/views/Wallet/views/Account/Send/ethereum/components/AdvancedForm/index.messages.js +++ b/src/views/Wallet/views/Account/Send/ethereum/components/AdvancedForm/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_GAS_LIMIT: { diff --git a/src/views/Wallet/views/Account/Send/ethereum/index.messages.js b/src/views/Wallet/views/Account/Send/ethereum/index.messages.js index a6be61a0..f2fde122 100644 --- a/src/views/Wallet/views/Account/Send/ethereum/index.messages.js +++ b/src/views/Wallet/views/Account/Send/ethereum/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_SEND_ETHEREUM_OR_TOKENS: { @@ -11,6 +11,26 @@ const definedMessages: Messages = defineMessages({ id: 'YOU_HAVE_TOKEN_BALANCE', defaultMessage: 'You have: {tokenBalance}', }, + TR_HIGH_FEE: { + id: 'TR_HIGH_FEE', + defaultMessage: 'High', + description: 'fee level', + }, + TR_NORMAL_FEE: { + id: 'TR_NORMAL_FEE', + defaultMessage: 'Normal', + description: 'fee level', + }, + TR_LOW_FEE: { + id: 'TR_LOW_FEE', + defaultMessage: 'Low', + description: 'fee level', + }, + TR_CUSTOM_FEE: { + id: 'TR_CUSTOM_FEE', + defaultMessage: 'Custom', + description: 'fee level', + }, }); export default definedMessages; diff --git a/src/views/Wallet/views/Account/Send/ripple/components/AdvancedForm/index.messages.js b/src/views/Wallet/views/Account/Send/ripple/components/AdvancedForm/index.messages.js index 3c9b8b76..2634bf24 100644 --- a/src/views/Wallet/views/Account/Send/ripple/components/AdvancedForm/index.messages.js +++ b/src/views/Wallet/views/Account/Send/ripple/components/AdvancedForm/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_XRP_TRANSFER_COST: { diff --git a/src/views/Wallet/views/Account/Send/ripple/index.messages.js b/src/views/Wallet/views/Account/Send/ripple/index.messages.js index f61ae33b..b1ce8ffd 100644 --- a/src/views/Wallet/views/Account/Send/ripple/index.messages.js +++ b/src/views/Wallet/views/Account/Send/ripple/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_XRP_RESERVE: { diff --git a/src/views/Wallet/views/Account/Send/validation.messages.js b/src/views/Wallet/views/Account/Send/validation.messages.js index a2a09450..c6f38cac 100644 --- a/src/views/Wallet/views/Account/Send/validation.messages.js +++ b/src/views/Wallet/views/Account/Send/validation.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_AMOUNT_IS_NOT_SET: { diff --git a/src/views/Wallet/views/Account/SignVerify/index.messages.js b/src/views/Wallet/views/Account/SignVerify/index.messages.js index 1e9ce9d1..4bf7f057 100644 --- a/src/views/Wallet/views/Account/SignVerify/index.messages.js +++ b/src/views/Wallet/views/Account/SignVerify/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_MESSAGE: { diff --git a/src/views/Wallet/views/Account/Summary/common.messages.js b/src/views/Wallet/views/Account/Summary/common.messages.js index 63422066..70baa681 100644 --- a/src/views/Wallet/views/Account/Summary/common.messages.js +++ b/src/views/Wallet/views/Account/Summary/common.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_SEE_FULL_TRANSACTION_HISTORY: { diff --git a/src/views/Wallet/views/Account/Summary/components/AddTokenMessage/index.messages.js b/src/views/Wallet/views/Account/Summary/components/AddTokenMessage/index.messages.js index 7df755cb..84b9a713 100644 --- a/src/views/Wallet/views/Account/Summary/components/AddTokenMessage/index.messages.js +++ b/src/views/Wallet/views/Account/Summary/components/AddTokenMessage/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_ADD_YOUR_TOKENS: { diff --git a/src/views/Wallet/views/Account/Summary/components/Balance/index.messages.js b/src/views/Wallet/views/Account/Summary/components/Balance/index.messages.js index 1799efec..4ed69ab0 100644 --- a/src/views/Wallet/views/Account/Summary/components/Balance/index.messages.js +++ b/src/views/Wallet/views/Account/Summary/components/Balance/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_BALANCE: { diff --git a/src/views/Wallet/views/Account/common.messages.js b/src/views/Wallet/views/Account/common.messages.js index 11af684f..7bb674cc 100644 --- a/src/views/Wallet/views/Account/common.messages.js +++ b/src/views/Wallet/views/Account/common.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_AMOUNT: { diff --git a/src/views/Wallet/views/Acquire/index.messages.js b/src/views/Wallet/views/Acquire/index.messages.js index fed99f30..fb2c1223 100644 --- a/src/views/Wallet/views/Acquire/index.messages.js +++ b/src/views/Wallet/views/Acquire/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_DEVICE_USED_IN_OTHER: { diff --git a/src/views/Wallet/views/Bootloader/index.messages.js b/src/views/Wallet/views/Bootloader/index.messages.js index ecac185d..196c3c49 100644 --- a/src/views/Wallet/views/Bootloader/index.messages.js +++ b/src/views/Wallet/views/Bootloader/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_YOUR_DEVICE_IS_IN_FIRMWARE: { diff --git a/src/views/Wallet/views/Dashboard/index.messages.js b/src/views/Wallet/views/Dashboard/index.messages.js index cf2e5329..936115cf 100644 --- a/src/views/Wallet/views/Dashboard/index.messages.js +++ b/src/views/Wallet/views/Dashboard/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_PLEASE_SELECT_YOUR: { diff --git a/src/views/Wallet/views/FirmwareUpdate/index.messages.js b/src/views/Wallet/views/FirmwareUpdate/index.messages.js index 82136c53..cbfe3854 100644 --- a/src/views/Wallet/views/FirmwareUpdate/index.messages.js +++ b/src/views/Wallet/views/FirmwareUpdate/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_ITS_TIME_TO_UPDATE_FIRMWARE: { diff --git a/src/views/Wallet/views/Initialize/index.messages.js b/src/views/Wallet/views/Initialize/index.messages.js index 42b99f66..409a0015 100644 --- a/src/views/Wallet/views/Initialize/index.messages.js +++ b/src/views/Wallet/views/Initialize/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_YOUR_DEVICE_IS_NOT_INITIALIZED: { diff --git a/src/views/Wallet/views/NoBackup/index.messages.js b/src/views/Wallet/views/NoBackup/index.messages.js index 717ab097..73762f56 100644 --- a/src/views/Wallet/views/NoBackup/index.messages.js +++ b/src/views/Wallet/views/NoBackup/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_PLEASE_USE_TO_CREATE_BACKUP: { diff --git a/src/views/Wallet/views/Seedless/index.messages.js b/src/views/Wallet/views/Seedless/index.messages.js index 4e791146..91f471ea 100644 --- a/src/views/Wallet/views/Seedless/index.messages.js +++ b/src/views/Wallet/views/Seedless/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_DEVICE_IS_INITIALIZED_IN_SEEDLESS_MODE: { diff --git a/src/views/Wallet/views/UnreadableDevice/index.messages.js b/src/views/Wallet/views/UnreadableDevice/index.messages.js index 55b15e17..83578f42 100644 --- a/src/views/Wallet/views/UnreadableDevice/index.messages.js +++ b/src/views/Wallet/views/UnreadableDevice/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_UNREADABLE_DEVICE: { diff --git a/src/views/Wallet/views/WalletSettings/index.messages.js b/src/views/Wallet/views/WalletSettings/index.messages.js index b22ad616..a17d2227 100644 --- a/src/views/Wallet/views/WalletSettings/index.messages.js +++ b/src/views/Wallet/views/WalletSettings/index.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_LOCAL_CURRENCY: { diff --git a/src/views/common.messages.js b/src/views/common.messages.js index 43047d19..caafbcc7 100644 --- a/src/views/common.messages.js +++ b/src/views/common.messages.js @@ -1,6 +1,6 @@ /* @flow */ import { defineMessages } from 'react-intl'; -import type { Messages } from 'flowtype/npm/react-intl'; +import type { Messages } from 'flowtype'; const definedMessages: Messages = defineMessages({ TR_DEVICE_SETTINGS: { From 0c4d9d7311fa6cd08fa1a14b171c35e58367b831 Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Mon, 29 Apr 2019 12:56:36 +0200 Subject: [PATCH 06/17] l10n support for validation in eth send form --- src/actions/ethereum/SendFormActions.js | 3 +- .../ethereum/SendFormValidationActions.js | 154 ++++++++---------- src/actions/ripple/SendFormActions.js | 1 + src/reducers/SendFormEthereumReducer.js | 10 +- src/support/ConnectedIntlProvider.js | 2 +- .../ethereum/components/AdvancedForm/index.js | 12 +- .../views/Account/Send/ethereum/index.js | 33 +++- .../Account/Send/ethereum/index.messages.js | 20 --- src/views/common.messages.js | 30 ++++ 9 files changed, 135 insertions(+), 130 deletions(-) diff --git a/src/actions/ethereum/SendFormActions.js b/src/actions/ethereum/SendFormActions.js index c1983404..efc57868 100644 --- a/src/actions/ethereum/SendFormActions.js +++ b/src/actions/ethereum/SendFormActions.js @@ -427,7 +427,8 @@ export const onFeeLevelChange = (feeLevel: FeeLevel): ThunkAction => ( } newGasPrice = feeLevel.gasPrice; } - + console.log('selected'); + console.log(feeLevel); dispatch({ type: SEND.CHANGE, networkType: 'ethereum', diff --git a/src/actions/ethereum/SendFormValidationActions.js b/src/actions/ethereum/SendFormValidationActions.js index 8a3ef2b7..fe01a718 100644 --- a/src/actions/ethereum/SendFormValidationActions.js +++ b/src/actions/ethereum/SendFormValidationActions.js @@ -5,7 +5,6 @@ import EthereumjsUtil from 'ethereumjs-util'; import EthereumjsUnits from 'ethereumjs-units'; import { findDevice, getPendingAmount, findToken } from 'reducers/utils'; import { toFiatCurrency } from 'utils/fiatConverter'; -import { IntlProvider } from 'react-intl'; import * as SEND from 'actions/constants/send'; import * as ethUtils from 'utils/ethUtils'; import * as validators from 'utils/validators'; @@ -13,6 +12,8 @@ import * as validators from 'utils/validators'; import type { Dispatch, GetState, PayloadAction } from 'flowtype'; import type { State, FeeLevel } from 'reducers/SendFormEthereumReducer'; import l10nMessages from 'views/Wallet/views/Account/Send/validation.messages'; +import l10nCommonMessages from 'views/common.messages'; + /* * Called from SendFormActions.observe * Reaction for WEB3.GAS_PRICE_UPDATED action @@ -144,15 +145,7 @@ export const updateCustomFeeLabel = ($state: State): PayloadAction => (): /* * Address value validation */ -export const addressValidation = ($state: State): PayloadAction => ( - dispatch: Dispatch, - getState: GetState -): State => { - // get react-intl imperative api - const { language, messages } = getState().wallet; - const intlProvider = new IntlProvider({ language, messages }); - const { intl } = intlProvider.getChildContext(); - +export const addressValidation = ($state: State): PayloadAction => (): State => { const state = { ...$state }; if (!state.touched.address) return state; @@ -160,16 +153,16 @@ export const addressValidation = ($state: State): PayloadAction => ( if (address.length < 1) { // state.errors.address = 'Address is not set'; - state.errors.address = intl.formatMessage(l10nMessages.TR_ADDRESS_IS_NOT_SET); + state.errors.address = l10nMessages.TR_ADDRESS_IS_NOT_SET; } else if (!EthereumjsUtil.isValidAddress(address)) { // state.errors.address = 'Address is not valid'; - state.errors.address = intl.formatMessage(l10nMessages.TR_ADDRESS_IS_NOT_VALID); + state.errors.address = l10nMessages.TR_ADDRESS_IS_NOT_VALID; } else if ( validators.hasUppercase(address) && !EthereumjsUtil.isValidChecksumAddress(address) ) { // state.errors.address = 'Address is not a valid checksum'; - state.errors.address = intl.formatMessage(l10nMessages.TR_ADDRESS_CHECKSUM_IS_NOT_VALID); + state.errors.address = l10nMessages.TR_ADDRESS_CHECKSUM_IS_NOT_VALID; } return state; }; @@ -201,9 +194,13 @@ export const addressLabel = ($state: State): PayloadAction => ( currentNetworkAccount.deviceState ); if (device) { - state.infos.address = `${ - device.instanceLabel - } Account #${currentNetworkAccount.index + 1}`; + state.infos.address = { + ...l10nCommonMessages.TR_DEVICE_LABEL_ACCOUNT_HASH, + values: { + deviceLabel: device.instanceLabel, + number: currentNetworkAccount.index + 1, + }, + }; } } else { // corner-case: the same derivation path is used on different networks @@ -216,11 +213,14 @@ export const addressLabel = ($state: State): PayloadAction => ( const { networks } = getState().localStorage.config; const otherNetwork = networks.find(c => c.shortcut === otherNetworkAccount.network); if (device && otherNetwork) { - state.warnings.address = `Looks like it's ${ - device.instanceLabel - } Account #${otherNetworkAccount.index + 1} address of ${ - otherNetwork.name - } network`; + state.warnings.address = { + ...l10nCommonMessages.TR_LOOKS_LIKE_IT_IS_DEVICE_LABEL, + values: { + deviceLabel: device.instanceLabel, + number: otherNetworkAccount.index + 1, + network: otherNetwork.name, + }, + }; } } } @@ -241,18 +241,13 @@ export const amountValidation = ($state: State): PayloadAction => ( const { account, tokens, pending } = getState().selectedAccount; if (!account) return state; - // get react-intl imperative api - const { language, messages } = getState().wallet; - const intlProvider = new IntlProvider({ language, messages }); - const { intl } = intlProvider.getChildContext(); - const { amount } = state; if (amount.length < 1) { // state.errors.amount = 'Amount is not set'; - state.errors.amount = intl.formatMessage(l10nMessages.TR_AMOUNT_IS_NOT_SET); + state.errors.amount = l10nMessages.TR_AMOUNT_IS_NOT_SET; } else if (amount.length > 0 && !validators.isNumber(amount)) { // state.errors.amount = 'Amount is not a number'; - state.errors.amount = intl.formatMessage(l10nMessages.TR_AMOUNT_IS_NOT_A_NUMBER); + state.errors.amount = l10nMessages.TR_AMOUNT_IS_NOT_A_NUMBER; } else { const isToken: boolean = state.currency !== state.networkSymbol; const pendingAmount: BigNumber = getPendingAmount(pending, state.currency, isToken); @@ -268,16 +263,17 @@ export const amountValidation = ($state: State): PayloadAction => ( if (!validators.hasDecimals(state.amount, parseInt(token.decimals, 0))) { // state.errors.amount = `Maximum ${token.decimals} decimals allowed`; - state.errors.amount = intl.formatMessage(l10nMessages.TR_MAXIMUM_DECIMALS_ALLOWED, { - decimals: token.decimals, - }); + state.errors.amount = { + ...l10nMessages.TR_MAXIMUM_DECIMALS_ALLOWED, + values: { decimals: token.decimals }, + }; } else if (new BigNumber(state.total).isGreaterThan(account.balance)) { - state.errors.amount = intl.formatMessage( - l10nMessages.TR_NOT_ENOUGH_FUNDS_TO_COVER_TRANSACTION, - { + state.errors.amount = { + ...l10nMessages.TR_NOT_ENOUGH_FUNDS_TO_COVER_TRANSACTION, + values: { networkSymbol: state.networkSymbol, - } - ); + }, + }; // state.errors.amount = `Not enough ${state.networkSymbol} to cover transaction fee`; } else if ( new BigNumber(state.amount).isGreaterThan( @@ -285,24 +281,27 @@ export const amountValidation = ($state: State): PayloadAction => ( ) ) { // state.errors.amount = 'Not enough funds'; - state.errors.amount = intl.formatMessage(l10nMessages.TR_NOT_ENOUGH_FUNDS); + state.errors.amount = l10nMessages.TR_NOT_ENOUGH_FUNDS; } else if (new BigNumber(state.amount).isLessThanOrEqualTo('0')) { // TODO: this is never gonna happen! It will fail in second if condiftion (isNumber validation) // state.errors.amount = 'Amount is too low'; - state.errors.amount = intl.formatMessage(l10nMessages.TR_AMOUNT_IS_TOO_LOW); + state.errors.amount = l10nMessages.TR_AMOUNT_IS_TOO_LOW; } } else if (!validators.hasDecimals(state.amount, 18)) { // state.errors.amount = 'Maximum 18 decimals allowed'; - state.errors.amount = intl.formatMessage(l10nMessages.TR_MAXIMUM_DECIMALS_ALLOWED, { - decimals: 18, - }); + state.errors.amount = { + ...l10nMessages.TR_MAXIMUM_DECIMALS_ALLOWED, + values: { + decimals: 18, + }, + }; } else if ( new BigNumber(state.total).isGreaterThan( new BigNumber(account.balance).minus(pendingAmount) ) ) { // state.errors.amount = 'Not enough funds'; - state.errors.amount = intl.formatMessage(l10nMessages.TR_NOT_ENOUGH_FUNDS); + state.errors.amount = l10nMessages.TR_NOT_ENOUGH_FUNDS; } } return state; @@ -321,23 +320,18 @@ export const gasLimitValidation = ($state: State): PayloadAction => ( const { network } = getState().selectedAccount; if (!network) return state; - // get react-intl imperative api - const { language, messages } = getState().wallet; - const intlProvider = new IntlProvider({ language, messages }); - const { intl } = intlProvider.getChildContext(); - const { gasLimit } = state; if (gasLimit.length < 1) { // state.errors.gasLimit = 'Gas limit is not set'; - state.errors.gasLimit = intl.formatMessage(l10nMessages.TR_GAS_LIMIT_IS_NOT_SET); + state.errors.gasLimit = l10nMessages.TR_GAS_LIMIT_IS_NOT_SET; } else if (gasLimit.length > 0 && !validators.isNumber(gasLimit)) { // state.errors.gasLimit = 'Gas limit is not a number'; - state.errors.gasLimit = intl.formatMessage(l10nMessages.TR_GAS_LIMIT_IS_NOT_A_NUMBER); + state.errors.gasLimit = l10nMessages.TR_GAS_LIMIT_IS_NOT_A_NUMBER; } else { const gl: BigNumber = new BigNumber(gasLimit); if (gl.isLessThan(1)) { // state.errors.gasLimit = 'Gas limit is too low'; - state.errors.gasLimit = intl.formatMessage(l10nMessages.TR_GAS_LIMIT_IS_TOO_LOW); + state.errors.gasLimit = l10nMessages.TR_GAS_LIMIT_IS_TOO_LOW; } else if ( gl.isLessThan( state.currency !== state.networkSymbol @@ -346,9 +340,7 @@ export const gasLimitValidation = ($state: State): PayloadAction => ( ) ) { // state.warnings.gasLimit = 'Gas limit is below recommended'; - state.warnings.gasLimit = intl.formatMessage( - l10nMessages.TR_GAS_LIMIT_IS_BELOW_RECOMMENDED - ); + state.warnings.gasLimit = l10nMessages.TR_GAS_LIMIT_IS_BELOW_RECOMMENDED; } } return state; @@ -357,33 +349,25 @@ export const gasLimitValidation = ($state: State): PayloadAction => ( /* * Gas price value validation */ -export const gasPriceValidation = ($state: State): PayloadAction => ( - dispatch: Dispatch, - getState: GetState -): State => { +export const gasPriceValidation = ($state: State): PayloadAction => (): 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 = intl.formatMessage(l10nMessages.TR_GAS_PRICE_IS_NOT_SET); + state.errors.gasPrice = 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 = intl.formatMessage(l10nMessages.TR_GAS_PRICE_IS_NOT_A_NUMBER); + state.errors.gasPrice = 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 = intl.formatMessage(l10nMessages.TR_GAS_PRICE_IS_TOO_HIGH); + state.warnings.gasPrice = l10nMessages.TR_GAS_PRICE_IS_TOO_HIGH; } else if (gp.isLessThanOrEqualTo('0')) { // state.errors.gasPrice = 'Gas price is too low'; - state.errors.gasPrice = intl.formatMessage(l10nMessages.TR_GAS_PRICE_IS_TOO_LOW); + state.errors.gasPrice = l10nMessages.TR_GAS_PRICE_IS_TOO_LOW; } } return state; @@ -399,33 +383,24 @@ 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 = intl.formatMessage(l10nMessages.TR_NONCE_IS_NOT_SET); + state.errors.nonce = l10nMessages.TR_NONCE_IS_NOT_SET; } else if (!validators.isAbs(nonce)) { // state.errors.nonce = 'Nonce is not a valid number'; - state.errors.nonce = intl.formatMessage(l10nMessages.TR_NONCE_IS_NOT_A_NUMBER); + state.errors.nonce = 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 = intl.formatMessage( - l10nMessages.TR_NONCE_IS_LOWER_THAN_RECOMMENDED - ); + state.warnings.nonce = l10nMessages.TR_NONCE_IS_LOWER_THAN_RECOMMENDED; } else if (n.isGreaterThan(account.nonce)) { // state.warnings.nonce = 'Nonce is greater than recommended'; - state.warnings.nonce = intl.formatMessage( - l10nMessages.TR_NONCE_IS_GREATER_THAN_RECOMMENDED - ); + state.warnings.nonce = l10nMessages.TR_NONCE_IS_GREATER_THAN_RECOMMENDED; } } return state; @@ -434,21 +409,13 @@ export const nonceValidation = ($state: State): PayloadAction => ( /* * Data validation */ -export const dataValidation = ($state: State): PayloadAction => ( - dispatch: Dispatch, - getState: GetState -): State => { +export const dataValidation = ($state: State): PayloadAction => (): 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 = intl.formatMessage(l10nMessages.TR_DATA_IS_NOT_VALID_HEX); + state.errors.data = l10nMessages.TR_DATA_IS_NOT_VALID_HEX; } return state; }; @@ -513,29 +480,38 @@ export const getFeeLevels = ( selected && selected.value === 'Custom' ? { value: 'Custom', + localizedValue: l10nCommonMessages.TR_CUSTOM_FEE, gasPrice: selected.gasPrice, // label: `${ calculateFee(gasPrice, gasLimit) } ${ symbol }` label: `${calculateFee(selected.gasPrice, gasLimit)} ${symbol}`, } : { value: 'Custom', + localizedValue: l10nCommonMessages.TR_CUSTOM_FEE, gasPrice: low, label: '', }; + console.log(l10nCommonMessages.TR_LOW_FEE); + console.log(l10nCommonMessages.TR_NORMAL_FEE); + console.log(l10nCommonMessages.TR_HIGH_FEE); + console.log(l10nCommonMessages.TR_CUSTOM_FEE); return [ { value: 'High', + localizedValue: l10nCommonMessages.TR_HIGH_FEE, gasPrice: high, label: `${calculateFee(high, gasLimit)} ${symbol}`, }, { value: 'Normal', + localizedValue: l10nCommonMessages.TR_NORMAL_FEE, gasPrice: gasPrice.toString(), label: `${calculateFee(price.toFixed(), gasLimit)} ${symbol}`, }, { value: 'Low', + localizedValue: l10nCommonMessages.TR_LOW_FEE, gasPrice: low, label: `${calculateFee(low, gasLimit)} ${symbol}`, }, diff --git a/src/actions/ripple/SendFormActions.js b/src/actions/ripple/SendFormActions.js index 41c34fdc..b32f1cae 100644 --- a/src/actions/ripple/SendFormActions.js +++ b/src/actions/ripple/SendFormActions.js @@ -110,6 +110,7 @@ export const init = (): AsyncAction => async ( const blockchainFeeLevels = dispatch(BlockchainActions.getFeeLevels(network)); const feeLevels = dispatch(ValidationActions.getFeeLevels(blockchainFeeLevels)); + console.log(feeLevels); const selectedFeeLevel = ValidationActions.getSelectedFeeLevel( feeLevels, initialState.selectedFeeLevel diff --git a/src/reducers/SendFormEthereumReducer.js b/src/reducers/SendFormEthereumReducer.js index 23234658..78bdb322 100644 --- a/src/reducers/SendFormEthereumReducer.js +++ b/src/reducers/SendFormEthereumReducer.js @@ -3,7 +3,8 @@ import * as SEND from 'actions/constants/send'; import * as ACCOUNT from 'actions/constants/account'; -import type { Action } from 'flowtype'; +import type { Action, MessageDescriptor } from 'flowtype'; +import l10nCommonMessages from 'views/common.messages'; export type FeeLevel = { label: string, @@ -36,9 +37,9 @@ export type State = { nonce: string, total: string, - errors: { [k: string]: string }, - warnings: { [k: string]: string }, - infos: { [k: string]: string }, + errors: { [k: string]: MessageDescriptor }, + warnings: { [k: string]: MessageDescriptor }, + infos: { [k: string]: MessageDescriptor }, sending: boolean, }; @@ -62,6 +63,7 @@ export const initialState: State = { label: 'Normal', gasPrice: '0', value: 'Normal', + localizedValue: l10nCommonMessages.TR_NORMAL_FEE, }, recommendedGasPrice: '0', gasPriceNeedsUpdate: false, diff --git a/src/support/ConnectedIntlProvider.js b/src/support/ConnectedIntlProvider.js index e216072d..4ee8b55f 100644 --- a/src/support/ConnectedIntlProvider.js +++ b/src/support/ConnectedIntlProvider.js @@ -63,7 +63,7 @@ export type MessageDescriptor = { defaultMessage: string, // Context for the translator about how it's used in the UI description?: string, - values: { [key: string]: any }, + values?: { [key: string]: any }, }; export type Messages = { diff --git a/src/views/Wallet/views/Account/Send/ethereum/components/AdvancedForm/index.js b/src/views/Wallet/views/Account/Send/ethereum/components/AdvancedForm/index.js index 75fbb723..ebcfa99b 100644 --- a/src/views/Wallet/views/Account/Send/ethereum/components/AdvancedForm/index.js +++ b/src/views/Wallet/views/Account/Send/ethereum/components/AdvancedForm/index.js @@ -81,7 +81,7 @@ const AdvancedSettingsSendButtonWrapper = styled.div` justify-content: flex-end; `; -const getGasLimitInputState = (gasLimitErrors: string, gasLimitWarnings: string): ?string => { +const getGasLimitInputState = (gasLimitErrors: boolean, gasLimitWarnings: boolean): ?string => { let state = null; if (gasLimitWarnings && !gasLimitErrors) { state = 'warning'; @@ -92,7 +92,7 @@ const getGasLimitInputState = (gasLimitErrors: string, gasLimitWarnings: string) return state; }; -const getGasPriceInputState = (gasPriceErrors: string, gasPriceWarnings: string): ?string => { +const getGasPriceInputState = (gasPriceErrors: boolean, gasPriceWarnings: boolean): ?string => { let state = null; if (gasPriceWarnings && !gasPriceErrors) { state = 'warning'; @@ -103,7 +103,7 @@ const getGasPriceInputState = (gasPriceErrors: string, gasPriceWarnings: string) return state; }; -const getDataTextareaState = (dataError: string, dataWarning: string): ?string => { +const getDataTextareaState = (dataError: boolean, dataWarning: boolean): ?string => { let state = null; if (dataWarning) { state = 'warning'; @@ -177,7 +177,7 @@ const AdvancedForm = (props: Props) => { { /> { } - state={getDataTextareaState(errors.data, warnings.data)} + state={getDataTextareaState(!!errors.data, !!warnings.data)} bottomText={errors.data || warnings.data || infos.data} isDisabled={networkSymbol !== currency} value={networkSymbol !== currency ? '' : data} diff --git a/src/views/Wallet/views/Account/Send/ethereum/index.js b/src/views/Wallet/views/Account/Send/ethereum/index.js index fe6ebed5..1435a313 100644 --- a/src/views/Wallet/views/Account/Send/ethereum/index.js +++ b/src/views/Wallet/views/Account/Send/ethereum/index.js @@ -204,8 +204,8 @@ const StyledIcon = styled(Icon)` // render helpers const getAddressInputState = ( address: string, - addressErrors: string, - addressWarnings: string + addressErrors: boolean, + addressWarnings: boolean ): ?string => { let state = null; if (address && !addressErrors) { @@ -220,7 +220,7 @@ const getAddressInputState = ( return state; }; -const getAmountInputState = (amountErrors: string, amountWarnings: string): ?string => { +const getAmountInputState = (amountErrors: boolean, amountWarnings: boolean): ?string => { let state = null; if (amountWarnings && !amountErrors) { state = 'warning'; @@ -347,13 +347,19 @@ const AccountSend = (props: Props) => { + {errors.address && } + {warnings.address && } + {infos.address && } + + } value={address} onChange={event => onAddressChange(event.target.value)} sideAddons={[ @@ -365,7 +371,7 @@ const AccountSend = (props: Props) => { { } value={amount} onChange={event => onAmountChange(event.target.value)} - bottomText={errors.amount || warnings.amount || infos.amount} + bottomText={ + <> + {errors.amount && } + {warnings.amount && } + {infos.amount && } + + } sideAddons={[ onSetMax()} isWhite={!setMax}> {!setMax && ( @@ -420,7 +432,7 @@ const AccountSend = (props: Props) => { = { options={feeLevels} formatOptionLabel={option => ( - {option.value} + {console.log(option)} + + + {option.label} )} diff --git a/src/views/Wallet/views/Account/Send/ethereum/index.messages.js b/src/views/Wallet/views/Account/Send/ethereum/index.messages.js index f2fde122..700cdb91 100644 --- a/src/views/Wallet/views/Account/Send/ethereum/index.messages.js +++ b/src/views/Wallet/views/Account/Send/ethereum/index.messages.js @@ -11,26 +11,6 @@ const definedMessages: Messages = defineMessages({ id: 'YOU_HAVE_TOKEN_BALANCE', defaultMessage: 'You have: {tokenBalance}', }, - TR_HIGH_FEE: { - id: 'TR_HIGH_FEE', - defaultMessage: 'High', - description: 'fee level', - }, - TR_NORMAL_FEE: { - id: 'TR_NORMAL_FEE', - defaultMessage: 'Normal', - description: 'fee level', - }, - TR_LOW_FEE: { - id: 'TR_LOW_FEE', - defaultMessage: 'Low', - description: 'fee level', - }, - TR_CUSTOM_FEE: { - id: 'TR_CUSTOM_FEE', - defaultMessage: 'Custom', - description: 'fee level', - }, }); export default definedMessages; diff --git a/src/views/common.messages.js b/src/views/common.messages.js index caafbcc7..8b83fc99 100644 --- a/src/views/common.messages.js +++ b/src/views/common.messages.js @@ -16,6 +16,16 @@ const definedMessages: Messages = defineMessages({ defaultMessage: 'Account #{number}', description: 'Used in auto-generated account label', }, + TR_DEVICE_LABEL_ACCOUNT_HASH: { + id: 'TR_DEVICE_LABEL_ACCOUNT_HASH', + defaultMessage: '{deviceLabel} Account #{number}', + description: 'Used in auto-generated account label', + }, + TR_LOOKS_LIKE_IT_IS_DEVICE_LABEL: { + id: 'TR_LOOKS_LIKE_IT_IS_DEVICE_LABEL', + defaultMessage: 'Looks like it is {deviceLabel} Account #{number} of {network}', + description: 'Example: Looks like it is My Trezor Account #1 of ETH', + }, TR_IMPORTED_ACCOUNT_HASH: { id: 'TR_IMPORTED_ACCOUNT_HASH', defaultMessage: 'Imported account #{number}', @@ -100,6 +110,26 @@ const definedMessages: Messages = defineMessages({ id: 'TR_SHOW_ADDRESS_I_WILL_TAKE_THE_RISK', defaultMessage: 'Show address, I will take the risk', }, + TR_HIGH_FEE: { + id: 'TR_HIGH_FEE', + defaultMessage: 'High', + description: 'fee level', + }, + TR_NORMAL_FEE: { + id: 'TR_NORMAL_FEE', + defaultMessage: 'Normal', + description: 'fee level', + }, + TR_LOW_FEE: { + id: 'TR_LOW_FEE', + defaultMessage: 'Low', + description: 'fee level', + }, + TR_CUSTOM_FEE: { + id: 'TR_CUSTOM_FEE', + defaultMessage: 'Custom', + description: 'fee level', + }, }); export default definedMessages; From 8d1c01bc61b1fd0e23b7c4dbec986a4615d0f38f Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Mon, 29 Apr 2019 12:57:25 +0200 Subject: [PATCH 07/17] delete console.log --- src/actions/ethereum/SendFormActions.js | 3 +-- src/actions/ethereum/SendFormValidationActions.js | 4 ---- src/actions/ripple/SendFormActions.js | 1 - src/views/Wallet/views/Account/Send/ethereum/index.js | 1 - 4 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/actions/ethereum/SendFormActions.js b/src/actions/ethereum/SendFormActions.js index efc57868..c1983404 100644 --- a/src/actions/ethereum/SendFormActions.js +++ b/src/actions/ethereum/SendFormActions.js @@ -427,8 +427,7 @@ export const onFeeLevelChange = (feeLevel: FeeLevel): ThunkAction => ( } newGasPrice = feeLevel.gasPrice; } - console.log('selected'); - console.log(feeLevel); + dispatch({ type: SEND.CHANGE, networkType: 'ethereum', diff --git a/src/actions/ethereum/SendFormValidationActions.js b/src/actions/ethereum/SendFormValidationActions.js index fe01a718..34f823f3 100644 --- a/src/actions/ethereum/SendFormValidationActions.js +++ b/src/actions/ethereum/SendFormValidationActions.js @@ -492,10 +492,6 @@ export const getFeeLevels = ( label: '', }; - console.log(l10nCommonMessages.TR_LOW_FEE); - console.log(l10nCommonMessages.TR_NORMAL_FEE); - console.log(l10nCommonMessages.TR_HIGH_FEE); - console.log(l10nCommonMessages.TR_CUSTOM_FEE); return [ { value: 'High', diff --git a/src/actions/ripple/SendFormActions.js b/src/actions/ripple/SendFormActions.js index b32f1cae..41c34fdc 100644 --- a/src/actions/ripple/SendFormActions.js +++ b/src/actions/ripple/SendFormActions.js @@ -110,7 +110,6 @@ export const init = (): AsyncAction => async ( const blockchainFeeLevels = dispatch(BlockchainActions.getFeeLevels(network)); const feeLevels = dispatch(ValidationActions.getFeeLevels(blockchainFeeLevels)); - console.log(feeLevels); const selectedFeeLevel = ValidationActions.getSelectedFeeLevel( feeLevels, initialState.selectedFeeLevel diff --git a/src/views/Wallet/views/Account/Send/ethereum/index.js b/src/views/Wallet/views/Account/Send/ethereum/index.js index 1435a313..dbb3c8ff 100644 --- a/src/views/Wallet/views/Account/Send/ethereum/index.js +++ b/src/views/Wallet/views/Account/Send/ethereum/index.js @@ -480,7 +480,6 @@ const AccountSend = (props: Props) => { options={feeLevels} formatOptionLabel={option => ( - {console.log(option)} From 934df3806413b9d27a02140b8d6533a77629309d Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Mon, 29 Apr 2019 15:36:05 +0200 Subject: [PATCH 08/17] l10n support for xrp validation --- .../ripple/SendFormValidationActions.js | 83 +++++++++++++------ src/reducers/SendFormRippleReducer.js | 9 +- .../ripple/components/AdvancedForm/index.js | 30 +++++-- .../Wallet/views/Account/Send/ripple/index.js | 28 +++++-- .../views/Account/Send/validation.messages.js | 38 +++++++++ src/views/common.messages.js | 5 +- 6 files changed, 145 insertions(+), 48 deletions(-) diff --git a/src/actions/ripple/SendFormValidationActions.js b/src/actions/ripple/SendFormValidationActions.js index d24ff34c..cc13a4b3 100644 --- a/src/actions/ripple/SendFormValidationActions.js +++ b/src/actions/ripple/SendFormValidationActions.js @@ -6,6 +6,8 @@ import { findDevice, getPendingAmount } from 'reducers/utils'; import { toDecimalAmount } from 'utils/formatUtils'; import { toFiatCurrency } from 'utils/fiatConverter'; import * as validators from 'utils/validators'; +import l10nMessages from 'views/Wallet/views/Account/Send/validation.messages'; +import l10nCommonMessages from 'views/common.messages'; import type { Dispatch, @@ -150,11 +152,11 @@ const addressValidation = ($state: State): PayloadAction => ( const { address } = state; if (address.length < 1) { - state.errors.address = 'Address is not set'; + state.errors.address = l10nMessages.TR_ADDRESS_IS_NOT_SET; } else if (!AddressValidator.validate(address, 'XRP')) { - state.errors.address = 'Address is not valid'; + state.errors.address = l10nMessages.TR_ADDRESS_IS_NOT_VALID; } else if (address.toLowerCase() === account.descriptor.toLowerCase()) { - state.errors.address = 'Cannot send to myself'; + state.errors.address = l10nMessages.TR_CANNOT_SEND_TO_MYSELF; } return state; }; @@ -226,9 +228,13 @@ const addressLabel = ($state: State): PayloadAction => ( currentNetworkAccount.deviceState ); if (device) { - state.infos.address = `${ - device.instanceLabel - } Account #${currentNetworkAccount.index + 1}`; + state.infos.address = { + ...l10nCommonMessages.TR_DEVICE_LABEL_ACCOUNT_HASH, + values: { + deviceLabel: device.instanceLabel, + number: currentNetworkAccount.index + 1, + }, + }; } } else { // corner-case: the same derivation path is used on different networks @@ -241,11 +247,14 @@ const addressLabel = ($state: State): PayloadAction => ( const { networks } = getState().localStorage.config; const otherNetwork = networks.find(c => c.shortcut === otherNetworkAccount.network); if (device && otherNetwork) { - state.warnings.address = `Looks like it's ${ - device.instanceLabel - } Account #${otherNetworkAccount.index + 1} address of ${ - otherNetwork.name - } network`; + state.warnings.address = { + ...l10nCommonMessages.TR_LOOKS_LIKE_IT_IS_DEVICE_LABEL, + values: { + deviceLabel: device.instanceLabel, + number: otherNetworkAccount.index + 1, + network: otherNetwork.name, + }, + }; } } } @@ -268,19 +277,22 @@ const amountValidation = ($state: State): PayloadAction => ( const { amount } = state; if (amount.length < 1) { - state.errors.amount = 'Amount is not set'; + state.errors.amount = l10nMessages.TR_AMOUNT_IS_NOT_SET; } else if (amount.length > 0 && !validators.isNumber(amount)) { - state.errors.amount = 'Amount is not a number'; + state.errors.amount = l10nMessages.TR_AMOUNT_IS_NOT_A_NUMBER; } else { const pendingAmount: BigNumber = getPendingAmount(pending, state.networkSymbol); if (!validators.hasDecimals(state.amount, 6)) { - state.errors.amount = 'Maximum 6 decimals allowed'; + state.errors.amount = { + ...l10nMessages.TR_MAXIMUM_DECIMALS_ALLOWED, + values: { decimals: 6 }, + }; } else if ( new BigNumber(state.total).isGreaterThan( new BigNumber(account.balance).minus(pendingAmount) ) ) { - state.errors.amount = 'Not enough funds'; + state.errors.amount = l10nMessages.TR_NOT_ENOUGH_FUNDS; } } @@ -288,15 +300,23 @@ const amountValidation = ($state: State): PayloadAction => ( !state.errors.amount && new BigNumber(account.balance).minus(state.total).lt(account.reserve) ) { - state.errors.amount = `Not enough funds. Reserved amount for this account is ${ - account.reserve - } ${state.networkSymbol}`; + state.errors.amount = { + ...l10nMessages.TR_NOT_ENOUGH_FUNDS_RESERVED_AMOUNT, + values: { + reservedAmount: account.reserve, + networkSymbol: state.networkSymbol, + }, + }; } if (!state.errors.amount && new BigNumber(state.amount).lt(state.minAmount)) { - state.errors.amount = `Amount is too low. Minimum amount for creating a new account is ${ - state.minAmount - } ${state.networkSymbol}`; + state.errors.amount = { + ...l10nMessages.TR_AMOUNT_IS_TOO_LOW_MINIMUM_AMOUNT_FOR_CREATING, + values: { + reservedAmount: state.minAmount, + networkSymbol: state.networkSymbol, + }, + }; } return state; @@ -317,15 +337,15 @@ export const feeValidation = ($state: State): PayloadAction => ( const { fee } = state; if (fee.length < 1) { - state.errors.fee = 'Fee is not set'; + state.errors.fee = l10nMessages.TR_FEE_IS_NOT_SET; } else if (fee.length > 0 && !validators.isAbs(fee)) { - state.errors.fee = 'Fee must be an absolute number'; + state.errors.fee = l10nMessages.TR_FEE_MUST_ME_AN_ABSOLUT_NUMBER; } else { const gl: BigNumber = new BigNumber(fee); if (gl.isLessThan(network.fee.minFee)) { - state.errors.fee = 'Fee is below recommended'; + state.errors.fee = l10nMessages.TR_FEE_IS_BELOW_RECOMMENDED; } else if (gl.isGreaterThan(network.fee.maxFee)) { - state.errors.fee = 'Fee is above recommended'; + state.errors.fee = l10nMessages.TR_FEE_IS_ABOVE_RECOMMENDED; } } return state; @@ -340,11 +360,11 @@ export const destinationTagValidation = ($state: State): PayloadAction => const { destinationTag } = state; if (destinationTag.length > 0 && !validators.isAbs(destinationTag)) { - state.errors.destinationTag = 'Destination tag must be an absolute number'; + state.errors.destinationTag = l10nMessages.TR_DESTINATION_TAG_MUST_BE_AN_ABSOLUTE; } if (parseInt(destinationTag, 10) > U_INT_32) { - state.errors.destinationTag = 'Number is too big'; + state.errors.destinationTag = l10nMessages.TR_DESTINATION_TAG_IS_NOT_VALID; } return state; @@ -386,9 +406,16 @@ export const getFeeLevels = ( const { network } = getState().selectedAccount; if (!network) return []; // flowtype fallback + const l10nFeeMap = { + Low: l10nCommonMessages.TR_LOW_FEE, + Normal: l10nCommonMessages.TR_NORMAL_FEE, + High: l10nCommonMessages.TR_HIGH_FEE, + }; + // map BlockchainFeeLevel to SendFormReducer FeeLevel const levels = feeLevels.map(level => ({ value: level.name, + localizedValue: l10nFeeMap[level.value] || level.value, fee: level.value, label: `${toDecimalAmount(level.value, network.decimals)} ${network.symbol}`, })); @@ -398,11 +425,13 @@ export const getFeeLevels = ( selected && selected.value === 'Custom' ? { value: 'Custom', + localizedValue: l10nCommonMessages.TR_CUSTOM_FEE, fee: selected.fee, label: `${toDecimalAmount(selected.fee, network.decimals)} ${network.symbol}`, } : { value: 'Custom', + localizedValue: l10nCommonMessages.TR_CUSTOM_FEE, fee: '0', label: '', }; diff --git a/src/reducers/SendFormRippleReducer.js b/src/reducers/SendFormRippleReducer.js index 9b38445a..18fa3d90 100644 --- a/src/reducers/SendFormRippleReducer.js +++ b/src/reducers/SendFormRippleReducer.js @@ -3,12 +3,13 @@ import * as SEND from 'actions/constants/send'; import * as ACCOUNT from 'actions/constants/account'; -import type { Action } from 'flowtype'; +import type { Action, MessageDescriptor } from 'flowtype'; export type FeeLevel = { label: string, fee: string, value: string, + localizedValue?: MessageDescriptor, }; export type State = { @@ -33,9 +34,9 @@ export type State = { destinationTag: string, total: string, - errors: { [k: string]: string }, - warnings: { [k: string]: string }, - infos: { [k: string]: string }, + errors: { [k: string]: MessageDescriptor }, + warnings: { [k: string]: MessageDescriptor }, + infos: { [k: string]: MessageDescriptor }, sending: boolean, }; diff --git a/src/views/Wallet/views/Account/Send/ripple/components/AdvancedForm/index.js b/src/views/Wallet/views/Account/Send/ripple/components/AdvancedForm/index.js index ad7a84e9..79ac08e5 100644 --- a/src/views/Wallet/views/Account/Send/ripple/components/AdvancedForm/index.js +++ b/src/views/Wallet/views/Account/Send/ripple/components/AdvancedForm/index.js @@ -52,7 +52,7 @@ const TooltipContainer = styled.div` margin-left: 6px; `; -const getFeeInputState = (feeErrors: string, feeWarnings: string): ?string => { +const getFeeInputState = (feeErrors: boolean, feeWarnings: boolean): ?string => { let state = null; if (feeWarnings && !feeErrors) { state = 'warning'; @@ -63,7 +63,7 @@ const getFeeInputState = (feeErrors: string, feeWarnings: string): ?string => { return state; }; -const getDestinationTagInputState = (errors: string, warnings: string): ?string => { +const getDestinationTagInputState = (errors: boolean, warnings: boolean): ?string => { let state = null; if (warnings && !errors) { state = 'warning'; @@ -90,7 +90,7 @@ const AdvancedForm = (props: Props) => { { } - bottomText={errors.fee || warnings.fee || infos.fee} + bottomText={ + <> + {(errors.fee && ) || + (warnings.fee && ) || + (infos.fee && )} + + } value={fee} onChange={event => onFeeChange(event.target.value)} /> @@ -134,8 +140,8 @@ const AdvancedForm = (props: Props) => { { } bottomText={ - errors.destinationTag || warnings.destinationTag || infos.destinationTag + <> + {(errors.destinationTag && ( + + )) || + (warnings.destinationTag && ( + + )) || + (infos.destinationTag && ( + + ))} + } value={destinationTag} onChange={event => onDestinationTagChange(event.target.value)} diff --git a/src/views/Wallet/views/Account/Send/ripple/index.js b/src/views/Wallet/views/Account/Send/ripple/index.js index 8a7676bd..4a1d3305 100644 --- a/src/views/Wallet/views/Account/Send/ripple/index.js +++ b/src/views/Wallet/views/Account/Send/ripple/index.js @@ -202,8 +202,8 @@ const StyledIcon = styled(Icon)` // render helpers const getAddressInputState = ( address: string, - addressErrors: string, - addressWarnings: string + addressErrors: boolean, + addressWarnings: boolean ): ?string => { let state = null; if (address && !addressErrors) { @@ -218,7 +218,7 @@ const getAddressInputState = ( return state; }; -const getAmountInputState = (amountErrors: string, amountWarnings: string): ?string => { +const getAmountInputState = (amountErrors: boolean, amountWarnings: boolean): ?string => { let state = null; if (amountWarnings && !amountErrors) { state = 'warning'; @@ -317,13 +317,19 @@ const AccountSend = (props: Props) => { + {(errors.address && ) || + (warnings.address && ) || + (infos.address && )} + + } value={address} onChange={event => onAddressChange(event.target.value)} sideAddons={[ @@ -335,7 +341,7 @@ const AccountSend = (props: Props) => { { } value={amount} onChange={event => onAmountChange(event.target.value)} - bottomText={errors.amount || warnings.amount || infos.amount} + bottomText={ + <> + {(errors.amount && ) || + (warnings.amount && ) || + (infos.amount && )} + + } sideAddons={[ onSetMax()} isWhite={!setMax}> {!setMax && ( @@ -385,7 +397,7 @@ const AccountSend = (props: Props) => { = Date: Mon, 29 Apr 2019 15:46:24 +0200 Subject: [PATCH 09/17] fix rendering of validation error for advanced send eth --- .../ethereum/components/AdvancedForm/index.js | 28 +++++++++++++++++-- .../views/Account/Send/ethereum/index.js | 12 ++++---- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/views/Wallet/views/Account/Send/ethereum/components/AdvancedForm/index.js b/src/views/Wallet/views/Account/Send/ethereum/components/AdvancedForm/index.js index ebcfa99b..3c25795e 100644 --- a/src/views/Wallet/views/Account/Send/ethereum/components/AdvancedForm/index.js +++ b/src/views/Wallet/views/Account/Send/ethereum/components/AdvancedForm/index.js @@ -234,7 +234,15 @@ const AdvancedForm = (props: Props) => { )} } - bottomText={errors.gasLimit || warnings.gasLimit || infos.gasLimit} + bottomText={ + <> + {(errors.gasLimit && ) || + (warnings.gasLimit && ( + + )) || + (infos.gasLimit && )} + + } value={ calculatingGasLimit ? props.intl.formatMessage(l10nMessages.TR_CALCULATING_DOT_DOT) @@ -292,7 +300,15 @@ const AdvancedForm = (props: Props) => { } - bottomText={errors.gasPrice || warnings.gasPrice || infos.gasPrice} + bottomText={ + <> + {(errors.gasPrice && ) || + (warnings.gasPrice && ( + + )) || + (infos.v && )} + + } value={gasPrice} onChange={event => onGasPriceChange(event.target.value)} /> @@ -323,7 +339,13 @@ const AdvancedForm = (props: Props) => { } state={getDataTextareaState(!!errors.data, !!warnings.data)} - bottomText={errors.data || warnings.data || infos.data} + bottomText={ + <> + {(errors.data && ) || + (warnings.data && ) || + (infos.data && )} + + } isDisabled={networkSymbol !== currency} value={networkSymbol !== currency ? '' : data} onChange={event => onDataChange(event.target.value)} diff --git a/src/views/Wallet/views/Account/Send/ethereum/index.js b/src/views/Wallet/views/Account/Send/ethereum/index.js index dbb3c8ff..d02328c2 100644 --- a/src/views/Wallet/views/Account/Send/ethereum/index.js +++ b/src/views/Wallet/views/Account/Send/ethereum/index.js @@ -355,9 +355,9 @@ const AccountSend = (props: Props) => { topLabel={props.intl.formatMessage(l10nCommonMessages.TR_ADDRESS)} bottomText={ <> - {errors.address && } - {warnings.address && } - {infos.address && } + {(errors.address && ) || + (warnings.address && ) || + (infos.address && )} } value={address} @@ -399,9 +399,9 @@ const AccountSend = (props: Props) => { onChange={event => onAmountChange(event.target.value)} bottomText={ <> - {errors.amount && } - {warnings.amount && } - {infos.amount && } + {(errors.amount && ) || + (warnings.amount && ) || + (infos.amount && )} } sideAddons={[ From 9a083dff87545e1659052bf4f6ac74cdc5222eac Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Mon, 29 Apr 2019 15:51:55 +0200 Subject: [PATCH 10/17] fix localized value for xrp fee select --- src/actions/ripple/SendFormValidationActions.js | 2 +- src/views/Wallet/views/Account/Send/ripple/index.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/actions/ripple/SendFormValidationActions.js b/src/actions/ripple/SendFormValidationActions.js index cc13a4b3..cf400427 100644 --- a/src/actions/ripple/SendFormValidationActions.js +++ b/src/actions/ripple/SendFormValidationActions.js @@ -415,7 +415,7 @@ export const getFeeLevels = ( // map BlockchainFeeLevel to SendFormReducer FeeLevel const levels = feeLevels.map(level => ({ value: level.name, - localizedValue: l10nFeeMap[level.value] || level.value, + localizedValue: l10nFeeMap[level.value], fee: level.value, label: `${toDecimalAmount(level.value, network.decimals)} ${network.symbol}`, })); diff --git a/src/views/Wallet/views/Account/Send/ripple/index.js b/src/views/Wallet/views/Account/Send/ripple/index.js index 4a1d3305..2387790b 100644 --- a/src/views/Wallet/views/Account/Send/ripple/index.js +++ b/src/views/Wallet/views/Account/Send/ripple/index.js @@ -445,7 +445,13 @@ const AccountSend = (props: Props) => { options={feeLevels} formatOptionLabel={option => ( - {option.value} + + {option.localizedValue ? ( + + ) : ( + option.value + )} + {option.label} )} From 3bcf991ef9616e9967b9f156b2ad500b8ae34267 Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Mon, 29 Apr 2019 17:08:06 +0200 Subject: [PATCH 11/17] refactor passed value to bottomText prop --- src/utils/uiUtils.js | 16 ++++++++++ .../ethereum/components/AdvancedForm/index.js | 30 +++---------------- .../views/Account/Send/ethereum/index.js | 17 ++--------- .../ripple/components/AdvancedForm/index.js | 28 +++++------------ .../Wallet/views/Account/Send/ripple/index.js | 18 ++--------- 5 files changed, 33 insertions(+), 76 deletions(-) create mode 100644 src/utils/uiUtils.js diff --git a/src/utils/uiUtils.js b/src/utils/uiUtils.js new file mode 100644 index 00000000..e95d6f80 --- /dev/null +++ b/src/utils/uiUtils.js @@ -0,0 +1,16 @@ +/* @flow */ +import * as React from 'react'; +import { FormattedMessage } from 'react-intl'; + +export const getBottomText = (error: any, warning: any, info: any): React.Node => { + if (error) { + return ; + } + if (warning) { + return ; + } + if (info) { + return ; + } + return null; +}; diff --git a/src/views/Wallet/views/Account/Send/ethereum/components/AdvancedForm/index.js b/src/views/Wallet/views/Account/Send/ethereum/components/AdvancedForm/index.js index 3c25795e..05e9d1f9 100644 --- a/src/views/Wallet/views/Account/Send/ethereum/components/AdvancedForm/index.js +++ b/src/views/Wallet/views/Account/Send/ethereum/components/AdvancedForm/index.js @@ -15,7 +15,7 @@ import { import type { IntlShape } from 'react-intl'; import { FONT_SIZE } from 'config/variables'; - +import { getBottomText } from 'utils/uiUtils'; import l10nCommonMessages from 'views/common.messages'; import l10nMessages from './index.messages'; @@ -234,15 +234,7 @@ const AdvancedForm = (props: Props) => { )} } - bottomText={ - <> - {(errors.gasLimit && ) || - (warnings.gasLimit && ( - - )) || - (infos.gasLimit && )} - - } + bottomText={getBottomText(errors.gasLimit, warnings.gasLimit, infos.gasLimit)} value={ calculatingGasLimit ? props.intl.formatMessage(l10nMessages.TR_CALCULATING_DOT_DOT) @@ -300,15 +292,7 @@ const AdvancedForm = (props: Props) => { } - bottomText={ - <> - {(errors.gasPrice && ) || - (warnings.gasPrice && ( - - )) || - (infos.v && )} - - } + bottomText={getBottomText(errors.gasPrice, warnings.gasPrice, infos.gasPrice)} value={gasPrice} onChange={event => onGasPriceChange(event.target.value)} /> @@ -339,13 +323,7 @@ const AdvancedForm = (props: Props) => { } state={getDataTextareaState(!!errors.data, !!warnings.data)} - bottomText={ - <> - {(errors.data && ) || - (warnings.data && ) || - (infos.data && )} - - } + bottomText={getBottomText(errors.data, warnings.data, infos.data)} isDisabled={networkSymbol !== currency} value={networkSymbol !== currency ? '' : data} onChange={event => onDataChange(event.target.value)} diff --git a/src/views/Wallet/views/Account/Send/ethereum/index.js b/src/views/Wallet/views/Account/Send/ethereum/index.js index d02328c2..723bef68 100644 --- a/src/views/Wallet/views/Account/Send/ethereum/index.js +++ b/src/views/Wallet/views/Account/Send/ethereum/index.js @@ -12,6 +12,7 @@ import * as stateUtils from 'reducers/utils'; import type { Token } from 'flowtype'; import { FormattedMessage } from 'react-intl'; import l10nCommonMessages from 'views/common.messages'; +import { getBottomText } from 'utils/uiUtils'; import AdvancedForm from './components/AdvancedForm'; import PendingTransactions from '../components/PendingTransactions'; @@ -353,13 +354,7 @@ const AccountSend = (props: Props) => { autoCapitalize="off" spellCheck="false" topLabel={props.intl.formatMessage(l10nCommonMessages.TR_ADDRESS)} - bottomText={ - <> - {(errors.address && ) || - (warnings.address && ) || - (infos.address && )} - - } + bottomText={getBottomText(errors.address, warnings.address, infos.address)} value={address} onChange={event => onAddressChange(event.target.value)} sideAddons={[ @@ -397,13 +392,7 @@ const AccountSend = (props: Props) => { } value={amount} onChange={event => onAmountChange(event.target.value)} - bottomText={ - <> - {(errors.amount && ) || - (warnings.amount && ) || - (infos.amount && )} - - } + bottomText={getBottomText(errors.amount, warnings.amount, infos.amount)} sideAddons={[ onSetMax()} isWhite={!setMax}> {!setMax && ( diff --git a/src/views/Wallet/views/Account/Send/ripple/components/AdvancedForm/index.js b/src/views/Wallet/views/Account/Send/ripple/components/AdvancedForm/index.js index 79ac08e5..5bbb4fc5 100644 --- a/src/views/Wallet/views/Account/Send/ripple/components/AdvancedForm/index.js +++ b/src/views/Wallet/views/Account/Send/ripple/components/AdvancedForm/index.js @@ -4,7 +4,7 @@ import * as React from 'react'; import { FormattedMessage } from 'react-intl'; import styled from 'styled-components'; import { Input, Tooltip, Icon, colors, icons as ICONS } from 'trezor-ui-components'; - +import { getBottomText } from 'utils/uiUtils'; import l10nCommonMessages from 'views/common.messages'; import l10nSendMessages from 'views/Wallet/views/Account/common.messages'; import l10nMessages from './index.messages'; @@ -125,13 +125,7 @@ const AdvancedForm = (props: Props) => { } - bottomText={ - <> - {(errors.fee && ) || - (warnings.fee && ) || - (infos.fee && )} - - } + bottomText={getBottomText(errors.fee, warnings.fee, infos.fee)} value={fee} onChange={event => onFeeChange(event.target.value)} /> @@ -177,19 +171,11 @@ const AdvancedForm = (props: Props) => { } - bottomText={ - <> - {(errors.destinationTag && ( - - )) || - (warnings.destinationTag && ( - - )) || - (infos.destinationTag && ( - - ))} - - } + bottomText={getBottomText( + errors.destinationTag, + warnings.destinationTag, + infos.destinationTag + )} value={destinationTag} onChange={event => onDestinationTagChange(event.target.value)} /> diff --git a/src/views/Wallet/views/Account/Send/ripple/index.js b/src/views/Wallet/views/Account/Send/ripple/index.js index 2387790b..e7b1d427 100644 --- a/src/views/Wallet/views/Account/Send/ripple/index.js +++ b/src/views/Wallet/views/Account/Send/ripple/index.js @@ -10,9 +10,9 @@ import { FIAT_CURRENCIES } from 'config/app'; import Title from 'views/Wallet/components/Title'; import l10nCommonMessages from 'views/common.messages'; import Content from 'views/Wallet/components/Content'; +import { getBottomText } from 'utils/uiUtils'; import PendingTransactions from '../components/PendingTransactions'; import AdvancedForm from './components/AdvancedForm'; - import l10nMessages from './index.messages'; import l10nSendMessages from '../../common.messages'; @@ -323,13 +323,7 @@ const AccountSend = (props: Props) => { autoCapitalize="off" spellCheck="false" topLabel={props.intl.formatMessage(l10nCommonMessages.TR_ADDRESS)} - bottomText={ - <> - {(errors.address && ) || - (warnings.address && ) || - (infos.address && )} - - } + bottomText={getBottomText(errors.address, warnings.address, infos.address)} value={address} onChange={event => onAddressChange(event.target.value)} sideAddons={[ @@ -363,13 +357,7 @@ const AccountSend = (props: Props) => { } value={amount} onChange={event => onAmountChange(event.target.value)} - bottomText={ - <> - {(errors.amount && ) || - (warnings.amount && ) || - (infos.amount && )} - - } + bottomText={getBottomText(errors.amount, warnings.amount, infos.amount)} sideAddons={[ onSetMax()} isWhite={!setMax}> {!setMax && ( From 25e8c6ae561a0b9e1c6c60596b110814faa44a2f Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Mon, 29 Apr 2019 18:49:16 +0200 Subject: [PATCH 12/17] l10n for actions that use notifications --- src/actions/DiscoveryActions.js | 13 +++-- src/actions/NotificationActions.js | 11 +++- src/actions/ReceiveActions.js | 9 ++-- src/actions/SignVerifyActions.js | 11 ++-- src/actions/TrezorConnectActions.js | 11 ++-- src/actions/ethereum/SendFormActions.js | 11 ++-- src/actions/ripple/SendFormActions.js | 9 ++-- .../modals/confirm/UnverifiedAddress/index.js | 2 +- .../UnverifiedAddress/index.messages.js | 5 -- .../notifications/Context/actions.messages.js | 54 +++++++++++++++++++ .../components/Group/index.js | 23 +++++++- src/reducers/NotificationReducer.js | 2 +- src/views/common.messages.js | 5 ++ 13 files changed, 133 insertions(+), 33 deletions(-) create mode 100644 src/components/notifications/Context/actions.messages.js diff --git a/src/actions/DiscoveryActions.js b/src/actions/DiscoveryActions.js index d61f2085..9347ea84 100644 --- a/src/actions/DiscoveryActions.js +++ b/src/actions/DiscoveryActions.js @@ -1,5 +1,6 @@ /* @flow */ - +import React from 'react'; +import { FormattedMessage } from 'react-intl'; import TrezorConnect, { UI } from 'trezor-connect'; import * as BLOCKCHAIN_ACTION from 'actions/constants/blockchain'; import * as DISCOVERY from 'actions/constants/discovery'; @@ -17,6 +18,8 @@ import type { Account, } from 'flowtype'; import type { Discovery, State } from 'reducers/DiscoveryReducer'; +import l10nMessages from 'components/notifications/Context/actions.messages'; +import l10nCommonMessages from 'views/common.messages'; import * as BlockchainActions from './BlockchainActions'; import * as EthereumDiscoveryActions from './ethereum/DiscoveryActions'; import * as RippleDiscoveryActions from './ripple/DiscoveryActions'; @@ -176,12 +179,12 @@ const begin = (device: TrezorDevice, networkName: string): AsyncAction => async type: NOTIFICATION.ADD, payload: { type: 'error', - title: 'Discovery error', + title: , message: error.message, cancelable: true, actions: [ { - label: 'Try again', + label: , callback: () => { dispatch(start(device, networkName)); }, @@ -264,12 +267,12 @@ const discoverAccount = (device: TrezorDevice, discoveryProcess: Discovery): Asy type: NOTIFICATION.ADD, payload: { type: 'error', - title: 'Account discovery error', + title: , message: error.message, cancelable: true, actions: [ { - label: 'Try again', + label: , callback: () => { dispatch(start(device, discoveryProcess.network)); }, diff --git a/src/actions/NotificationActions.js b/src/actions/NotificationActions.js index 48e2706e..9f847a33 100644 --- a/src/actions/NotificationActions.js +++ b/src/actions/NotificationActions.js @@ -2,7 +2,14 @@ import * as React from 'react'; import * as NOTIFICATION from 'actions/constants/notification'; -import type { Action, AsyncAction, GetState, Dispatch, RouterLocationState } from 'flowtype'; +import type { + Action, + AsyncAction, + GetState, + Dispatch, + RouterLocationState, + MessageDescriptor, +} from 'flowtype'; import type { CallbackAction } from 'reducers/NotificationReducer'; export type NotificationAction = @@ -10,7 +17,7 @@ export type NotificationAction = type: typeof NOTIFICATION.ADD, payload: { +type: string, - +title: React.Node | string, + +title: React.Node | MessageDescriptor | string, +message?: ?(React.Node | string), +cancelable: boolean, actions?: Array, diff --git a/src/actions/ReceiveActions.js b/src/actions/ReceiveActions.js index 867f7e2a..2aee2821 100644 --- a/src/actions/ReceiveActions.js +++ b/src/actions/ReceiveActions.js @@ -1,5 +1,6 @@ /* @flow */ - +import React from 'react'; +import { FormattedMessage } from 'react-intl'; import TrezorConnect from 'trezor-connect'; import * as RECEIVE from 'actions/constants/receive'; import * as NOTIFICATION from 'actions/constants/notification'; @@ -8,6 +9,8 @@ import { initialState } from 'reducers/ReceiveReducer'; import type { State } from 'reducers/ReceiveReducer'; import type { TrezorDevice, ThunkAction, AsyncAction, Action, GetState, Dispatch } from 'flowtype'; +import l10nMessages from 'components/notifications/Context/actions.messages'; +import l10nCommonMessages from 'views/common.messages'; export type ReceiveAction = | { @@ -112,12 +115,12 @@ export const showAddress = (path: Array): AsyncAction => async ( type: NOTIFICATION.ADD, payload: { type: 'error', - title: 'Verifying address error', + title: , message: response.payload.error, cancelable: true, actions: [ { - label: 'Try again', + label: , callback: () => { dispatch(showAddress(path)); }, diff --git a/src/actions/SignVerifyActions.js b/src/actions/SignVerifyActions.js index 8fc3982f..30878e30 100644 --- a/src/actions/SignVerifyActions.js +++ b/src/actions/SignVerifyActions.js @@ -1,8 +1,11 @@ /* @flow */ +import React from 'react'; +import { FormattedMessage } from 'react-intl'; import TrezorConnect from 'trezor-connect'; import type { GetState, Dispatch, ThunkAction, AsyncAction } from 'flowtype'; import { validateAddress } from 'utils/ethUtils'; import * as NOTIFICATION from 'actions/constants/notification'; +import l10nMessages from 'components/notifications/Context/actions.messages'; import * as SIGN_VERIFY from './constants/signVerify'; export type SignVerifyAction = @@ -65,7 +68,7 @@ const sign = (path: Array, message: string, hex: boolean = false): Async type: NOTIFICATION.ADD, payload: { type: 'error', - title: 'Sign error', + title: , message: response.payload.error, cancelable: true, }, @@ -110,8 +113,8 @@ const verify = ( type: NOTIFICATION.ADD, payload: { type: 'success', - title: 'Verify success', - message: 'signature is valid', + title: , + message: , cancelable: true, }, }); @@ -120,7 +123,7 @@ const verify = ( type: NOTIFICATION.ADD, payload: { type: 'error', - title: 'Verify error', + title: , message: response.payload.error, cancelable: true, }, diff --git a/src/actions/TrezorConnectActions.js b/src/actions/TrezorConnectActions.js index 0b5ce5f2..87c3d4be 100644 --- a/src/actions/TrezorConnectActions.js +++ b/src/actions/TrezorConnectActions.js @@ -6,6 +6,8 @@ import TrezorConnect, { TRANSPORT_EVENT, BLOCKCHAIN_EVENT, } from 'trezor-connect'; +import React from 'react'; +import { FormattedMessage } from 'react-intl'; import { CONTEXT_NONE } from 'actions/constants/modal'; import urlConstants from 'constants/urls'; import * as CONNECT from 'actions/constants/TrezorConnect'; @@ -35,6 +37,9 @@ import type { TrezorDevice, } from 'flowtype'; +import l10nCommonMessages from 'views/common.messages'; +import l10nMessages from 'components/notifications/Context/actions.messages'; + export type TrezorConnectAction = | { type: typeof CONNECT.INITIALIZATION_ERROR, @@ -264,12 +269,12 @@ export const authorizeDevice = (): AsyncAction => async ( payload: { devicePath: selected.path, type: 'error', - title: 'Authentication error', + title: , message: response.payload.error, cancelable: false, actions: [ { - label: 'Try again', + label: , callback: () => { dispatch({ type: NOTIFICATION.CLOSE, @@ -350,7 +355,7 @@ export function acquire(): AsyncAction { type: NOTIFICATION.ADD, payload: { type: 'error', - title: 'Acquire device error', + title: , message: response.payload.error, cancelable: true, // actions: [ diff --git a/src/actions/ethereum/SendFormActions.js b/src/actions/ethereum/SendFormActions.js index c1983404..4fec6257 100644 --- a/src/actions/ethereum/SendFormActions.js +++ b/src/actions/ethereum/SendFormActions.js @@ -1,5 +1,6 @@ /* @flow */ import React from 'react'; +import { FormattedMessage } from 'react-intl'; import { Link } from 'trezor-ui-components'; import TrezorConnect from 'trezor-connect'; import BigNumber from 'bignumber.js'; @@ -23,10 +24,10 @@ import type { TrezorDevice, } from 'flowtype'; import type { State, FeeLevel } from 'reducers/SendFormEthereumReducer'; +import l10nMessages from 'components/notifications/Context/actions.messages'; import * as SessionStorageActions from '../SessionStorageActions'; import { prepareEthereumTx, serializeEthereumTx } from '../TxActions'; import * as BlockchainActions from './BlockchainActions'; - import * as ValidationActions from './SendFormValidationActions'; // list of all actions which has influence on "sendFormEthereum" reducer @@ -717,7 +718,7 @@ export const onSend = (): AsyncAction => async ( type: NOTIFICATION.ADD, payload: { type: 'error', - title: 'Transaction error', + title: , message: signedTransaction.payload.error, cancelable: true, actions: [], @@ -807,10 +808,10 @@ export const onSend = (): AsyncAction => async ( type: NOTIFICATION.ADD, payload: { type: 'success', - title: 'Transaction success', + title: , message: ( - See transaction detail + ), cancelable: true, @@ -822,7 +823,7 @@ export const onSend = (): AsyncAction => async ( type: NOTIFICATION.ADD, payload: { type: 'error', - title: 'Transaction error', + title: , message: error.message || error, cancelable: true, actions: [], diff --git a/src/actions/ripple/SendFormActions.js b/src/actions/ripple/SendFormActions.js index 41c34fdc..ae237a5a 100644 --- a/src/actions/ripple/SendFormActions.js +++ b/src/actions/ripple/SendFormActions.js @@ -1,4 +1,6 @@ /* @flow */ +import React from 'react'; +import { FormattedMessage } from 'react-intl'; import TrezorConnect from 'trezor-connect'; import * as NOTIFICATION from 'actions/constants/notification'; import * as SEND from 'actions/constants/send'; @@ -19,6 +21,7 @@ import type { TrezorDevice, } from 'flowtype'; import type { State, FeeLevel } from 'reducers/SendFormRippleReducer'; +import l10nMessages from 'components/notifications/Context/actions.messages'; import * as SessionStorageActions from '../SessionStorageActions'; import * as BlockchainActions from './BlockchainActions'; @@ -455,7 +458,7 @@ export const onSend = (): AsyncAction => async ( type: NOTIFICATION.ADD, payload: { type: 'error', - title: 'Transaction error', + title: , message: signedTransaction.payload.error, cancelable: true, actions: [], @@ -474,7 +477,7 @@ export const onSend = (): AsyncAction => async ( type: NOTIFICATION.ADD, payload: { type: 'error', - title: 'Transaction error', + title: , message: push.payload.error, cancelable: true, actions: [], @@ -497,7 +500,7 @@ export const onSend = (): AsyncAction => async ( type: NOTIFICATION.ADD, payload: { type: 'success', - title: 'Transaction success', + title: , message: txid, cancelable: true, actions: [], diff --git a/src/components/modals/confirm/UnverifiedAddress/index.js b/src/components/modals/confirm/UnverifiedAddress/index.js index fb7789f7..9f8c75eb 100644 --- a/src/components/modals/confirm/UnverifiedAddress/index.js +++ b/src/components/modals/confirm/UnverifiedAddress/index.js @@ -159,7 +159,7 @@ class ConfirmUnverifiedAddress extends PureComponent { this.showUnverifiedAddress()}> diff --git a/src/components/modals/confirm/UnverifiedAddress/index.messages.js b/src/components/modals/confirm/UnverifiedAddress/index.messages.js index 9390b84b..8f8efb17 100644 --- a/src/components/modals/confirm/UnverifiedAddress/index.messages.js +++ b/src/components/modals/confirm/UnverifiedAddress/index.messages.js @@ -33,11 +33,6 @@ const definedMessages: Messages = defineMessages({ id: 'TR_SHOW_UNVERIFIED_ADDRESS', defaultMessage: 'Show unverified address', }, - TR_TRY_AGAIN: { - id: 'TR_TRY_AGAIN', - defaultMessage: 'Try again', - description: 'Try to verify the address again', - }, TR_TO_PREVENT_PHISHING_ATTACKS_COMMA: { id: 'TR_TO_PREVENT_PHISHING_ATTACKS_COMMA', defaultMessage: diff --git a/src/components/notifications/Context/actions.messages.js b/src/components/notifications/Context/actions.messages.js new file mode 100644 index 00000000..3e4511fa --- /dev/null +++ b/src/components/notifications/Context/actions.messages.js @@ -0,0 +1,54 @@ +/* @flow */ +import { defineMessages } from 'react-intl'; +import type { Messages } from 'flowtype'; + +const definedMessages: Messages = defineMessages({ + TR_ACQUIRE_DEVICE_ERROR: { + id: 'TR_ACQUIRE_DEVICE_ERROR', + defaultMessage: 'Acquire device error', + }, + TR_AUTHENTICATION_ERROR: { + id: 'TR_AUTHENTICATION_ERROR', + defaultMessage: 'Authentication error', + }, + TR_ACCOUNT_DISCOVERY_ERROR: { + id: 'TR_ACCOUNT_DISCOVERY_ERROR', + defaultMessage: 'Account discovery error', + description: 'Error during account discovery', + }, + TR_TRANSACTION_ERROR: { + id: 'TR_TRANSACTION_ERROR', + defaultMessage: 'Transaction error', + description: 'Error during signing transaction', + }, + TR_TRANSACTION_SUCCESS: { + id: 'TR_TRANSACTION_SUCCESS', + defaultMessage: 'Transaction has been sent successfully', + }, + TR_SEE_TRANSACTION_DETAILS: { + id: 'TR_SEE_TRANSACTION_DETAILS', + defaultMessage: 'See transaction details', + }, + TR_VERIFYING_ADDRESS_ERROR: { + id: 'TR_VERIFYING_ADDRESS_ERROR', + defaultMessage: 'Verifying address error', + }, + TR_SIGN_MESSAGE_ERROR: { + id: 'TR_SIGN_MESSAGE_ERROR', + defaultMessage: 'Sign error', + }, + TR_VERIFY_MESSAGE_ERROR: { + id: 'TR_VERIFY_MESSAGE_ERROR', + defaultMessage: 'Verify error', + }, + TR_VERIFY_MESSAGE_SUCCESS: { + id: 'TR_VERIFY_MESSAGE_SUCCESS', + defaultMessage: 'Message has been successfully verified', + }, + TR_SIGNATURE_IS_VALID: { + id: 'TR_SIGNATURE_IS_VALID', + defaultMessage: 'Signature is valid', + }, +}); + +export default definedMessages; diff --git a/src/components/notifications/Context/components/Action/components/NotificationsGroups/components/Group/index.js b/src/components/notifications/Context/components/Action/components/NotificationsGroups/components/Group/index.js index 8f5e135c..2e9fffae 100644 --- a/src/components/notifications/Context/components/Action/components/NotificationsGroups/components/Group/index.js +++ b/src/components/notifications/Context/components/Action/components/NotificationsGroups/components/Group/index.js @@ -41,6 +41,18 @@ const StyledIcon = styled(Icon)` margin-right: 6px; `; +// const getLocalizedMessage = msg => { +// if ( +// typeof msg === 'object' && +// msg.hasOwnProperty('id') && +// msg.hasOwnProperty('defaultMessage') +// ) { +// //messageDescriptor +// return ; +// } +// return msg; +// }; + class Group extends PureComponent { constructor() { super(); @@ -114,7 +126,16 @@ Group.propTypes = { PropTypes.shape({ key: PropTypes.object, type: PropTypes.string, - title: PropTypes.oneOfType([PropTypes.string, PropTypes.node]), + title: PropTypes.oneOfType([ + PropTypes.string, + PropTypes.node, + PropTypes.shape({ + id: PropTypes.string, + defaultMessage: PropTypes.string, + description: PropTypes.string, + values: PropTypes.object, + }), + ]), message: PropTypes.oneOfType([PropTypes.string, PropTypes.node]), }) ), diff --git a/src/reducers/NotificationReducer.js b/src/reducers/NotificationReducer.js index 5e3691cc..a13cd240 100644 --- a/src/reducers/NotificationReducer.js +++ b/src/reducers/NotificationReducer.js @@ -8,7 +8,7 @@ import { DEVICE } from 'trezor-connect'; import type { Action } from 'flowtype'; export type CallbackAction = { - label: string, + label: React.Node, callback: Function, }; diff --git a/src/views/common.messages.js b/src/views/common.messages.js index 6ca13227..ba5c95fb 100644 --- a/src/views/common.messages.js +++ b/src/views/common.messages.js @@ -131,6 +131,11 @@ const definedMessages: Messages = defineMessages({ defaultMessage: 'Custom', description: 'fee level', }, + TR_TRY_AGAIN: { + id: 'TR_TRY_AGAIN', + defaultMessage: 'Try again', + description: 'Try to run the proccess again', + }, }); export default definedMessages; From 5843e0946d2e6da446e934ebd2dc67f6249e6ddf Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Mon, 29 Apr 2019 18:53:58 +0200 Subject: [PATCH 13/17] fix some msg ids --- src/components/DeviceHeader/index.messages.js | 2 +- src/views/Wallet/views/Account/Send/validation.messages.js | 2 +- src/views/Wallet/views/WalletSettings/index.messages.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/DeviceHeader/index.messages.js b/src/components/DeviceHeader/index.messages.js index d5058a07..329f1277 100644 --- a/src/components/DeviceHeader/index.messages.js +++ b/src/components/DeviceHeader/index.messages.js @@ -14,7 +14,7 @@ const definedMessages: Messages = defineMessages({ description: 'Device status', }, TR_CONNECTED_NOT_INITIALIZED: { - id: 'TR_CONNECTED', + id: 'TR_CONNECTED_NOT_INITIALIZED', defaultMessage: 'Connected (not initialized)', description: 'Device status', }, diff --git a/src/views/Wallet/views/Account/Send/validation.messages.js b/src/views/Wallet/views/Account/Send/validation.messages.js index 68a192aa..d951c7eb 100644 --- a/src/views/Wallet/views/Account/Send/validation.messages.js +++ b/src/views/Wallet/views/Account/Send/validation.messages.js @@ -12,7 +12,7 @@ const definedMessages: Messages = defineMessages({ defaultMessage: 'Amount is not a number', }, TR_MAXIMUM_DECIMALS_ALLOWED: { - id: 'TR_AMOUNT_IS_NOT_A_NUMBER', + id: 'TR_MAXIMUM_DECIMALS_ALLOWED:', defaultMessage: 'Maximum {decimals} decimals allowed', }, TR_NOT_ENOUGH_FUNDS_TO_COVER_TRANSACTION: { diff --git a/src/views/Wallet/views/WalletSettings/index.messages.js b/src/views/Wallet/views/WalletSettings/index.messages.js index a17d2227..078501f7 100644 --- a/src/views/Wallet/views/WalletSettings/index.messages.js +++ b/src/views/Wallet/views/WalletSettings/index.messages.js @@ -21,7 +21,7 @@ const definedMessages: Messages = defineMessages({ defaultMessage: 'Visible coins', }, TR_VISIBLE_COINS_EXTERNAL: { - id: 'TR_VISIBLE_COINS', + id: 'TR_VISIBLE_COINS_EXTERNAL:', defaultMessage: 'Visible external coins', }, TR_VISIBLE_COINS_EXPLAINED: { From f5f233f9403edbda5b2954363d4603296b200564 Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Tue, 30 Apr 2019 09:50:52 +0200 Subject: [PATCH 14/17] remove commented lines --- src/actions/ethereum/SendFormValidationActions.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/actions/ethereum/SendFormValidationActions.js b/src/actions/ethereum/SendFormValidationActions.js index 34f823f3..f90413ef 100644 --- a/src/actions/ethereum/SendFormValidationActions.js +++ b/src/actions/ethereum/SendFormValidationActions.js @@ -355,18 +355,14 @@ export const gasPriceValidation = ($state: State): PayloadAction => (): S const { gasPrice } = state; if (gasPrice.length < 1) { - // state.errors.gasPrice = 'Gas price is not set'; state.errors.gasPrice = 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 = 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 = l10nMessages.TR_GAS_PRICE_IS_TOO_HIGH; } else if (gp.isLessThanOrEqualTo('0')) { - // state.errors.gasPrice = 'Gas price is too low'; state.errors.gasPrice = l10nMessages.TR_GAS_PRICE_IS_TOO_LOW; } } @@ -388,18 +384,14 @@ export const nonceValidation = ($state: State): PayloadAction => ( const { nonce } = state; if (nonce.length < 1) { - // state.errors.nonce = 'Nonce is not set'; state.errors.nonce = l10nMessages.TR_NONCE_IS_NOT_SET; } else if (!validators.isAbs(nonce)) { - // state.errors.nonce = 'Nonce is not a valid number'; state.errors.nonce = 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 = l10nMessages.TR_NONCE_IS_LOWER_THAN_RECOMMENDED; } else if (n.isGreaterThan(account.nonce)) { - // state.warnings.nonce = 'Nonce is greater than recommended'; state.warnings.nonce = l10nMessages.TR_NONCE_IS_GREATER_THAN_RECOMMENDED; } } @@ -414,7 +406,6 @@ export const dataValidation = ($state: State): PayloadAction => (): State if (!state.touched.data || state.data.length === 0) return state; if (!ethUtils.isHex(state.data)) { - // state.errors.data = 'Data is not valid hexadecimal'; state.errors.data = l10nMessages.TR_DATA_IS_NOT_VALID_HEX; } return state; @@ -482,7 +473,6 @@ export const getFeeLevels = ( value: 'Custom', localizedValue: l10nCommonMessages.TR_CUSTOM_FEE, gasPrice: selected.gasPrice, - // label: `${ calculateFee(gasPrice, gasLimit) } ${ symbol }` label: `${calculateFee(selected.gasPrice, gasLimit)} ${symbol}`, } : { From 1a1a4daaa96ed42ac8ca489a1433d0409491ae00 Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Fri, 3 May 2019 21:58:45 +0200 Subject: [PATCH 15/17] cleanup --- src/utils/device.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/utils/device.js b/src/utils/device.js index b75c20fc..0b74a21a 100644 --- a/src/utils/device.js +++ b/src/utils/device.js @@ -53,40 +53,28 @@ export const getStatus = (device: TrezorDevice): string => { export const getStatusName = (deviceStatus: string, intl: IntlShape): string => { switch (deviceStatus) { case 'connected': - // return 'Connected'; return intl.formatMessage(l10nMessages.TR_CONNECTED); case 'disconnected': - // return 'Disconnected'; return intl.formatMessage(l10nMessages.TR_DISCONNECTED); case 'bootloader': - // return 'Connected (bootloader mode)'; return intl.formatMessage(l10nMessages.TR_CONNECTED_BOOTLOADER); case 'initialize': - // return 'Connected (not initialized)'; return intl.formatMessage(l10nMessages.TR_CONNECTED_NOT_INITIALIZED); case 'seedless': - // return 'Connected (seedless mode)'; return intl.formatMessage(l10nMessages.TR_CONNECTED_SEEDLESS); case 'firmware-required': - // return 'Connected (update required)'; return intl.formatMessage(l10nMessages.TR_CONNECTED_UPDATE_REQUIRED); case 'firmware-recommended': - // return 'Connected (update recommended)'; return intl.formatMessage(l10nMessages.TR_CONNECTED_UPDATE_RECOMMENDED); case 'used-in-other-window': - // return 'Used in other window'; return intl.formatMessage(l10nMessages.TR_USED_IN_ANOTHER_WINDOW); case 'unacquired': - // return 'Used in other window'; return intl.formatMessage(l10nMessages.TR_USED_IN_ANOTHER_WINDOW); case 'unavailable': - // return 'Unavailable'; return intl.formatMessage(l10nMessages.TR_UNAVAILABLE); case 'unreadable': - // return 'Unreadable'; return intl.formatMessage(l10nMessages.TR_UNREADABLE); default: - // return 'Status unknown'; return intl.formatMessage(l10nMessages.TR_STATUS_UNKNOWN); } }; From adce529d5aed48ad6783900c6d9bfdeaa8b16e19 Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Fri, 3 May 2019 22:03:29 +0200 Subject: [PATCH 16/17] mend --- src/actions/ethereum/SendFormValidationActions.js | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/actions/ethereum/SendFormValidationActions.js b/src/actions/ethereum/SendFormValidationActions.js index f90413ef..f3509031 100644 --- a/src/actions/ethereum/SendFormValidationActions.js +++ b/src/actions/ethereum/SendFormValidationActions.js @@ -152,16 +152,13 @@ export const addressValidation = ($state: State): PayloadAction => (): St const { address } = state; if (address.length < 1) { - // state.errors.address = 'Address is not set'; state.errors.address = l10nMessages.TR_ADDRESS_IS_NOT_SET; } else if (!EthereumjsUtil.isValidAddress(address)) { - // state.errors.address = 'Address is not valid'; state.errors.address = l10nMessages.TR_ADDRESS_IS_NOT_VALID; } else if ( validators.hasUppercase(address) && !EthereumjsUtil.isValidChecksumAddress(address) ) { - // state.errors.address = 'Address is not a valid checksum'; state.errors.address = l10nMessages.TR_ADDRESS_CHECKSUM_IS_NOT_VALID; } return state; @@ -262,7 +259,6 @@ export const amountValidation = ($state: State): PayloadAction => ( if (!token) return state; if (!validators.hasDecimals(state.amount, parseInt(token.decimals, 0))) { - // state.errors.amount = `Maximum ${token.decimals} decimals allowed`; state.errors.amount = { ...l10nMessages.TR_MAXIMUM_DECIMALS_ALLOWED, values: { decimals: token.decimals }, @@ -274,21 +270,17 @@ export const amountValidation = ($state: State): PayloadAction => ( networkSymbol: state.networkSymbol, }, }; - // state.errors.amount = `Not enough ${state.networkSymbol} to cover transaction fee`; } else if ( new BigNumber(state.amount).isGreaterThan( new BigNumber(token.balance).minus(pendingAmount) ) ) { - // state.errors.amount = 'Not enough funds'; state.errors.amount = l10nMessages.TR_NOT_ENOUGH_FUNDS; } else if (new BigNumber(state.amount).isLessThanOrEqualTo('0')) { // TODO: this is never gonna happen! It will fail in second if condiftion (isNumber validation) - // state.errors.amount = 'Amount is too low'; state.errors.amount = l10nMessages.TR_AMOUNT_IS_TOO_LOW; } } else if (!validators.hasDecimals(state.amount, 18)) { - // state.errors.amount = 'Maximum 18 decimals allowed'; state.errors.amount = { ...l10nMessages.TR_MAXIMUM_DECIMALS_ALLOWED, values: { @@ -300,7 +292,6 @@ export const amountValidation = ($state: State): PayloadAction => ( new BigNumber(account.balance).minus(pendingAmount) ) ) { - // state.errors.amount = 'Not enough funds'; state.errors.amount = l10nMessages.TR_NOT_ENOUGH_FUNDS; } } @@ -322,15 +313,12 @@ export const gasLimitValidation = ($state: State): PayloadAction => ( const { gasLimit } = state; if (gasLimit.length < 1) { - // state.errors.gasLimit = 'Gas limit is not set'; state.errors.gasLimit = l10nMessages.TR_GAS_LIMIT_IS_NOT_SET; } else if (gasLimit.length > 0 && !validators.isNumber(gasLimit)) { - // state.errors.gasLimit = 'Gas limit is not a number'; state.errors.gasLimit = l10nMessages.TR_GAS_LIMIT_IS_NOT_A_NUMBER; } else { const gl: BigNumber = new BigNumber(gasLimit); if (gl.isLessThan(1)) { - // state.errors.gasLimit = 'Gas limit is too low'; state.errors.gasLimit = l10nMessages.TR_GAS_LIMIT_IS_TOO_LOW; } else if ( gl.isLessThan( @@ -339,7 +327,6 @@ export const gasLimitValidation = ($state: State): PayloadAction => ( : network.defaultGasLimit ) ) { - // state.warnings.gasLimit = 'Gas limit is below recommended'; state.warnings.gasLimit = l10nMessages.TR_GAS_LIMIT_IS_BELOW_RECOMMENDED; } } From f01c6f735d22ee4f9ed67a2cd1a0bdffada2a53e Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Mon, 6 May 2019 21:02:10 +0200 Subject: [PATCH 17/17] cleanup --- src/actions/ethereum/SendFormValidationActions.js | 2 -- .../NotificationsGroups/components/Group/index.js | 12 ------------ 2 files changed, 14 deletions(-) diff --git a/src/actions/ethereum/SendFormValidationActions.js b/src/actions/ethereum/SendFormValidationActions.js index f3509031..33aa0ec6 100644 --- a/src/actions/ethereum/SendFormValidationActions.js +++ b/src/actions/ethereum/SendFormValidationActions.js @@ -240,10 +240,8 @@ export const amountValidation = ($state: State): PayloadAction => ( const { amount } = state; if (amount.length < 1) { - // state.errors.amount = 'Amount is not set'; state.errors.amount = l10nMessages.TR_AMOUNT_IS_NOT_SET; } else if (amount.length > 0 && !validators.isNumber(amount)) { - // state.errors.amount = 'Amount is not a number'; state.errors.amount = l10nMessages.TR_AMOUNT_IS_NOT_A_NUMBER; } else { const isToken: boolean = state.currency !== state.networkSymbol; diff --git a/src/components/notifications/Context/components/Action/components/NotificationsGroups/components/Group/index.js b/src/components/notifications/Context/components/Action/components/NotificationsGroups/components/Group/index.js index 74232118..49490105 100644 --- a/src/components/notifications/Context/components/Action/components/NotificationsGroups/components/Group/index.js +++ b/src/components/notifications/Context/components/Action/components/NotificationsGroups/components/Group/index.js @@ -41,18 +41,6 @@ const StyledIcon = styled(Icon)` margin-right: 6px; `; -// const getLocalizedMessage = msg => { -// if ( -// typeof msg === 'object' && -// msg.hasOwnProperty('id') && -// msg.hasOwnProperty('defaultMessage') -// ) { -// //messageDescriptor -// return ; -// } -// return msg; -// }; - class Group extends PureComponent { constructor() { super();