mirror of
https://github.com/trezor/trezor-wallet
synced 2025-03-20 18:16:10 +00:00
changed method definitions to ThunkAction, remove all accounts associated to deviceID
This commit is contained in:
parent
17f63b6d9a
commit
de7aafa5c3
@ -102,7 +102,7 @@ export const importAddress = (
|
||||
type: ACCOUNT.CREATE,
|
||||
payload,
|
||||
});
|
||||
LocalStorageActions.setImportedAccount(payload);
|
||||
dispatch(LocalStorageActions.setImportedAccount(payload));
|
||||
dispatch({
|
||||
type: NOTIFICATION.ADD,
|
||||
payload: {
|
||||
|
@ -385,7 +385,7 @@ export const addAccount = (): ThunkAction => (dispatch: Dispatch, getState: GetS
|
||||
|
||||
export const addImportedAccounts = (): ThunkAction => (dispatch: Dispatch): void => {
|
||||
// get imported accounts from local storage
|
||||
const importedAccounts = LocalStorageActions.getImportedAccounts();
|
||||
const importedAccounts = dispatch(LocalStorageActions.getImportedAccounts());
|
||||
if (importedAccounts) {
|
||||
// create each account
|
||||
importedAccounts.forEach(account => {
|
||||
|
@ -323,8 +323,8 @@ export const setLocalCurrency = (): ThunkAction => (
|
||||
storageUtils.set(TYPE, KEY_LOCAL_CURRENCY, JSON.stringify(localCurrency));
|
||||
};
|
||||
|
||||
export const setImportedAccount = (account: Account): void => {
|
||||
const prevImportedAccounts: ?Array<Account> = getImportedAccounts();
|
||||
export const setImportedAccount = (account: Account): ThunkAction => (dispatch: Dispatch): void => {
|
||||
const prevImportedAccounts: ?Array<Account> = dispatch(getImportedAccounts());
|
||||
let importedAccounts = [account];
|
||||
if (prevImportedAccounts) {
|
||||
importedAccounts = importedAccounts.concat(prevImportedAccounts);
|
||||
@ -332,7 +332,7 @@ export const setImportedAccount = (account: Account): void => {
|
||||
storageUtils.set(TYPE, KEY_IMPORTED_ACCOUNTS, JSON.stringify(importedAccounts));
|
||||
};
|
||||
|
||||
export const getImportedAccounts = (): ?Array<Account> => {
|
||||
export const getImportedAccounts = (): ThunkAction => (): ?Array<Account> => {
|
||||
const importedAccounts: ?string = storageUtils.get(TYPE, KEY_IMPORTED_ACCOUNTS);
|
||||
if (importedAccounts) {
|
||||
return JSON.parse(importedAccounts);
|
||||
@ -340,15 +340,18 @@ export const getImportedAccounts = (): ?Array<Account> => {
|
||||
return importedAccounts;
|
||||
};
|
||||
|
||||
export const removeImportedAccounts = (device: TrezorDevice): void => {
|
||||
const importedAccounts: ?Array<Account> = getImportedAccounts();
|
||||
export const removeImportedAccounts = (device: TrezorDevice): ThunkAction => (
|
||||
dispatch: Dispatch
|
||||
): void => {
|
||||
const importedAccounts: ?Array<Account> = dispatch(getImportedAccounts());
|
||||
if (!importedAccounts) return;
|
||||
|
||||
const deviceId = device.features ? device.features.device_id : null;
|
||||
const filteredImportedAccounts = importedAccounts.filter(
|
||||
account => account.deviceState !== device.state
|
||||
account => account.deviceID !== deviceId
|
||||
);
|
||||
storageUtils.remove(TYPE, KEY_IMPORTED_ACCOUNTS);
|
||||
filteredImportedAccounts.forEach(account => {
|
||||
setImportedAccount(account);
|
||||
dispatch(setImportedAccount(account));
|
||||
});
|
||||
};
|
||||
|
@ -59,7 +59,7 @@ const LocalStorageService: Middleware = (api: MiddlewareAPI) => (next: Middlewar
|
||||
case CONNECT.FORGET_SINGLE:
|
||||
case CONNECT.FORGET_SILENT:
|
||||
api.dispatch(LocalStorageActions.save());
|
||||
LocalStorageActions.removeImportedAccounts(action.device);
|
||||
api.dispatch(LocalStorageActions.removeImportedAccounts(action.device));
|
||||
break;
|
||||
|
||||
case CONNECT.RECEIVE_WALLET_TYPE:
|
||||
|
Loading…
Reference in New Issue
Block a user