diff --git a/common/actions/config.js b/common/actions/config.js index 2e94eb14..b721d8de 100644 --- a/common/actions/config.js +++ b/common/actions/config.js @@ -1,5 +1,4 @@ // @flow -import { setLanguage } from 'translations'; export type ChangeNodeAction = { type: 'CONFIG_NODE_CHANGE', @@ -15,7 +14,6 @@ export type ChangeLanguageAction = { export type ConfigAction = ChangeNodeAction | ChangeLanguageAction; export function changeLanguage(sign: string) { - setLanguage(sign); return { type: 'CONFIG_LANGUAGE_CHANGE', value: sign diff --git a/common/index.jsx b/common/index.jsx index 004c5402..ca1b8cdc 100644 --- a/common/index.jsx +++ b/common/index.jsx @@ -1,72 +1,14 @@ import React from 'react'; import { render } from 'react-dom'; -import { syncHistoryWithStore, routerMiddleware } from 'react-router-redux'; -import { composeWithDevTools } from 'redux-devtools-extension'; -import Perf from 'react-addons-perf'; -import { createStore, applyMiddleware } from 'redux'; -import RootReducer from './reducers'; +import { syncHistoryWithStore } from 'react-router-redux'; + import { Root } from 'components'; import { Routing, history } from './routing'; -import { createLogger } from 'redux-logger'; -import createSagaMiddleware from 'redux-saga'; -import notificationsSaga from './sagas/notifications'; -import ensSaga from './sagas/ens'; -import walletSaga from './sagas/wallet'; -import { initialState as configInitialState } from 'reducers/config'; -import throttle from 'lodash/throttle'; +import { store } from './store'; // application styles import 'assets/styles/etherwallet-master.less'; -import { saveState, loadStatePropertyOrEmptyObject } from 'utils/localStorage'; - -let store; - -const configureStore = () => { - const logger = createLogger({ - collapsed: true - }); - const sagaMiddleware = createSagaMiddleware(); - let middleware; - - if (process.env.NODE_ENV !== 'production') { - window.Perf = Perf; - middleware = composeWithDevTools( - applyMiddleware(sagaMiddleware, logger, routerMiddleware(history)) - ); - } else { - middleware = applyMiddleware(sagaMiddleware, routerMiddleware(history)); - } - - const persistedConfigInitialState = { - config: { - ...configInitialState, - ...loadStatePropertyOrEmptyObject('config') - } - }; - - const completePersistedInitialState = { - ...persistedConfigInitialState - }; - - store = createStore(RootReducer, completePersistedInitialState, middleware); - sagaMiddleware.run(notificationsSaga); - sagaMiddleware.run(ensSaga); - sagaMiddleware.run(walletSaga); - - store.subscribe( - throttle(() => { - saveState({ - config: { - languageSelection: store.getState().config.languageSelection - } - }); - }), - 1000 - ); - return store; -}; const renderRoot = Root => { - let store = configureStore(); let syncedHistory = syncHistoryWithStore(history, store); render( { + const logger = createLogger({ + collapsed: true + }); + const sagaMiddleware = createSagaMiddleware(); + let middleware; + let store; + + if (process.env.NODE_ENV !== 'production') { + window.Perf = Perf; + middleware = composeWithDevTools( + applyMiddleware(sagaMiddleware, logger, routerMiddleware(history)) + ); + } else { + middleware = applyMiddleware(sagaMiddleware, routerMiddleware(history)); + } + + const persistedConfigInitialState = { + config: { + ...configInitialState, + ...loadStatePropertyOrEmptyObject('config') + } + }; + + const completePersistedInitialState = { + ...persistedConfigInitialState + }; + + store = createStore(RootReducer, completePersistedInitialState, middleware); + sagaMiddleware.run(notificationsSaga); + sagaMiddleware.run(ensSaga); + sagaMiddleware.run(walletSaga); + + store.subscribe( + throttle(() => { + saveState({ + config: { + languageSelection: store.getState().config.languageSelection + } + }); + }), + 1000 + ); + return store; +}; + +export const store = configureStore(); diff --git a/common/translations/index.js b/common/translations/index.js index fe6a9820..cba9bef5 100644 --- a/common/translations/index.js +++ b/common/translations/index.js @@ -1,6 +1,6 @@ // @flow import { markupToReact } from './markup'; -let activeLanguage = 'en'; +import { store } from '../store'; let fallbackLanguage = 'en'; let repository = {}; @@ -31,11 +31,8 @@ languages.forEach(l => { repository[l.code] = l.data; }); -export function setLanguage(code: string) { - activeLanguage = code; -} - export default function translate(key: string) { + let activeLanguage = store.getState().config.languageSelection; return markupToReact( (repository[activeLanguage] && repository[activeLanguage][key]) || repository[fallbackLanguage][key] ||