From 0cfac808b88f6698d845b225d56d853dc758ab95 Mon Sep 17 00:00:00 2001 From: Hanwen Cheng Date: Wed, 28 Aug 2019 11:50:04 +0200 Subject: [PATCH] fix: delete account --- src/stores/AccountsStore.js | 14 ++++++-------- src/util/account.js | 5 ++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/stores/AccountsStore.js b/src/stores/AccountsStore.js index 3f0f2d6ef0..e70abdb728 100644 --- a/src/stores/AccountsStore.js +++ b/src/stores/AccountsStore.js @@ -19,13 +19,12 @@ import { Container } from 'unstated'; import { accountId, empty } from '../util/account'; -import { loadAccounts, saveAccount } from '../util/db'; +import { loadAccounts, saveAccount, deleteAccount as deleteDbAccount} from '../util/db'; import {parseSURI} from '../util/suri' import { decryptData, encryptData } from '../util/native'; export type Account = { address: string, - archived: boolean, createdAt: number, derivationPassword: string, derivationPath: string, // doesn't contain the ///password @@ -116,7 +115,7 @@ export default class AccountsStore extends Container { if (pin && account.seed) { account.encryptedSeed = await encryptData(account.seed, pin); } - + const accountToSave = this.deleteSensitiveData(account); accountToSave.updatedAt = new Date().getTime(); @@ -130,10 +129,9 @@ export default class AccountsStore extends Container { async deleteAccount(account) { const { accounts } = this.state; - account.archived = true; - accounts.set(accountId(account), account); + accounts.delete(accountId(account)); this.setState({ accounts }); - await this.save(account); + await deleteDbAccount(account); } async unlockAccount(account, pin) { @@ -163,7 +161,7 @@ export default class AccountsStore extends Container { delete account.seedPhrase; delete account.derivationPassword; delete account.derivationPath; - + return account } @@ -203,7 +201,7 @@ export default class AccountsStore extends Container { getAccounts() { return Array.from(this.state.accounts.values()) - .filter(a => !a.archived && a.networkKey) + .filter(a => !!a.networkKey) .sort((a, b) => { if (a.name < b.name) { return -1; diff --git a/src/util/account.js b/src/util/account.js index 547a2b8d26..bf69968b2b 100644 --- a/src/util/account.js +++ b/src/util/account.js @@ -13,7 +13,7 @@ export function accountId({ const { ethereumChainId='', protocol, genesisHash } = NETWORK_LIST[networkKey]; - if (protocol === NetworkProtocols.SUBSTRATE) { + if (protocol === NetworkProtocols.SUBSTRATE) { return `${protocol}:${address}:${genesisHash}`; } else { return `${protocol}:0x${address.toLowerCase()}@${ethereumChainId}`; @@ -23,9 +23,8 @@ export function accountId({ export function empty(account = {}) { return { address: '', - archived: false, createdAt: new Date().getTime(), - derivationPassword: '', + derivationPassword: '', derivationPath:'', encryptedSeed: null, name: '',