You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trezor-wallet/src/services/LogService.js

62 lines
1.7 KiB

/* @flow */
import * as LogActions from 'actions/LogActions';
import { TRANSPORT, DEVICE } from 'trezor-connect';
import * as DISCOVERY from 'actions/constants/discovery';
import * as ACCOUNT from 'actions/constants/account';
import type { Middleware, MiddlewareAPI, MiddlewareDispatch, Action } from 'flowtype';
const actions: Array<string> = [
TRANSPORT.START,
DEVICE.CONNECT,
DEVICE.DISCONNECT,
DISCOVERY.START,
ACCOUNT.CREATE,
];
/**
* Middleware
*/
const LogService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispatch) => (
action: Action
): Action => {
next(action);
if (actions.indexOf(action.type) < 0) return action;
switch (action.type) {
case TRANSPORT.START:
api.dispatch(
LogActions.add('Transport', {
type: action.payload.type,
version: action.payload.version,
})
);
break;
case DEVICE.CONNECT:
api.dispatch(LogActions.add('Device connected', action.payload));
break;
case DEVICE.DISCONNECT:
api.dispatch(LogActions.add('Device disconnected', action.payload));
break;
case DISCOVERY.START:
api.dispatch(LogActions.add('Discovery started', action));
break;
case ACCOUNT.CREATE:
api.dispatch(LogActions.add('Account created', action));
break;
default:
break;
}
// 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));
// }
return action;
};
export default LogService;