1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-12-25 16:38:08 +00:00
trezor-wallet/src/store.js

75 lines
2.2 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';
2018-09-06 15:04:28 +00:00
import { routerMiddleware } from 'react-router-redux';
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';
2018-08-14 13:18:16 +00:00
import reducers from 'reducers';
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-09-12 14:59:31 +00:00
import type { Action, GetState, Store } 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
];
// sentry io middleware only in dev build
if (process.env.BUILD === 'development') {
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-04-16 21:19:50 +00:00
if (process.env.NODE_ENV === 'development') {
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,
});
const devToolsExtension: ?Function = window.devToolsExtension;
if (typeof devToolsExtension === 'function') {
enhancers.push(devToolsExtension());
}
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(
reducers,
initialState,
2018-07-30 10:52:13 +00:00
composedEnhancers,
2018-04-16 21:19:50 +00:00
);
// if (process.env.NODE_ENV === 'production') {
// module.exports = require('./store.dev'); // eslint-disable-line global-require
// } else {
// module.exports = require('./store.dev'); // eslint-disable-line global-require
// }