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

41 lines
812 B
JavaScript
Raw Normal View History

2018-03-08 16:10:53 +00:00
/* @flow */
2018-07-30 10:52:13 +00:00
2018-08-14 13:18:16 +00:00
import * as LOG from 'actions/constants/log';
2018-04-16 21:19:50 +00:00
2018-07-30 10:52:13 +00:00
import type {
Action, ThunkAction, GetState, Dispatch,
2018-08-14 12:56:47 +00:00
} from 'flowtype';
2018-08-14 13:18:16 +00:00
import type { LogEntry } from 'reducers/LogReducer';
2018-04-16 21:19:50 +00:00
export type LogAction = {
type: typeof LOG.OPEN,
} | {
type: typeof LOG.CLOSE,
2018-05-05 11:52:03 +00:00
} | {
type: typeof LOG.ADD,
payload: LogEntry
2018-04-16 21:19:50 +00:00
};
2018-07-30 10:52:13 +00:00
export const toggle = (): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
if (!getState().log.opened) {
window.scrollTo(0, 0);
2018-03-08 16:10:53 +00:00
2018-07-30 10:52:13 +00:00
dispatch({
type: LOG.OPEN,
});
} else {
dispatch({
type: LOG.CLOSE,
});
2018-03-08 16:10:53 +00:00
}
2018-07-30 10:52:13 +00:00
};
2018-05-05 11:52:03 +00:00
2018-07-30 10:52:13 +00:00
export const add = (type: string, message: any): Action => ({
type: LOG.ADD,
payload: {
time: new Date().getTime(),
type,
message,
},
});