2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2016-11-22 16:19:36 +01:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import React, { Component, PropTypes } from 'react';
|
2017-01-27 14:42:06 +01:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2016-11-22 16:19:36 +01:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
|
2017-05-09 12:01:44 +02:00
|
|
|
import { newError } from '@parity/shared/redux/actions';
|
2017-05-12 12:06:16 +02:00
|
|
|
import { ConfirmDialog, IdentityIcon, IdentityName, Input } from '@parity/ui';
|
2016-11-22 16:19:36 +01:00
|
|
|
|
|
|
|
import styles from './deleteAccount.css';
|
|
|
|
|
|
|
|
class DeleteAccount extends Component {
|
|
|
|
static contextTypes = {
|
|
|
|
api: PropTypes.object.isRequired,
|
|
|
|
router: PropTypes.object
|
|
|
|
}
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
account: PropTypes.object.isRequired,
|
2016-11-23 22:17:36 +01:00
|
|
|
onClose: PropTypes.func.isRequired,
|
|
|
|
newError: PropTypes.func.isRequired
|
2016-11-22 16:19:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
state = {
|
2017-03-03 19:50:54 +01:00
|
|
|
isBusy: false,
|
2016-11-22 16:19:36 +01:00
|
|
|
password: ''
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { account } = this.props;
|
2017-03-03 19:50:54 +01:00
|
|
|
const { isBusy, password } = this.state;
|
2016-11-22 16:19:36 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<ConfirmDialog
|
2017-03-03 19:50:54 +01:00
|
|
|
busy={ isBusy }
|
2016-11-22 16:19:36 +01:00
|
|
|
className={ styles.body }
|
2017-01-18 13:05:01 +01:00
|
|
|
onConfirm={ this.onDeleteConfirmed }
|
2017-01-27 14:42:06 +01:00
|
|
|
onDeny={ this.closeDeleteDialog }
|
2017-03-03 19:50:54 +01:00
|
|
|
open
|
2017-01-27 14:42:06 +01:00
|
|
|
title={
|
|
|
|
<FormattedMessage
|
|
|
|
id='deleteAccount.title'
|
|
|
|
defaultMessage='confirm removal'
|
|
|
|
/>
|
|
|
|
}
|
2017-01-18 13:05:01 +01:00
|
|
|
>
|
2016-11-22 16:19:36 +01:00
|
|
|
<div className={ styles.hero }>
|
2017-01-27 14:42:06 +01:00
|
|
|
<FormattedMessage
|
|
|
|
id='deleteAccount.question'
|
|
|
|
defaultMessage='Are you sure you want to permanently delete the following account?'
|
|
|
|
/>
|
2016-11-22 16:19:36 +01:00
|
|
|
</div>
|
|
|
|
<div className={ styles.info }>
|
|
|
|
<IdentityIcon
|
2017-01-18 13:05:01 +01:00
|
|
|
address={ account.address }
|
2017-01-27 14:42:06 +01:00
|
|
|
className={ styles.icon }
|
2017-01-18 13:05:01 +01:00
|
|
|
/>
|
2016-11-22 16:19:36 +01:00
|
|
|
<div className={ styles.nameinfo }>
|
|
|
|
<div className={ styles.header }>
|
2017-01-27 14:42:06 +01:00
|
|
|
<IdentityName
|
|
|
|
address={ account.address }
|
|
|
|
unknown
|
|
|
|
/>
|
2016-11-22 16:19:36 +01:00
|
|
|
</div>
|
|
|
|
<div className={ styles.address }>
|
|
|
|
{ account.address }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={ styles.description }>
|
|
|
|
{ account.meta.description }
|
|
|
|
</div>
|
|
|
|
<div className={ styles.password }>
|
|
|
|
<Input
|
2017-02-24 12:26:30 +01:00
|
|
|
autoFocus
|
2017-01-27 14:42:06 +01:00
|
|
|
hint={
|
|
|
|
<FormattedMessage
|
|
|
|
id='deleteAccount.password.hint'
|
|
|
|
defaultMessage='provide the account password to confirm the account deletion'
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='deleteAccount.password.label'
|
|
|
|
defaultMessage='account password'
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
onChange={ this.onChangePassword }
|
2017-02-24 12:26:30 +01:00
|
|
|
onDefaultAction={ this.onDeleteConfirmed }
|
2016-11-22 16:19:36 +01:00
|
|
|
type='password'
|
|
|
|
value={ password }
|
2017-01-18 13:05:01 +01:00
|
|
|
/>
|
2016-11-22 16:19:36 +01:00
|
|
|
</div>
|
|
|
|
</ConfirmDialog>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
onChangePassword = (event, password) => {
|
|
|
|
this.setState({ password });
|
|
|
|
}
|
|
|
|
|
|
|
|
onDeleteConfirmed = () => {
|
|
|
|
const { api, router } = this.context;
|
|
|
|
const { account, newError } = this.props;
|
|
|
|
const { password } = this.state;
|
|
|
|
|
2017-03-03 19:50:54 +01:00
|
|
|
this.setState({ isBusy: true });
|
|
|
|
|
2017-01-27 14:42:06 +01:00
|
|
|
return api.parity
|
2016-11-22 16:19:36 +01:00
|
|
|
.killAccount(account.address, password)
|
|
|
|
.then((result) => {
|
2017-03-03 19:50:54 +01:00
|
|
|
this.setState({ isBusy: true });
|
|
|
|
|
2016-11-22 16:19:36 +01:00
|
|
|
if (result === true) {
|
|
|
|
router.push('/accounts');
|
2016-11-23 22:17:36 +01:00
|
|
|
this.closeDeleteDialog();
|
2016-11-22 16:19:36 +01:00
|
|
|
} else {
|
|
|
|
newError(new Error('Deletion failed.'));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
2017-03-03 19:50:54 +01:00
|
|
|
this.setState({ isBusy: false });
|
2016-11-22 16:19:36 +01:00
|
|
|
console.error('onDeleteConfirmed', error);
|
|
|
|
newError(new Error(`Deletion failed: ${error.message}`));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
closeDeleteDialog = () => {
|
|
|
|
this.props.onClose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps (dispatch) {
|
|
|
|
return bindActionCreators({ newError }, dispatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(
|
2017-01-27 14:42:06 +01:00
|
|
|
null,
|
2016-11-22 16:19:36 +01:00
|
|
|
mapDispatchToProps
|
|
|
|
)(DeleteAccount);
|