1
0
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:
slowbackspace 2019-04-09 14:06:15 +02:00
parent 6d76c20886
commit 17f63b6d9a
3 changed files with 21 additions and 4 deletions

View File

@ -102,7 +102,7 @@ export const importAddress = (
type: ACCOUNT.CREATE,
payload,
});
dispatch(LocalStorageActions.setImportedAccount(payload));
LocalStorageActions.setImportedAccount(payload);
dispatch({
type: NOTIFICATION.ADD,
payload: {

View File

@ -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);
});
};

View File

@ -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: