mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-27 10:48:22 +00:00
remove imported accounts when forgetting device
This commit is contained in:
parent
6d76c20886
commit
17f63b6d9a
@ -102,7 +102,7 @@ export const importAddress = (
|
||||
type: ACCOUNT.CREATE,
|
||||
payload,
|
||||
});
|
||||
dispatch(LocalStorageActions.setImportedAccount(payload));
|
||||
LocalStorageActions.setImportedAccount(payload);
|
||||
dispatch({
|
||||
type: NOTIFICATION.ADD,
|
||||
payload: {
|
||||
|
@ -323,8 +323,8 @@ export const setLocalCurrency = (): ThunkAction => (
|
||||
storageUtils.set(TYPE, KEY_LOCAL_CURRENCY, JSON.stringify(localCurrency));
|
||||
};
|
||||
|
||||
export const setImportedAccount = (account: Account): ThunkAction => (): void => {
|
||||
const prevImportedAccounts: ?string = JSON.parse(storageUtils.get(TYPE, KEY_IMPORTED_ACCOUNTS));
|
||||
export const setImportedAccount = (account: Account): void => {
|
||||
const prevImportedAccounts: ?Array<Account> = getImportedAccounts();
|
||||
let importedAccounts = [account];
|
||||
if (prevImportedAccounts) {
|
||||
importedAccounts = importedAccounts.concat(prevImportedAccounts);
|
||||
@ -332,10 +332,23 @@ export const setImportedAccount = (account: Account): ThunkAction => (): void =>
|
||||
storageUtils.set(TYPE, KEY_IMPORTED_ACCOUNTS, JSON.stringify(importedAccounts));
|
||||
};
|
||||
|
||||
export const getImportedAccounts = (): Array<Account> => {
|
||||
export const getImportedAccounts = (): ?Array<Account> => {
|
||||
const importedAccounts: ?string = storageUtils.get(TYPE, KEY_IMPORTED_ACCOUNTS);
|
||||
if (importedAccounts) {
|
||||
return JSON.parse(importedAccounts);
|
||||
}
|
||||
return importedAccounts;
|
||||
};
|
||||
|
||||
export const removeImportedAccounts = (device: TrezorDevice): void => {
|
||||
const importedAccounts: ?Array<Account> = getImportedAccounts();
|
||||
if (!importedAccounts) return;
|
||||
|
||||
const filteredImportedAccounts = importedAccounts.filter(
|
||||
account => account.deviceState !== device.state
|
||||
);
|
||||
storageUtils.remove(TYPE, KEY_IMPORTED_ACCOUNTS);
|
||||
filteredImportedAccounts.forEach(account => {
|
||||
setImportedAccount(account);
|
||||
});
|
||||
};
|
||||
|
@ -58,6 +58,10 @@ const LocalStorageService: Middleware = (api: MiddlewareAPI) => (next: Middlewar
|
||||
case CONNECT.FORGET:
|
||||
case CONNECT.FORGET_SINGLE:
|
||||
case CONNECT.FORGET_SILENT:
|
||||
api.dispatch(LocalStorageActions.save());
|
||||
LocalStorageActions.removeImportedAccounts(action.device);
|
||||
break;
|
||||
|
||||
case CONNECT.RECEIVE_WALLET_TYPE:
|
||||
case DEVICE.CHANGED:
|
||||
case DEVICE.DISCONNECT:
|
||||
|
Loading…
Reference in New Issue
Block a user