Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: delete account #338

Merged
merged 1 commit into from
Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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