Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// 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 (
<RequireHealthOverlay require='node'>
<div>
<AccountHeader
address={address}
copyAddress
i18n={i18n}
name={name}
packageNS={packageNS}
type={type}
left={
<Link to='/accounts' className='icon -back'>
{i18n.t(`${packageNS}:navigation.back`)}
</Link>
}
/>
<br />
<Card className='-space-around'>
{type === 'signer'
? this.renderSignerAccount()
: this.renderParityAccount()}
</Card>
</div>
</RequireHealthOverlay>
);
}
renderParityAccount () {
const { history } = this.props;
const { isLoading, message, password } = this.state;
return (
<form onSubmit={this.deleteParityAccount}>
<div className='text'>
<p>{i18n.t(`${packageNS}:account.delete.warning_parity_account`)}</p>
</div>
<br />
<div className='text'>
<p>
{i18n.t(`${packageNS}:account.delete.label_msg_password_unlock`)}
</p>
</div>
<FetherForm.Field
label={i18n.t(`${packageNS}:account.delete.label_password_unlock`)}
onChange={this.handlePasswordChange}
autoFocus
required
type='password'
value={password}
/>
<p className='error'> {message} </p>
<nav className='form-nav -space-around'>
<button
className='button -back'
onClick={history.goBack}
type='button'
>
{i18n.t(`${packageNS}:navigation.back`)}
</button>
<button
autoFocus
className='button'
disabled={!password || isLoading}
>
{i18n.t(`${packageNS}:account.delete.button_confirm`)}
</button>
</nav>
</form>
);
}
renderSignerAccount () {
const { history } = this.props;
return (
<React.Fragment>
<div className='text'>
<p>{i18n.t(`${packageNS}:account.delete.warning_signer_account`)}</p>
</div>
<br />
<nav className='form-nav -space-around'>
<button
className='button -back'
onClick={history.goBack}
type='button'
>
{i18n.t(`${packageNS}:navigation.back`)}
</button>
<button
autoFocus
className='button'
onClick={this.deleteSignerAccount}
>
{i18n.t(`${packageNS}:account.delete.button_confirm`)}
</button>
</nav>
</React.Fragment>
);
}
}
export default DeleteAccount;