Newer
Older
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
import { AccountCard, Card, Form as FetherForm } from 'fether-ui';
import Blockies from 'react-blockies';
import { inject, observer } from 'mobx-react';
Axel Chalon
committed
import loading from '../../../assets/img/icons/loading.svg';
class AccountName extends Component {
const { createAccountStore } = this.props;
// Generate a new public address if there's none yet
if (!createAccountStore.address) {
createAccountStore.generateNewAccount();
}
this.props.createAccountStore.setName(value);
// Save Signer account to Parity without asking for a password
createAccountStore
.saveAccountToParity()
.then(res => {
createAccountStore.clear();
history.push('/accounts');
})
.catch(err => {
console.error(err);
this.setState({
error: err.text
});
});
} else {
// Ask for a password otherwise
history.push(`/accounts/new/${+currentStep + 1}`);
}
render () {
const {
createAccountStore: { isImport }
} = this.props;
return isImport ? this.renderCardWhenImported() : this.renderCardWhenNew();
}
renderCardWhenImported = () => {
const {
createAccountStore: { address, name, noPrivateKey }
drawers={[this.renderDrawer()]}
name={name || '(no name)'}
/>
);
};
renderCardWhenNew = () => {
const {
createAccountStore: { address, generateNewAccount }
} = this.props;
return (
<Card drawers={[this.renderDrawer()]}>
<div className='account'>
<div className='account_avatar'>
Axel Chalon
committed
{address ? (
<Blockies seed={address.toLowerCase()} />
) : (
<img
className='account_avatar_loading'
alt='loading'
src={loading}
/>
)}
<button className='button -back' onClick={generateNewAccount}>
Axel Chalon
committed
Generate another icon
</div>
</Card>
);
};
renderDrawer = () => {
const {
Axel Chalon
committed
createAccountStore: { address, name },
location: { pathname }
} = this.props;
const currentStep = pathname.slice(-1);
return (
<form key='createAccount' onSubmit={this.handleSubmit}>
<div className='text'>
<p>Please give this account a name:</p>
</div>
label='Name'
onChange={this.handleChangeName}
required
type='text'
value={name}
/>
<nav className='form-nav -space-around'>
{currentStep > 1 && (
onClick={history.goBack}
type='button'
>
Axel Chalon
committed
{name && address ? (
) : (
<button className='button' disabled>
Next
</button>
)}
</nav>