2016-12-11 19:31:31 +01:00
|
|
|
// Copyright 2015, 2016 Parity Technologies (UK) Ltd.
|
2016-10-30 09:54:21 +01:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import React, { Component, PropTypes } from 'react';
|
|
|
|
|
2016-12-05 11:47:13 +01:00
|
|
|
import { Form, Input } from '~/ui';
|
2016-10-30 09:54:21 +01:00
|
|
|
|
|
|
|
import styles from '../createAccount.css';
|
|
|
|
|
2016-12-19 13:17:28 +01:00
|
|
|
import ERRORS from '../errors';
|
2016-10-30 09:54:21 +01:00
|
|
|
|
|
|
|
export default class RawKey extends Component {
|
|
|
|
static contextTypes = {
|
|
|
|
api: PropTypes.object.isRequired
|
|
|
|
}
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
onChange: PropTypes.func.isRequired
|
|
|
|
}
|
|
|
|
|
|
|
|
state = {
|
|
|
|
accountName: '',
|
|
|
|
accountNameError: ERRORS.noName,
|
2016-12-19 13:17:28 +01:00
|
|
|
isValidKey: false,
|
|
|
|
isValidName: false,
|
2017-01-06 17:56:57 +01:00
|
|
|
isValidPass: true,
|
2016-10-30 09:54:21 +01:00
|
|
|
passwordHint: '',
|
|
|
|
password1: '',
|
2016-12-19 13:17:28 +01:00
|
|
|
password1Error: null,
|
2016-10-30 09:54:21 +01:00
|
|
|
password2: '',
|
2016-12-19 13:17:28 +01:00
|
|
|
password2Error: null,
|
|
|
|
rawKey: '',
|
|
|
|
rawKeyError: ERRORS.noKey
|
2016-10-30 09:54:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillMount () {
|
|
|
|
this.props.onChange(false, {});
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { accountName, accountNameError, passwordHint, password1, password1Error, password2, password2Error, rawKey, rawKeyError } = this.state;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form>
|
|
|
|
<Input
|
|
|
|
hint='the raw hex encoded private key'
|
|
|
|
label='private key'
|
|
|
|
error={ rawKeyError }
|
|
|
|
value={ rawKey }
|
|
|
|
onChange={ this.onEditKey } />
|
|
|
|
<Input
|
|
|
|
label='account name'
|
|
|
|
hint='a descriptive name for the account'
|
|
|
|
error={ accountNameError }
|
|
|
|
value={ accountName }
|
|
|
|
onChange={ this.onEditAccountName } />
|
|
|
|
<Input
|
|
|
|
label='password hint'
|
|
|
|
hint='(optional) a hint to help with remembering the password'
|
|
|
|
value={ passwordHint }
|
|
|
|
onChange={ this.onEditPasswordHint } />
|
|
|
|
<div className={ styles.passwords }>
|
|
|
|
<div className={ styles.password }>
|
|
|
|
<Input
|
|
|
|
label='password'
|
|
|
|
hint='a strong, unique password'
|
|
|
|
type='password'
|
|
|
|
error={ password1Error }
|
|
|
|
value={ password1 }
|
|
|
|
onChange={ this.onEditPassword1 } />
|
|
|
|
</div>
|
|
|
|
<div className={ styles.password }>
|
|
|
|
<Input
|
|
|
|
label='password (repeat)'
|
|
|
|
hint='verify your password'
|
|
|
|
type='password'
|
|
|
|
error={ password2Error }
|
|
|
|
value={ password2 }
|
|
|
|
onChange={ this.onEditPassword2 } />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateParent = () => {
|
|
|
|
const { isValidName, isValidPass, isValidKey, accountName, passwordHint, password1, rawKey } = this.state;
|
|
|
|
const isValid = isValidName && isValidPass && isValidKey;
|
|
|
|
|
|
|
|
this.props.onChange(isValid, {
|
|
|
|
name: accountName,
|
|
|
|
passwordHint,
|
|
|
|
password: password1,
|
|
|
|
rawKey
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onEditPasswordHint = (event, value) => {
|
|
|
|
this.setState({
|
|
|
|
passwordHint: value
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onEditKey = (event) => {
|
|
|
|
const { api } = this.context;
|
|
|
|
const rawKey = event.target.value;
|
|
|
|
let rawKeyError = null;
|
|
|
|
|
|
|
|
if (!rawKey || !rawKey.trim().length) {
|
|
|
|
rawKeyError = ERRORS.noKey;
|
|
|
|
} else if (rawKey.substr(0, 2) !== '0x' || rawKey.substr(2).length !== 64 || !api.util.isHex(rawKey)) {
|
|
|
|
rawKeyError = ERRORS.invalidKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
rawKey,
|
|
|
|
rawKeyError,
|
|
|
|
isValidKey: !rawKeyError
|
|
|
|
}, this.updateParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
onEditAccountName = (event) => {
|
|
|
|
const accountName = event.target.value;
|
|
|
|
let accountNameError = null;
|
|
|
|
|
2016-12-19 13:17:28 +01:00
|
|
|
if (!accountName || !accountName.trim().length) {
|
2016-10-30 09:54:21 +01:00
|
|
|
accountNameError = ERRORS.noName;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
accountName,
|
|
|
|
accountNameError,
|
|
|
|
isValidName: !accountNameError
|
|
|
|
}, this.updateParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
onEditPassword1 = (event) => {
|
2016-12-19 13:17:28 +01:00
|
|
|
const password1 = event.target.value;
|
|
|
|
let password2Error = null;
|
2016-10-30 09:54:21 +01:00
|
|
|
|
2016-12-19 13:17:28 +01:00
|
|
|
if (password1 !== this.state.password2) {
|
|
|
|
password2Error = ERRORS.noMatchPassword;
|
2016-10-30 09:54:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({
|
2016-12-19 13:17:28 +01:00
|
|
|
password1,
|
|
|
|
password1Error: null,
|
|
|
|
password2Error,
|
|
|
|
isValidPass: !password2Error
|
2016-10-30 09:54:21 +01:00
|
|
|
}, this.updateParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
onEditPassword2 = (event) => {
|
2016-12-19 13:17:28 +01:00
|
|
|
const password2 = event.target.value;
|
|
|
|
let password2Error = null;
|
2016-10-30 09:54:21 +01:00
|
|
|
|
2016-12-19 13:17:28 +01:00
|
|
|
if (password2 !== this.state.password1) {
|
|
|
|
password2Error = ERRORS.noMatchPassword;
|
2016-10-30 09:54:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({
|
2016-12-19 13:17:28 +01:00
|
|
|
password2,
|
|
|
|
password2Error,
|
|
|
|
isValidPass: !password2Error
|
2016-10-30 09:54:21 +01:00
|
|
|
}, this.updateParent);
|
|
|
|
}
|
|
|
|
}
|