From 9bc39357ed4183fca7ba9e0a8fbe776ede8b110a Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Wed, 5 Jun 2019 12:35:46 +0200 Subject: [PATCH 1/5] Add menu --- packages/fether-react/src/Tokens/Tokens.js | 4 ++++ packages/fether-react/src/i18n/locales/de.json | 3 ++- packages/fether-react/src/i18n/locales/en.json | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/fether-react/src/Tokens/Tokens.js b/packages/fether-react/src/Tokens/Tokens.js index c4c0cee38..bc6964a8e 100644 --- a/packages/fether-react/src/Tokens/Tokens.js +++ b/packages/fether-react/src/Tokens/Tokens.js @@ -50,6 +50,10 @@ class Tokens extends PureComponent { { name: i18n.t(`${packageNS}:tokens.tokens.menu_items.add_tokens`), onClick: () => history.push(`/whitelist/${address}`) + }, + { + name: i18n.t(`${packageNS}:tokens.tokens.menu_items.delete_account`), + onClick: () => history.push(`/delete/${address}`) } ]; diff --git a/packages/fether-react/src/i18n/locales/de.json b/packages/fether-react/src/i18n/locales/de.json index fd4aa3e22..eed75340a 100644 --- a/packages/fether-react/src/i18n/locales/de.json +++ b/packages/fether-react/src/i18n/locales/de.json @@ -198,7 +198,8 @@ "tokens": { "menu_items": { "backup_account": "Sicherungskonto", - "add_tokens": "Token hinzufügen" + "add_tokens": "Token hinzufügen", + "delete_account": "Konto löschen" } } }, diff --git a/packages/fether-react/src/i18n/locales/en.json b/packages/fether-react/src/i18n/locales/en.json index 91dd2f531..677d70811 100644 --- a/packages/fether-react/src/i18n/locales/en.json +++ b/packages/fether-react/src/i18n/locales/en.json @@ -198,7 +198,8 @@ "tokens": { "menu_items": { "backup_account": "Backup Account", - "add_tokens": "Add Tokens" + "add_tokens": "Add Tokens", + "delete_account": "Delete Account" } } }, From 7841d5d07a0bb3bf2ab2aa6a27c5b2f317c20788 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Wed, 5 Jun 2019 13:29:13 +0200 Subject: [PATCH 2/5] Add correct screens --- packages/fether-react/src/App/App.js | 5 + .../src/DeleteAccount/DeleteAccount.js | 174 ++++++++++++++++++ .../fether-react/src/DeleteAccount/index.js | 8 + .../fether-react/src/i18n/locales/en.json | 7 + 4 files changed, 194 insertions(+) create mode 100644 packages/fether-react/src/DeleteAccount/DeleteAccount.js create mode 100644 packages/fether-react/src/DeleteAccount/index.js diff --git a/packages/fether-react/src/App/App.js b/packages/fether-react/src/App/App.js index 5eaac3ed1..b2db4ac93 100644 --- a/packages/fether-react/src/App/App.js +++ b/packages/fether-react/src/App/App.js @@ -19,6 +19,7 @@ import { version } from '../../package.json'; import i18n, { packageNS } from '../i18n'; import Accounts from '../Accounts'; import BackupAccount from '../BackupAccount'; +import DeleteAccount from '../DeleteAccount'; import Onboarding from '../Onboarding'; import * as postMessage from '../utils/postMessage'; import RequireParityVersion from '../RequireParityVersion'; @@ -178,6 +179,10 @@ class App extends Component { path='/backup/:accountAddress' component={BackupAccount} /> + { + const { + account: { address }, + parityStore: { api }, + history + } = this.props; + const { password } = this.state; + + event && event.preventDefault(); + + this.setState({ isLoading: true }); + + api.parity + .killAccount(address, password) + .then(() => { + history.push(`/accounts`); + }) + .catch(err => { + this.setState({ + message: err.text + ' Please check your password and try again.' + }); + this.setState({ isLoading: false }); + }); + }; + + deleteSignerAccount = () => { + const { history } = this.props; + + history.push(`/accounts`); + }; + + handlePasswordChange = ({ target: { value } }) => { + this.setState({ password: value }); + }; + + render () { + const { + account: { name, address, type } + } = this.props; + + return ( + +
+ + {i18n.t(`${packageNS}:navigation.back`)} + + } + /> +
+ + {type === 'signer' + ? this.renderSignerAccount() + : this.renderParityAccount()} + +
+
+ ); + } + + renderParityAccount () { + const { history } = this.props; + const { isLoading, message, password } = this.state; + + return ( +
+
+

{i18n.t(`${packageNS}:account.delete.warning_parity_account`)}

+
+
+ +
+

+ {i18n.t(`${packageNS}:account.delete.label_msg_password_unlock`)} +

+
+ + + +

{message}

+ + + + ); + } + + renderSignerAccount () { + const { history } = this.props; + const { message } = this.state; + + return ( + +
+

{i18n.t(`${packageNS}:account.delete.warning_signer_account`)}

+
+ +

{message}

+ + +
+ ); + } +} + +export default DeleteAccount; diff --git a/packages/fether-react/src/DeleteAccount/index.js b/packages/fether-react/src/DeleteAccount/index.js new file mode 100644 index 000000000..4274cbfc9 --- /dev/null +++ b/packages/fether-react/src/DeleteAccount/index.js @@ -0,0 +1,8 @@ +// Copyright 2015-2019 Parity Technologies (UK) Ltd. +// This file is part of Parity. +// +// SPDX-License-Identifier: BSD-3-Clause + +import DeleteAccount from './DeleteAccount'; + +export default DeleteAccount; diff --git a/packages/fether-react/src/i18n/locales/en.json b/packages/fether-react/src/i18n/locales/en.json index 677d70811..ab30d390e 100644 --- a/packages/fether-react/src/i18n/locales/en.json +++ b/packages/fether-react/src/i18n/locales/en.json @@ -20,6 +20,13 @@ "label_password_unlock": "Password", "button_confirm": "Confirm backup" }, + "delete": { + "label_msg_password_unlock": "Unlock your account to delete it:", + "label_password_unlock": "Password", + "button_confirm": "Confirm delete", + "warning_parity_account": "Please note that if you haven't made any backup (via JSON or via recovery phrase), your account and its funds will be definitely lost!", + "warning_signer_account": "The account will be removed from Fether, but you can add it back anytime by importing it again from Parity Signer." + }, "import": { "error_msg_existing_address": "Account {{address}} already listed", "signer": { From d44a38d1da5349c0e4e17b2b5758f0821875f730 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Wed, 5 Jun 2019 13:39:28 +0200 Subject: [PATCH 3/5] Remove from localStorage --- .../src/DeleteAccount/DeleteAccount.js | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/fether-react/src/DeleteAccount/DeleteAccount.js b/packages/fether-react/src/DeleteAccount/DeleteAccount.js index 1be4ca75c..b1d6dd56c 100644 --- a/packages/fether-react/src/DeleteAccount/DeleteAccount.js +++ b/packages/fether-react/src/DeleteAccount/DeleteAccount.js @@ -5,11 +5,14 @@ import React, { Component } from 'react'; import { AccountHeader, Card, Form as FetherForm } from 'fether-ui'; +import localForage from 'localforage'; import { observer, inject } from 'mobx-react'; import { Link, withRouter } from 'react-router-dom'; import i18n, { packageNS } from '../i18n'; +import localForage$ from '../utils/localForage'; import RequireHealthOverlay from '../RequireHealthOverlay'; +import { SIGNER_ACCOUNTS_LS_KEY } from '../stores/createAccountStore'; import withAccount from '../utils/withAccount'; @withRouter @@ -49,9 +52,20 @@ class DeleteAccount extends Component { }; deleteSignerAccount = () => { - const { history } = this.props; + const { + account: { address: currentAddress }, + history + } = this.props; - history.push(`/accounts`); + localForage$(SIGNER_ACCOUNTS_LS_KEY).subscribe(async accounts => { + const removed = accounts.filter( + ({ address }) => address !== currentAddress + ); + + await localForage.setItem(SIGNER_ACCOUNTS_LS_KEY, removed); + + history.push(`/accounts`); + }); }; handlePasswordChange = ({ target: { value } }) => { @@ -140,7 +154,6 @@ class DeleteAccount extends Component { renderSignerAccount () { const { history } = this.props; - const { message } = this.state; return ( @@ -148,7 +161,7 @@ class DeleteAccount extends Component {

{i18n.t(`${packageNS}:account.delete.warning_signer_account`)}

-

{message}

+