1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-12-25 00:18:07 +00:00
trezor-wallet/src/store.js
2018-09-19 16:55:09 +02:00

75 lines
2.2 KiB
JavaScript

/* @flow */
import { createStore, applyMiddleware, compose } from 'redux';
import { routerMiddleware } from 'react-router-redux';
import thunk from 'redux-thunk';
import createHistory from 'history/createHashHistory';
import { createLogger } from 'redux-logger';
import reducers from 'reducers';
import services from 'services';
import Raven from 'raven-js';
import RavenMiddleware from 'redux-raven-middleware';
import type { Action, GetState, Store } from 'flowtype';
export const history: History = createHistory({ queryKey: false });
const initialState: any = {};
const enhancers = [];
const middlewares = [
thunk,
routerMiddleware(history),
];
// 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);
}
let composedEnhancers: any;
if (process.env.NODE_ENV === 'development') {
const excludeLogger = (getState: GetState, action: Action): boolean => {
//'@@router/LOCATION_CHANGE'
const excluded: Array<?string> = ['LOG_TO_EXCLUDE', 'log__add', undefined];
const pass: Array<?string> = excluded.filter(act => action.type === act);
return pass.length === 0;
};
const logger = createLogger({
level: 'info',
predicate: excludeLogger,
collapsed: true,
});
const devToolsExtension: ?Function = window.devToolsExtension;
if (typeof devToolsExtension === 'function') {
enhancers.push(devToolsExtension());
}
composedEnhancers = compose(
applyMiddleware(logger, ...middlewares, ...services),
...enhancers,
);
} else {
composedEnhancers = compose(
applyMiddleware(...middlewares, ...services),
...enhancers,
);
}
export default createStore(
reducers,
initialState,
composedEnhancers,
);
// 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
// }