From 25e8c6ae561a0b9e1c6c60596b110814faa44a2f Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Mon, 29 Apr 2019 18:49:16 +0200 Subject: [PATCH] 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;