mirror of https://github.com/trezor/trezor-wallet
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.
52 lines
1.6 KiB
52 lines
1.6 KiB
6 years ago
|
/* @flow */
|
||
6 years ago
|
|
||
6 years ago
|
|
||
6 years ago
|
import * as NOTIFICATION from 'actions/constants/notification';
|
||
6 years ago
|
|
||
6 years ago
|
import type {
|
||
|
Action, AsyncAction, GetState, Dispatch, RouterLocationState,
|
||
6 years ago
|
} from 'flowtype';
|
||
6 years ago
|
import type { CallbackAction } from 'reducers/NotificationReducer';
|
||
6 years ago
|
|
||
|
export type NotificationAction = {
|
||
|
type: typeof NOTIFICATION.ADD,
|
||
|
payload: {
|
||
|
+type: string,
|
||
|
+title: string,
|
||
|
+message?: string,
|
||
|
+cancelable: boolean,
|
||
6 years ago
|
actions?: Array<CallbackAction>
|
||
6 years ago
|
}
|
||
|
} | {
|
||
|
type: typeof NOTIFICATION.CLOSE,
|
||
|
payload?: {
|
||
|
id?: string;
|
||
|
devicePath?: string
|
||
|
}
|
||
|
}
|
||
|
|
||
6 years ago
|
export const close = (payload: any = {}): Action => ({
|
||
|
type: NOTIFICATION.CLOSE,
|
||
|
payload,
|
||
|
});
|
||
6 years ago
|
|
||
6 years ago
|
|
||
|
// called from RouterService
|
||
6 years ago
|
export const clear = (currentParams: RouterLocationState, requestedParams: RouterLocationState): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||
|
// if route has been changed from device view into something else (like other device, settings...)
|
||
|
// try to remove all Notifications which are linked to previous device (they are not cancelable by user)
|
||
|
if (currentParams.device !== requestedParams.device || currentParams.deviceInstance !== requestedParams.deviceInstance) {
|
||
|
const entries = getState().notifications.filter(entry => typeof entry.devicePath === 'string');
|
||
|
entries.forEach((entry) => {
|
||
|
if (typeof entry.devicePath === 'string') {
|
||
|
dispatch({
|
||
|
type: NOTIFICATION.CLOSE,
|
||
|
payload: {
|
||
|
devicePath: entry.devicePath,
|
||
|
},
|
||
|
});
|
||
|
}
|
||
|
});
|
||
6 years ago
|
}
|
||
6 years ago
|
};
|