1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-15 12:59:09 +00:00
trezor-wallet/src/services/LogService.js

57 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-05-05 11:52:03 +00:00
/* @flow */
2018-08-14 13:11:52 +00:00
import * as LogActions from 'actions/LogActions';
2018-05-22 18:06:05 +00:00
import { TRANSPORT, DEVICE } from 'trezor-connect';
2018-10-09 13:36:55 +00:00
import * as DISCOVERY from 'actions/constants/discovery';
2018-05-05 11:52:03 +00:00
2019-03-04 12:33:02 +00:00
import type { Middleware, MiddlewareAPI, MiddlewareDispatch, Action } from 'flowtype';
2018-05-05 11:52:03 +00:00
2018-10-09 13:36:55 +00:00
const actions: Array<string> = [
2018-05-22 18:06:05 +00:00
TRANSPORT.START,
DEVICE.CONNECT,
2018-07-30 10:52:13 +00:00
DEVICE.DISCONNECT,
2018-10-09 13:36:55 +00:00
DISCOVERY.START,
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
*/
2019-03-04 12:33:02 +00:00
const LogService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispatch) => (
action: Action
): Action => {
2018-05-05 11:52:03 +00:00
next(action);
2018-10-09 13:36:55 +00:00
if (actions.indexOf(action.type) < 0) return action;
switch (action.type) {
case TRANSPORT.START:
2019-03-04 12:33:02 +00:00
api.dispatch(
LogActions.add('Transport', {
type: action.payload.type,
version: action.payload.version,
})
);
2018-10-09 13:36:55 +00:00
break;
case DEVICE.CONNECT:
api.dispatch(LogActions.add('Device connected', action.device));
break;
case DEVICE.DISCONNECT:
api.dispatch(LogActions.add('Device disconnected', action.device));
break;
case DISCOVERY.START:
api.dispatch(LogActions.add('Discovery started', action));
break;
2019-03-04 12:33:02 +00:00
default:
break;
2018-05-05 11:52:03 +00:00
}
2018-10-09 13:36:55 +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;
};
2019-03-04 12:33:02 +00:00
export default LogService;