diff --git a/src/actions/account.js b/src/actions/account.js index 566d67ae9..7049337b8 100644 --- a/src/actions/account.js +++ b/src/actions/account.js @@ -5,6 +5,7 @@ import { transactionAdded } from './transactions'; import { errorAlertDialogDisplayed } from './dialog'; import Fees from '../constants/fees'; import { toRawLsk } from '../utils/lsk'; +import transactionTypes from '../constants/transactionTypes'; /** * Trigger this action to update the account object @@ -58,7 +59,7 @@ export const secondPassphraseRegistered = ({ activePeer, secondPassphrase, accou senderId: account.address, amount: 0, fee: Fees.setSecondPassphrase, - type: 1, + type: transactionTypes.setSecondPassphrase, })); }).catch((error) => { const text = (error && error.message) ? error.message : 'An error occurred while registering your second passphrase. Please try again.'; @@ -83,7 +84,7 @@ export const delegateRegistered = ({ username, amount: 0, fee: Fees.registerDelegate, - type: 2, + type: transactionTypes.registerDelegate, })); }) .catch((error) => { @@ -108,7 +109,7 @@ export const sent = ({ activePeer, account, recipientId, amount, passphrase, sec recipientId, amount: toRawLsk(amount), fee: Fees.send, - type: 0, + type: transactionTypes.send, })); }) .catch((error) => { diff --git a/src/actions/account.test.js b/src/actions/account.test.js index 6e0845187..70d62b258 100644 --- a/src/actions/account.test.js +++ b/src/actions/account.test.js @@ -9,6 +9,7 @@ import * as accountApi from '../utils/api/account'; import * as delegateApi from '../utils/api/delegate'; import Fees from '../constants/fees'; import { toRawLsk } from '../utils/lsk'; +import transactionTypes from '../constants/transactionTypes'; describe('actions: account', () => { describe('accountUpdated', () => { @@ -69,7 +70,7 @@ describe('actions: account', () => { senderId: 'test_address', amount: 0, fee: Fees.setSecondPassphrase, - type: 1, + type: transactionTypes.setSecondPassphrase, }; actionFunction(dispatch); @@ -129,7 +130,7 @@ describe('actions: account', () => { username: data.username, amount: 0, fee: Fees.registerDelegate, - type: 2, + type: transactionTypes.registerDelegate, }; actionFunction(dispatch); @@ -191,7 +192,7 @@ describe('actions: account', () => { recipientId: data.recipientId, amount: toRawLsk(data.amount), fee: Fees.send, - type: 0, + type: transactionTypes.send, }; actionFunction(dispatch); diff --git a/src/actions/dialog.js b/src/actions/dialog.js index cc951babb..991b5a0da 100644 --- a/src/actions/dialog.js +++ b/src/actions/dialog.js @@ -1,5 +1,6 @@ -import actionTypes from '../constants/actions'; +import i18next from 'i18next'; import Alert from '../components/dialog/alert'; +import actionTypes from '../constants/actions'; /** * An action to dispatch to display a dialog @@ -28,7 +29,7 @@ export const alertDialogDisplayed = data => dialogDisplayed({ * */ export const successAlertDialogDisplayed = data => alertDialogDisplayed({ - title: 'Success', + title: i18next.t('Success'), text: data.text, type: 'success', }); @@ -38,7 +39,7 @@ export const successAlertDialogDisplayed = data => alertDialogDisplayed({ * */ export const errorAlertDialogDisplayed = data => alertDialogDisplayed({ - title: 'Error', + title: i18next.t('Error'), text: data.text, type: 'error', }); diff --git a/src/actions/voting.js b/src/actions/voting.js index 434871b19..7dee77a66 100644 --- a/src/actions/voting.js +++ b/src/actions/voting.js @@ -4,6 +4,7 @@ import { errorAlertDialogDisplayed } from './dialog'; import { passphraseUsed } from './account'; import actionTypes from '../constants/actions'; import Fees from '../constants/fees'; +import transactionTypes from '../constants/transactionTypes'; /** * Add pending variable to the list of voted delegates and list of unvoted delegates @@ -82,7 +83,7 @@ export const votePlaced = ({ activePeer, passphrase, account, votes, secondSecre senderId: account.address, amount: 0, fee: Fees.vote, - type: 3, + type: transactionTypes.vote, })); }).catch((error) => { const text = error && error.message ? `${error.message}.` : 'An error occurred while placing your vote.'; diff --git a/src/components/account/account.js b/src/components/account/account.js index 24984024a..40bb821d0 100644 --- a/src/components/account/account.js +++ b/src/components/account/account.js @@ -63,7 +63,7 @@ const Account = ({ LSK

- Click to send all funds + {t('Click to send all funds')}

diff --git a/src/components/account/account.test.js b/src/components/account/account.test.js index 1e8b16e24..ac1215b47 100644 --- a/src/components/account/account.test.js +++ b/src/components/account/account.test.js @@ -1,7 +1,8 @@ import React from 'react'; import { expect } from 'chai'; -import sinon from 'sinon'; import { shallow } from 'enzyme'; +import sinon from 'sinon'; +import i18n from '../../i18n'; import store from '../../store'; import Account from './account'; import ClickToSend from '../clickToSend'; @@ -50,7 +51,7 @@ describe('Account', () => { it('should render balance with ClickToSend component', () => { const wrapper = shallow(, { - context: { store }, + context: { store, i18n }, childContextTypes: { }, }); diff --git a/src/components/account/address.js b/src/components/account/address.js index fc32378b7..4a391f248 100644 --- a/src/components/account/address.js +++ b/src/components/account/address.js @@ -6,11 +6,11 @@ import styles from './account.css'; const getStatusTooltip = (props) => { if (props.secondSignature) { - return 'This account is protected by a second passphrase'; + return props.t('This account is protected by a second passphrase'); } else if (props.passphrase) { - return 'Passphrase of the acount is saved till the end of the session.'; + return props.t('Passphrase of the account is saved till the end of the session.'); } - return 'Passphrase of the acount will be required to perform any transaction.'; + return props.t('Passphrase of the account will be required to perform any transaction.'); }; const Address = (props) => { diff --git a/src/components/actionBar/index.js b/src/components/actionBar/index.js index 4cf130b21..34eb8a62e 100644 --- a/src/components/actionBar/index.js +++ b/src/components/actionBar/index.js @@ -1,20 +1,22 @@ -import React from 'react'; +import { translate } from 'react-i18next'; import Button from 'react-toolbox/lib/button'; +import React from 'react'; import grid from 'flexboxgrid/dist/flexboxgrid.css'; import PricedButton from '../pricedButton'; import styles from './actionBar.css'; -const ActionBar = ({ - secondaryButton, primaryButton, account, +export const ActionBarRaw = ({ + secondaryButton, primaryButton, account, t, }) => (
); -export default Alert; +export default translate()(Alert); diff --git a/src/components/dialog/alert.test.js b/src/components/dialog/alert.test.js index 3e382b2b8..813353dd9 100644 --- a/src/components/dialog/alert.test.js +++ b/src/components/dialog/alert.test.js @@ -1,18 +1,26 @@ +import PropTypes from 'prop-types'; import React from 'react'; import { expect } from 'chai'; import { mount } from 'enzyme'; import sinon from 'sinon'; import Alert from './alert'; +import i18n from '../../i18n'; describe('Alert', () => { let wrapper; let closeSpy; const text = 'some random text'; + const options = { + context: { i18n }, + childContextTypes: { + i18n: PropTypes.object.isRequired, + }, + }; beforeEach(() => { closeSpy = sinon.spy(); - wrapper = mount(); + wrapper = mount(, options); }); it('renders paragraph with props.text', () => { diff --git a/src/components/dialog/dialog.js b/src/components/dialog/dialog.js index 65adec27b..4f0dbbb6d 100644 --- a/src/components/dialog/dialog.js +++ b/src/components/dialog/dialog.js @@ -4,7 +4,7 @@ import Navigation from 'react-toolbox/lib/navigation'; import AppBar from 'react-toolbox/lib/app_bar'; import { IconButton } from 'react-toolbox/lib/button'; import styles from './dialog.css'; -import dialogs from './dialogs'; +import getDialogs from './dialogs'; class DialogElement extends Component { constructor() { @@ -55,6 +55,7 @@ class DialogElement extends Component { item.regex.test(this.props.history.location.pathname)); this.current.pathname = this.props.history.location.pathname; const dialogName = this.props.history.location.pathname.replace(this.current.reg.path, ''); + const dialogs = getDialogs(); if (dialogs[dialogName] !== undefined) { this.open(this.current.reg, dialogs[dialogName]); } else { diff --git a/src/components/dialog/dialog.test.js b/src/components/dialog/dialog.test.js index 6b4148cd4..17c83829f 100644 --- a/src/components/dialog/dialog.test.js +++ b/src/components/dialog/dialog.test.js @@ -25,6 +25,7 @@ describe('Dialog', () => { const props = { dialogDisplayed: () => {}, + t: key => key, }; beforeEach(() => { diff --git a/src/components/dialog/dialogs.js b/src/components/dialog/dialogs.js index 3877348c0..aeeb78683 100644 --- a/src/components/dialog/dialogs.js +++ b/src/components/dialog/dialogs.js @@ -1,3 +1,4 @@ +import i18next from 'i18next'; import ReceiveDialog from '../receiveDialog'; import Register from '../register'; import RegisterDelegate from '../registerDelegate'; @@ -9,45 +10,45 @@ import SignMessage from '../signMessage'; import VerifyMessage from '../verifyMessage'; import VoteDialog from '../voteDialog'; -export default { +export default () => ({ send: { - title: 'Send', + title: i18next.t('Send'), component: Send, }, 'register-delegate': { - title: 'Register as delegate', + title: i18next.t('Register as delegate'), component: RegisterDelegate, }, 'sign-message': { - title: 'Sign message', + title: i18next.t('Sign message'), component: SignMessage, }, 'verify-message': { - title: 'Verify message', + title: i18next.t('Verify message'), component: VerifyMessage, }, 'register-second-passphrase': { - title: 'Register Second Passphrase', + title: i18next.t('Register Second Passphrase'), component: SecondPassphrase, }, vote: { - title: 'Vote for delegates', + title: i18next.t('Vote for delegates'), component: VoteDialog, }, receive: { - title: 'Receive LSK', + title: i18next.t('Receive LSK'), component: ReceiveDialog, }, register: { - title: 'New Account', + title: i18next.t('New Account'), component: Register, }, 'save-account': { - title: 'Remember this account', + title: i18next.t('Remember this account'), component: SaveAccount, }, settings: { - title: 'Settings', + title: i18next.t('Settings'), component: Settings, }, -}; +}); diff --git a/src/components/forging/forging.js b/src/components/forging/forging.js index e46087202..ba6d51a00 100644 --- a/src/components/forging/forging.js +++ b/src/components/forging/forging.js @@ -7,7 +7,7 @@ import ForgingStats from './forgingStats'; import ForgedBlocks from './forgedBlocks'; const Forging = ({ - account, statistics, forgedBlocks, peers, onForgedBlocksLoaded, onForgingStatsUpdated, + account, statistics, forgedBlocks, peers, onForgedBlocksLoaded, onForgingStatsUpdated, t, }) => { const loadStats = (key, startMoment) => { onForgingStatsUpdated({ @@ -50,9 +50,7 @@ const Forging = ({ } {account && account.delegate && !account.isDelegate ?

- You need to become a delegate to start forging. - If you already registered to become a delegate, - your registration hasn't been processed, yet. + {t('You need to become a delegate to start forging. If you already registered to become a delegate, your registration hasn\'t been processed, yet.')}

: null } diff --git a/src/components/forging/forging.test.js b/src/components/forging/forging.test.js index e7ce164f3..3632df9d8 100644 --- a/src/components/forging/forging.test.js +++ b/src/components/forging/forging.test.js @@ -18,6 +18,7 @@ describe('Forging', () => { forgedBlocks: [], onForgingStatsUpdated: sinon.spy(), onForgedBlocksLoaded: sinon.spy(), + t: key => key, }; let account; diff --git a/src/components/forging/index.js b/src/components/forging/index.js index 9f799e467..598be0ea5 100644 --- a/src/components/forging/index.js +++ b/src/components/forging/index.js @@ -1,4 +1,5 @@ import { connect } from 'react-redux'; +import { translate } from 'react-i18next'; import { fetchAndUpdateForgedBlocks, fetchAndUpdateForgedStats } from '../../actions/forging'; import Forging from './forging'; @@ -17,4 +18,4 @@ const mapDispatchToProps = dispatch => ({ export default connect( mapStateToProps, mapDispatchToProps, -)(Forging); +)(translate()(Forging)); diff --git a/src/components/forging/index.test.js b/src/components/forging/index.test.js index d3176ef07..ee28023fb 100644 --- a/src/components/forging/index.test.js +++ b/src/components/forging/index.test.js @@ -1,8 +1,9 @@ import React from 'react'; import { expect } from 'chai'; import { mount } from 'enzyme'; -import { Provider } from 'react-redux'; import configureMockStore from 'redux-mock-store'; +import PropTypes from 'prop-types'; +import i18n from '../../i18n'; import ForgingHOC from './index'; describe('Forging HOC', () => { @@ -18,7 +19,14 @@ describe('Forging HOC', () => { forgedBlocks: [], }, }); - wrapper = mount(); + const options = { + context: { store, i18n }, + childContextTypes: { + store: PropTypes.object.isRequired, + i18n: PropTypes.object.isRequired, + }, + }; + wrapper = mount(, options); }); it('should render Forging component', () => { diff --git a/src/components/header/header.js b/src/components/header/header.js index 65370c022..d0c471acd 100644 --- a/src/components/header/header.js +++ b/src/components/header/header.js @@ -27,22 +27,22 @@ const Header = props => ( !props.account.isDelegate && Register as delegate + to='register-delegate'>{props.t('Register as delegate')} } { !props.account.secondSignature && Register second passphrase + to='register-second-passphrase'>{props.t('Register second passphrase')} } - Sign message + {props.t('Sign message')} Verify message + to='verify-message'>{props.t('Verify message')} diff --git a/src/components/login/login.js b/src/components/login/login.js index f954a4dee..7f5ebcb31 100644 --- a/src/components/login/login.js +++ b/src/components/login/login.js @@ -3,7 +3,7 @@ import grid from 'flexboxgrid/dist/flexboxgrid.css'; import Input from 'react-toolbox/lib/input'; import Dropdown from 'react-toolbox/lib/dropdown'; import Button from 'react-toolbox/lib/button'; -import networksRaw from './networks'; +import getNetworks from './networks'; import PassphraseInput from '../passphraseInput'; import styles from './login.css'; import env from '../../constants/env'; @@ -17,11 +17,6 @@ class Login extends React.Component { constructor() { super(); - this.networks = networksRaw.map((network, index) => ({ - label: network.name, - value: index, - })); - this.state = { passphrase: '', address: '', @@ -35,6 +30,11 @@ class Login extends React.Component { } componentWillMount() { + this.networks = getNetworks().map((network, index) => ({ + label: network.name, + value: index, + })); + this.props.accountsRetrieved(); } @@ -53,7 +53,7 @@ class Login extends React.Component { } onLoginSubmission(passphrase) { - const network = Object.assign({}, networksRaw[this.state.network]); + const network = Object.assign({}, getNetworks()[this.state.network]); if (this.state.network === 2) { network.address = this.state.address; } @@ -144,7 +144,7 @@ class Login extends React.Component { const { savedAccounts } = this.props; if (savedAccounts && savedAccounts.length > 0 && !this.props.account.afterLogout) { this.account = savedAccounts[0]; - const network = Object.assign({}, networksRaw[this.account.network]); + const network = Object.assign({}, getNetworks()[this.account.network]); if (this.account.network === 2) { network.address = this.account.address; } @@ -194,8 +194,10 @@ class Login extends React.Component {