1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-15 21:08:57 +00:00
trezor-wallet/src/store.js

72 lines
2.1 KiB
JavaScript
Raw Normal View History

2017-12-13 11:01:37 +00:00
/* @flow */
2018-07-30 10:52:13 +00:00
2018-04-16 21:19:50 +00:00
import { createStore, applyMiddleware, compose } from 'redux';
import { routerMiddleware } from 'connected-react-router';
2018-04-16 21:19:50 +00:00
import thunk from 'redux-thunk';
import createHistory from 'history/createHashHistory';
2018-09-12 14:59:31 +00:00
import { createLogger } from 'redux-logger';
import createRootReducer from 'reducers';
2018-08-14 13:18:16 +00:00
import services from 'services';
2018-05-11 19:01:43 +00:00
import Raven from 'raven-js';
2018-04-16 21:19:50 +00:00
import RavenMiddleware from 'redux-raven-middleware';
2018-10-11 16:04:25 +00:00
import * as buildUtils from 'utils/build';
2018-04-16 21:19:50 +00:00
2018-10-09 13:20:57 +00:00
import type { Action, GetState } from 'flowtype';
2018-04-16 21:19:50 +00:00
2018-07-30 10:52:13 +00:00
export const history: History = createHistory({ queryKey: false });
2018-04-16 21:19:50 +00:00
const initialState: any = {};
const enhancers = [];
const middlewares = [
2018-04-16 21:19:50 +00:00
thunk,
2018-07-30 10:52:13 +00:00
routerMiddleware(history),
2018-04-16 21:19:50 +00:00
];
2018-10-11 16:04:25 +00:00
// sentry io middleware only in dev and beta build
if (buildUtils.isDev() || buildUtils.isBeta()) {
const RAVEN_KEY = 'https://34b8c09deb6c4cd2a4dc3f0029cd02d8@sentry.io/1279550';
const ravenMiddleware = RavenMiddleware(RAVEN_KEY);
Raven.config(RAVEN_KEY).install();
middlewares.push(ravenMiddleware);
}
2018-04-16 21:19:50 +00:00
2018-05-05 11:52:03 +00:00
let composedEnhancers: any;
2018-10-11 16:04:25 +00:00
if (buildUtils.isDev()) {
2018-09-12 14:59:31 +00:00
const excludeLogger = (getState: GetState, action: Action): boolean => {
//'@@router/LOCATION_CHANGE'
2018-09-14 10:20:39 +00:00
const excluded: Array<?string> = ['LOG_TO_EXCLUDE', 'log__add', undefined];
const pass: Array<?string> = excluded.filter(act => action.type === act);
2018-09-12 14:59:31 +00:00
return pass.length === 0;
};
2018-07-30 10:52:13 +00:00
2018-09-03 15:47:15 +00:00
const logger = createLogger({
level: 'info',
predicate: excludeLogger,
collapsed: true,
});
2018-12-18 09:53:11 +00:00
/* eslint-disable no-underscore-dangle */
if (window && typeof window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ === 'function') {
enhancers.push(window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__());
2018-09-03 15:47:15 +00:00
}
2018-12-18 09:53:11 +00:00
/* eslint-enable */
2018-09-03 15:47:15 +00:00
2018-05-05 11:52:03 +00:00
composedEnhancers = compose(
applyMiddleware(logger, ...middlewares, ...services),
2018-07-30 10:52:13 +00:00
...enhancers,
2018-05-05 11:52:03 +00:00
);
} else {
composedEnhancers = compose(
applyMiddleware(...middlewares, ...services),
2018-07-30 10:52:13 +00:00
...enhancers,
2018-05-05 11:52:03 +00:00
);
}
2018-04-16 21:19:50 +00:00
export default createStore(
createRootReducer(history),
2018-04-16 21:19:50 +00:00
initialState,
2018-07-30 10:52:13 +00:00
composedEnhancers,
2018-04-16 21:19:50 +00:00
);