1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-17 05:49:10 +00:00
trezor-wallet/src/services/LogService.js

54 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-05-05 11:52:03 +00:00
/* @flow */
2018-07-30 10:52:13 +00:00
2018-05-05 11:52:03 +00:00
2018-08-14 13:11:52 +00:00
import * as LogActions from 'actions/LogActions';
import * as STORAGE from 'actions/constants/localStorage';
import * as SEND from 'actions/constants/send';
import { OPEN, CLOSE, ADD } from 'actions/constants/log';
2018-05-22 18:06:05 +00:00
import { TRANSPORT, DEVICE } from 'trezor-connect';
2018-05-05 11:52:03 +00:00
2018-07-30 10:52:13 +00:00
import type {
2018-05-05 11:52:03 +00:00
Middleware,
MiddlewareAPI,
MiddlewareDispatch,
State,
Dispatch,
Action,
AsyncAction,
2018-07-30 10:52:13 +00:00
GetState,
2018-08-14 12:56:47 +00:00
} from 'flowtype';
2018-05-05 11:52:03 +00:00
const exclude: Array<string> = [
ADD, OPEN, CLOSE,
STORAGE.READY,
2018-05-09 15:47:34 +00:00
SEND.TX_COMPLETE,
2018-07-30 10:52:13 +00:00
'web3__create',
2018-05-05 11:52:03 +00:00
];
2018-05-22 18:06:05 +00:00
const include: Array<string> = [
TRANSPORT.START,
DEVICE.CONNECT,
2018-07-30 10:52:13 +00:00
DEVICE.DISCONNECT,
2018-05-22 18:06:05 +00:00
];
2018-05-05 11:52:03 +00:00
/**
2018-07-30 10:52:13 +00:00
* Middleware
2018-05-05 11:52:03 +00:00
*/
const LogService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispatch) => (action: Action): Action => {
next(action);
2018-05-22 18:06:05 +00:00
// if (exclude.indexOf(action.type) < 0) {
if (include.indexOf(action.type) >= 0) {
2018-05-05 11:52:03 +00:00
// api.dispatch(LogActions.add(action.type, JSON.stringify( action )));
2018-07-30 10:52:13 +00:00
2018-05-22 18:06:05 +00:00
if (action.type === TRANSPORT.START) {
api.dispatch(LogActions.add('Transport', action.payload));
} else if (action.type === DEVICE.CONNECT) {
api.dispatch(LogActions.add(action.type, action));
}
2018-05-05 11:52:03 +00:00
}
return action;
};
export default LogService;