2017-07-16 21:02:13 +00:00
|
|
|
import {
|
|
|
|
saveState,
|
|
|
|
loadState,
|
|
|
|
loadStatePropertyOrEmptyObject
|
|
|
|
} from 'utils/localStorage';
|
2017-07-05 23:28:54 +00:00
|
|
|
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';
|
2017-07-08 02:00:09 +00:00
|
|
|
import bitySaga from './sagas/bity';
|
2017-07-13 21:02:39 +00:00
|
|
|
import ratesSaga from './sagas/rates';
|
2017-07-05 23:28:54 +00:00
|
|
|
import { initialState as configInitialState } from 'reducers/config';
|
2017-07-13 21:02:39 +00:00
|
|
|
import { initialState as customTokensInitialState } from 'reducers/customTokens';
|
2017-07-05 23:28:54 +00:00
|
|
|
import throttle from 'lodash/throttle';
|
|
|
|
import { composeWithDevTools } from 'redux-devtools-extension';
|
|
|
|
import Perf from 'react-addons-perf';
|
|
|
|
import { createStore, applyMiddleware } from 'redux';
|
|
|
|
import RootReducer from './reducers';
|
|
|
|
import { routerMiddleware } from 'react-router-redux';
|
|
|
|
|
|
|
|
const configureStore = () => {
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2017-07-13 21:02:39 +00:00
|
|
|
const persistedInitialState = {
|
2017-07-05 23:28:54 +00:00
|
|
|
config: {
|
|
|
|
...configInitialState,
|
|
|
|
...loadStatePropertyOrEmptyObject('config')
|
2017-07-13 21:02:39 +00:00
|
|
|
},
|
|
|
|
customTokens: (loadState() || {}).customTokens || customTokensInitialState
|
2017-07-05 23:28:54 +00:00
|
|
|
};
|
|
|
|
|
2017-07-13 21:02:39 +00:00
|
|
|
store = createStore(RootReducer, persistedInitialState, middleware);
|
2017-07-05 23:28:54 +00:00
|
|
|
sagaMiddleware.run(notificationsSaga);
|
|
|
|
sagaMiddleware.run(ensSaga);
|
|
|
|
sagaMiddleware.run(walletSaga);
|
2017-07-08 02:00:09 +00:00
|
|
|
sagaMiddleware.run(bitySaga);
|
2017-07-13 21:02:39 +00:00
|
|
|
sagaMiddleware.run(ratesSaga);
|
2017-07-05 23:28:54 +00:00
|
|
|
|
|
|
|
store.subscribe(
|
|
|
|
throttle(() => {
|
|
|
|
saveState({
|
|
|
|
config: {
|
|
|
|
languageSelection: store.getState().config.languageSelection
|
2017-07-13 21:02:39 +00:00
|
|
|
},
|
|
|
|
customTokens: store.getState().customTokens
|
2017-07-05 23:28:54 +00:00
|
|
|
});
|
|
|
|
}),
|
|
|
|
1000
|
|
|
|
);
|
|
|
|
return store;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const store = configureStore();
|