// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
// SPDX-License-Identifier: BSD-3-Clause
import React, { Component } from 'react';
import { AccountCard, Card, Form as FetherForm } from 'fether-ui';
import Blockies from 'react-blockies';
import { inject, observer } from 'mobx-react';
import loading from '../../../assets/img/icons/loading.svg';
@inject('createAccountStore')
@observer
class AccountName extends Component {
componentDidMount () {
const { createAccountStore } = this.props;
// Generate a new public address if there's none yet
if (!createAccountStore.address) {
createAccountStore.generateNewAccount();
}
}
handleChangeName = ({ target: { value } }) =>
this.props.createAccountStore.setName(value);
handleSubmit = () => {
const {
createAccountStore,
history,
location: { pathname }
} = this.props;
const currentStep = pathname.slice(-1);
if (createAccountStore.noPrivateKey) {
// 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 }
} = this.props;
return (