1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-30 20:28:09 +00:00
trezor-wallet/src/services/LocalStorageService.js

86 lines
2.5 KiB
JavaScript
Raw Normal View History

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';
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 => {
// pass action
2018-02-20 09:30:36 +00:00
next(action);
switch (action.type) {
case WALLET.HIDE_BETA_DISCLAIMER:
api.dispatch(LocalStorageActions.hideBetaDisclaimer());
break;
case WALLET.SET_LANGUAGE:
api.dispatch(LocalStorageActions.setLanguage());
break;
case WALLET.SET_HIDE_BALANCE:
api.dispatch(LocalStorageActions.setHideBalance());
break;
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:
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:
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:
case ACCOUNT.UPDATE:
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:
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:
case CONNECT.FORGET_SILENT:
api.dispatch(LocalStorageActions.save());
api.dispatch(LocalStorageActions.removeImportedAccounts(action.device));
break;
case CONNECT.RECEIVE_WALLET_TYPE:
2018-07-30 10:52:13 +00:00
case DEVICE.CHANGED:
case DEVICE.DISCONNECT:
case CONNECT.AUTH_DEVICE:
api.dispatch(LocalStorageActions.save());
2018-07-30 10:52:13 +00:00
break;
2018-02-20 09:30:36 +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:
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;