Unverified Commit 681bd362 authored by Hanwen Cheng's avatar Hanwen Cheng Committed by GitHub
Browse files

fix: delete account (#338)

parent d4b3f3ac
Pipeline #50586 failed with stage
in 14 seconds
......@@ -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;
......
......@@ -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: '',
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment