Newer
Older
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
import { AccountCard, Form as FetherForm } from 'fether-ui';
import { inject, observer } from 'mobx-react';
@inject('createAccountStore')
@observer
class AccountPassword extends Component {
Axel Chalon
committed
isLoading: false,
};
handleConfirmChange = ({ target: { value } }) => {
this.setState({ confirm: value });
};
handlePasswordChange = ({ target: { value } }) => {
this.setState({ password: value });
};
const { createAccountStore, history } = this.props;
if (!createAccountStore.jsonString && confirm !== password) {
this.setState({
error: 'Password confirmation does not match.'
});
return;
}
Axel Chalon
committed
this.setState({ isLoading: true });
createAccountStore
.saveAccountToParity(password)
.then(res => {
createAccountStore.clear();
history.push('/accounts');
})
.catch(err => {
console.error(err);
this.setState({
isLoading: false,
error: err.text
});
});
};
createAccountStore: { address, name, jsonString, isImport },
const { confirm, error, isLoading, password } = this.state;
const currentStep = pathname.slice(-1);
<AccountCard
address={address}
name={name}
drawers={[
<form key='createAccount' onSubmit={this.handleSubmit}>
<div className='text'>
{jsonString
? 'Unlock your account to decrypt your JSON keystore file: '
: 'Secure your account with a password:'}
</p>
onChange={this.handlePasswordChange}
required
type='password'
value={password}
/>
{!jsonString && (
<FetherForm.Field
label='Confirm'
onChange={this.handleConfirmChange}
required
type='password'
value={confirm}
/>
{error && error + ' Please check your password and try again.'}
<nav className='form-nav -space-around'>
{currentStep > 1 && (
<button
className='button -cancel'
onClick={history.goBack}
type='button'
>
!password ||
(!jsonString && confirm !== password) ||
isLoading
Confirm account {isImport ? `${'import'}` : `${'creation'}`}
</button>
</nav>
</form>
]}
/>
export default AccountPassword;