2018-02-20 09:30:36 +00:00
|
|
|
/* @flow */
|
2018-07-30 10:52:13 +00:00
|
|
|
import { DEVICE } from 'trezor-connect';
|
2018-08-14 13:11:52 +00:00
|
|
|
import * as LocalStorageActions from 'actions/LocalStorageActions';
|
2018-02-20 09:30:36 +00:00
|
|
|
|
2018-08-14 13:11:52 +00:00
|
|
|
import * as CONNECT from 'actions/constants/TrezorConnect';
|
|
|
|
import * as TOKEN from 'actions/constants/token';
|
|
|
|
import * as ACCOUNT from 'actions/constants/account';
|
|
|
|
import * as DISCOVERY from 'actions/constants/discovery';
|
|
|
|
import * as PENDING from 'actions/constants/pendingTx';
|
2018-10-17 10:09:25 +00:00
|
|
|
import * as WALLET from 'actions/constants/wallet';
|
|
|
|
|
2019-03-04 12:33:02 +00:00
|
|
|
import type { Middleware, MiddlewareAPI, MiddlewareDispatch, Action } from 'flowtype';
|
2018-04-16 21:19:50 +00:00
|
|
|
|
2019-03-04 12:33:02 +00:00
|
|
|
const LocalStorageService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispatch) => (
|
|
|
|
action: Action
|
|
|
|
): Action => {
|
2018-10-17 10:09:25 +00:00
|
|
|
// pass action
|
2018-02-20 09:30:36 +00:00
|
|
|
next(action);
|
|
|
|
|
|
|
|
switch (action.type) {
|
2018-10-17 10:09:25 +00:00
|
|
|
case WALLET.HIDE_BETA_DISCLAIMER:
|
|
|
|
api.dispatch(LocalStorageActions.hideBetaDisclaimer());
|
|
|
|
break;
|
2019-02-06 17:03:19 +00:00
|
|
|
|
|
|
|
case WALLET.SET_LANGUAGE:
|
|
|
|
api.dispatch(LocalStorageActions.setLanguage());
|
|
|
|
break;
|
2019-03-11 16:45:35 +00:00
|
|
|
|
2019-03-14 22:31:19 +00:00
|
|
|
case WALLET.SET_HIDE_BALANCE:
|
|
|
|
api.dispatch(LocalStorageActions.setHideBalance());
|
|
|
|
break;
|
|
|
|
|
2019-03-11 16:45:35 +00:00
|
|
|
case WALLET.SET_LOCAL_CURRENCY:
|
|
|
|
api.dispatch(LocalStorageActions.setLocalCurrency());
|
|
|
|
break;
|
2018-02-20 09:30:36 +00:00
|
|
|
// first time saving
|
2018-07-30 10:52:13 +00:00
|
|
|
case CONNECT.REMEMBER:
|
2018-10-17 10:09:25 +00:00
|
|
|
api.dispatch(LocalStorageActions.save());
|
2018-07-30 10:52:13 +00:00
|
|
|
break;
|
2018-02-20 09:30:36 +00:00
|
|
|
|
2018-07-30 10:52:13 +00:00
|
|
|
case TOKEN.ADD:
|
|
|
|
case TOKEN.REMOVE:
|
|
|
|
case TOKEN.SET_BALANCE:
|
2018-10-17 10:09:25 +00:00
|
|
|
api.dispatch(LocalStorageActions.save());
|
2018-07-30 10:52:13 +00:00
|
|
|
break;
|
2018-02-20 09:30:36 +00:00
|
|
|
|
2018-07-30 10:52:13 +00:00
|
|
|
case ACCOUNT.CREATE:
|
2018-12-21 09:58:53 +00:00
|
|
|
case ACCOUNT.UPDATE:
|
2018-10-17 10:09:25 +00:00
|
|
|
api.dispatch(LocalStorageActions.save());
|
2018-07-30 10:52:13 +00:00
|
|
|
break;
|
2018-02-20 09:30:36 +00:00
|
|
|
|
2018-07-30 10:52:13 +00:00
|
|
|
case DISCOVERY.START:
|
|
|
|
case DISCOVERY.STOP:
|
|
|
|
case DISCOVERY.COMPLETE:
|
2018-10-17 10:09:25 +00:00
|
|
|
api.dispatch(LocalStorageActions.save());
|
2018-07-30 10:52:13 +00:00
|
|
|
break;
|
2018-02-20 09:30:36 +00:00
|
|
|
|
2018-07-30 10:52:13 +00:00
|
|
|
case CONNECT.FORGET:
|
|
|
|
case CONNECT.FORGET_SINGLE:
|
2018-10-08 09:59:10 +00:00
|
|
|
case CONNECT.FORGET_SILENT:
|
|
|
|
case CONNECT.RECEIVE_WALLET_TYPE:
|
2018-07-30 10:52:13 +00:00
|
|
|
case DEVICE.CHANGED:
|
|
|
|
case DEVICE.DISCONNECT:
|
|
|
|
case CONNECT.AUTH_DEVICE:
|
2018-10-17 10:09:25 +00:00
|
|
|
api.dispatch(LocalStorageActions.save());
|
2018-07-30 10:52:13 +00:00
|
|
|
break;
|
2018-02-20 09:30:36 +00:00
|
|
|
|
2018-12-03 20:43:42 +00:00
|
|
|
case PENDING.ADD:
|
2018-07-30 10:52:13 +00:00
|
|
|
case PENDING.TX_RESOLVED:
|
2018-09-26 16:46:49 +00:00
|
|
|
case PENDING.TX_REJECTED:
|
2018-10-17 10:09:25 +00:00
|
|
|
api.dispatch(LocalStorageActions.save());
|
2018-07-30 10:52:13 +00:00
|
|
|
break;
|
2018-09-26 16:46:49 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return action;
|
2018-02-20 09:30:36 +00:00
|
|
|
}
|
|
|
|
|
2018-04-16 21:19:50 +00:00
|
|
|
return action;
|
2018-02-20 09:30:36 +00:00
|
|
|
};
|
|
|
|
|
2019-03-04 12:33:02 +00:00
|
|
|
export default LocalStorageService;
|