Skip to content

Commit

Permalink
fix: delete account
Browse files Browse the repository at this point in the history
  • Loading branch information
hanwencheng committed Aug 30, 2019
1 parent d4b3f3a commit 0cfac80
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
14 changes: 6 additions & 8 deletions src/stores/AccountsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -163,7 +161,7 @@ export default class AccountsStore extends Container {
delete account.seedPhrase;
delete account.derivationPassword;
delete account.derivationPath;

return account
}

Expand Down Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/util/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand All @@ -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: '',
Expand Down

0 comments on commit 0cfac80

Please sign in to comment.