-
-
Notifications
You must be signed in to change notification settings - Fork 241
/
protocolMiddleware.ts
36 lines (29 loc) · 1.19 KB
/
protocolMiddleware.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { MiddlewareAPI } from 'redux';
import { close } from '@suite-actions/notificationActions';
import { PROTOCOL } from '@suite-actions/constants';
import type { AppState, Action, Dispatch } from '@suite-types';
import type { ToastPayload } from '@suite-reducers/notificationReducer';
// close custom protocol notification of given type
const closeNotifications = (api: MiddlewareAPI<Dispatch, AppState>, type: ToastPayload['type']) => {
api.getState()
.notifications.filter(notification => notification.type === type && !notification.closed)
.forEach(protocolNotification => api.dispatch(close(protocolNotification.id)));
};
const protocolMiddleware =
(api: MiddlewareAPI<Dispatch, AppState>) =>
(next: Dispatch) =>
(action: Action): Action => {
next(action);
switch (action.type) {
case PROTOCOL.SAVE_COIN_PROTOCOL:
closeNotifications(api, 'coin-scheme-protocol');
break;
case PROTOCOL.SAVE_AOPP_PROTOCOL:
closeNotifications(api, 'aopp-protocol');
break;
default:
break;
}
return action;
};
export default protocolMiddleware;