// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
// SPDX-License-Identifier: BSD-3-Clause
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
@withAccount
@inject('parityStore')
@observer
class DeleteAccount extends Component {
state = {
isLoading: false,
password: '',
message: ''
};
deleteParityAccount = event => {
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 {
account: { address: currentAddress },
history
} = this.props;
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 } }) => {
this.setState({ password: value });
};
render () {
const {
account: { name, address, type }
} = this.props;
return (
{i18n.t(`${packageNS}:account.delete.warning_signer_account`)}