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 debounce from 'lodash/debounce';
import { inject, observer } from 'mobx-react';
@inject('createAccountStore')
@observer
class AccountRewritePhrase extends Component {
handleChange = ({ target: { value } }) => {
const {
Axel Chalon
committed
createAccountStore: { isImport, setPhrase }
} = this.props;
this.setState({ value });
// If we're importing, we show the current address generated by the current
// recovery phrase
Axel Chalon
committed
setPhrase(null); // Don't wait for debounce to disable button
const {
history,
location: { pathname }
} = this.props;
const currentStep = pathname.slice(-1);
history.push(`/accounts/new/${+currentStep + 1}`);
};
const {
createAccountStore: { setPhrase }
} = this.props;
Axel Chalon
committed
return setPhrase(value);
createAccountStore: { address, isImport, name },
history,
location: { pathname }
const currentStep = pathname.slice(-1);
Axel Chalon
committed
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
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]}
Axel Chalon
committed
createAccountStore: { isImport, phrase, address }
Axel Chalon
committed
const { 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'
Axel Chalon
committed
disabled={!address}
export default AccountRewritePhrase;