Newer
Older
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
Axel Chalon
committed
import { AccountCard, Card, Form as FetherForm } from 'fether-ui';
import { inject, observer } from 'mobx-react';
@inject('createAccountStore')
@observer
class AccountRewritePhrase extends Component {
isLoading: false,
handleChange = ({ target: { value } }) => {
this.setState({ value });
};
handleNextStep = async () => {
location: { pathname },
createAccountStore: { isImport, setPhrase }
const currentStep = pathname.slice(-1);
const { value } = this.state;
// If we're importing, derive address from recovery phrase when we submit
if (isImport) {
this.setState({ isLoading: true });
await setPhrase(value);
}
history.push(`/accounts/new/${+currentStep + 1}`);
};
createAccountStore: { address, isImport, name },
history,
location: { pathname }
const currentStep = pathname.slice(-1);
Axel Chalon
committed
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
const body = [
<div key='createAccount'>
<div className='text'>
{isImport ? (
<p>Type your Recovery phrase</p>
) : (
<p>
Type your secret phrase to confirm that you wrote it down
correctly:
</p>
)}
</div>
<FetherForm.Field
as='textarea'
label='Recovery phrase'
onChange={this.handleChange}
required
value={value}
/>
<nav className='form-nav -space-around'>
{currentStep > 1 && (
<button className='button -cancel' onClick={history.goBack}>
Back
</button>
)}
{this.renderButton()}
</nav>
</div>
];
return isImport ? (
<Card>{body}</Card>
) : (
<AccountCard
address={address}
name={address && !name ? '(no name)' : name}
Axel Chalon
committed
drawers={[body]}
createAccountStore: { isImport, phrase }
const { isLoading, value } = this.state;
// If we are creating a new account, the button just checks the phrase has
// been correctly written by the user.
if (!isImport) {
return (
<button
className='button'
Axel Chalon
committed
disabled={value !== phrase}
onClick={this.handleNextStep}
>
Next
</button>
);
// If we are importing an existing account, the button goes to the next step
<button
className='button'
disabled={!value.length || isLoading}
export default AccountRewritePhrase;