Skip to content
AccountWritePhrase.js 2.38 KiB
Newer Older
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
// SPDX-License-Identifier: MIT

import React, { Component } from 'react';
import { inject, observer } from 'mobx-react';

import AccountPlaceholder from '../AccountPlaceholder';
import CreateAccountHeader from '../CreateAccountHeader';

@inject('createAccountStore')
@observer
class AccountWritePhrase extends Component {
  state = {
    value: ''
  };

  handleChange = ({ target: { value } }) => this.setState({ value });

  handleNextStep = () => {
    const { history, location: { pathname } } = this.props;
    const currentStep = pathname.slice(-1);
    history.push(`/accounts/new/${+currentStep + 1}`);
  };

Amaury Martiny's avatar
Amaury Martiny committed
  handleSavePhrase = () => {
    const { createAccountStore: { setPhrase } } = this.props;
Amaury Martiny's avatar
Amaury Martiny committed
    const { value } = this.state;
    setPhrase(value).then(this.handleNextStep);
Amaury Martiny's avatar
Amaury Martiny committed
  };

Amaury Martiny's avatar
Amaury Martiny committed
  render () {
    const { createAccountStore: { isImport } } = this.props;
    const { value } = this.state;

    return (
      <div className='window_content'>
        <div className='box -padded'>
          <div className='box -card'>
            {isImport ? <AccountPlaceholder /> : <CreateAccountHeader />}
            <div className='box -card-drawer'>
              <div className='text'>
                <p>Please write your recovery phrase here:</p>
              </div>
              <div className='form_field'>
                <label>Recovery phrase</label>
Brian Flanagan's avatar
Brian Flanagan committed
                <textarea onChange={this.handleChange} required value={value} />
              </div>

              <nav className='form-nav'>
Amaury Martiny's avatar
Amaury Martiny committed
                {this.renderButton()}
              </nav>
            </div>
          </div>
        </div>
      </div>
    );
  }
Amaury Martiny's avatar
Amaury Martiny committed

  renderButton = () => {
    const { createAccountStore: { isImport, phrase } } = this.props;
Amaury Martiny's avatar
Amaury Martiny committed
    const { value } = this.state;

    // If we are creating a new account, the button just checks the phrase has
    // been correctly written by the user.
    if (!isImport) {
      return (
        <button
          className='button'
          disabled={value !== phrase}
          onClick={this.handleNextStep}
        >
          Next
        </button>
      );
Amaury Martiny's avatar
Amaury Martiny committed
    }

    // If we are importing an existing account, the button sets the phrase
    return (
      <button className='button' onClick={this.handleSavePhrase}>
        Next
      </button>
    );
  };
export default AccountWritePhrase;