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';
Luke Schoen
committed
import RequireHealthOverlay from '../../../RequireHealthOverlay';
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);
Luke Schoen
committed
<RequireHealthOverlay require='node'>
<AccountCard
address={address}
name={name}
drawers={[
<form key='createAccount' onSubmit={this.handleSubmit}>
<div className='text'>
<p>
{' '}
{jsonString
? 'Unlock your account to decrypt your JSON keystore file: '
: 'Secure your account with a password:'}
</p>
</div>
Luke Schoen
committed
autoFocus
label='Password'
onChange={this.handlePasswordChange}
Luke Schoen
committed
value={password}
Luke Schoen
committed
{!jsonString && (
<FetherForm.Field
label='Confirm'
onChange={this.handleConfirmChange}
required
type='password'
value={confirm}
/>
)}
Luke Schoen
committed
<p>
{error && error + ' Please check your password and try again.'}
</p>
<nav className='form-nav -space-around'>
{currentStep > 1 && (
<button
className='button -back'
onClick={history.goBack}
type='button'
>
Back
</button>
)}
Luke Schoen
committed
autoFocus
className='button'
disabled={
!password ||
(!jsonString && confirm !== password) ||
isLoading
}
Luke Schoen
committed
Confirm account {isImport ? `${'import'}` : `${'creation'}`}
Luke Schoen
committed
</nav>
</form>
]}
/>
</RequireHealthOverlay>
export default AccountPassword;