Newer
Older
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
import { AccountCard, Form as FetherForm } from 'fether-ui';
import { inject, observer } from 'mobx-react';
import i18n, { packageNS } from '../../../i18n';
Luke Schoen
committed
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: `${i18n.t(
`${packageNS}:account.password.create.error_msg_password_confirmation_no_match`
)}`
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);
Amaury Martiny
committed
<AccountCard
address={address}
name={name}
drawers={[
<form key='createAccount' noValidate onSubmit={this.handleSubmit}>
<div className='text'>
<p>
{' '}
{jsonString
? i18n.t(
`${packageNS}:account.password.import.label_msg_unlock_json`
)
: i18n.t(
`${packageNS}:account.password.create.label_msg_password`
)}
</p>
</div>
Luke Schoen
committed
Amaury Martiny
committed
<FetherForm.Field
autoFocus
label={i18n.t(
`${packageNS}:account.password.common.label_password`
)}
onChange={this.handlePasswordChange}
required
type='password'
value={password}
/>
{!jsonString && (
label={i18n.t(
Amaury Martiny
committed
`${packageNS}:account.password.common.label_password_confirm`
Amaury Martiny
committed
onChange={this.handleConfirmChange}
Amaury Martiny
committed
value={confirm}
Amaury Martiny
committed
)}
<p>
{error &&
error +
' ' +
i18n.t(
`${packageNS}:account.password.common.error_msg_password_incorrect`
Amaury Martiny
committed
</p>
Amaury Martiny
committed
<nav className='form-nav -space-around'>
{currentStep > 1 && (
Amaury Martiny
committed
className='button -back'
onClick={history.goBack}
type='button'
Amaury Martiny
committed
{i18n.t(`${packageNS}:navigation.back`)}
Amaury Martiny
committed
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
)}
<button
autoFocus
className='button'
disabled={
!password ||
(!jsonString && confirm !== password) ||
isLoading
}
>
{i18n.t(`${packageNS}:account.password.common.button_confirm`, {
postfix: isImport
? i18n.t(
`${packageNS}:account.password.common.button_confirm_opt1`
)
: i18n.t(
`${packageNS}:account.password.common.button_confirm_opt2`
)
})}
</button>
</nav>
</form>
]}
i18n={i18n}
packageNS={packageNS}
/>
export default AccountPassword;