Newer
Older
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
import React, { Component } from 'react';
import { accountsInfo$ } from '@parity/light.js';
import { inject, observer } from 'mobx-react';
import memoize from 'lodash/memoize';
import { Route } from 'react-router-dom';
import AccountConfirm from './AccountConfirm';
import AccountCopyPhrase from './AccountCopyPhrase';
import AccountName from './AccountName';
import AccountPassword from './AccountPassword';
import AccountRewritePhrase from './AccountRewritePhrase';
@inject('createAccountStore')
@observer
class CreateAccount extends Component {
/**
* Creating account and importing accounts have different processes: 4 steps
* for importing, and 5 steps for creating
*/
getSteps = memoize(isImport => {
return isImport
? [AccountRewritePhrase, AccountName, AccountPassword, AccountConfirm]
: [
AccountName,
AccountCopyPhrase,
AccountPassword,
AccountConfirm
];
});
handleToggleCreateImport = () => {
const {
createAccountStore,
history,
match: {
params: { step }
}
} = this.props;
createAccountStore.setIsImport(!createAccountStore.isImport);
// If we were further in the account creation, go back to step 1
if (step > 1) {
history.push('/accounts/new/1');
}
handleGoBack = () => this.props.history.goBack();
createAccountStore: { isImport },
params: { step } // Current step in account creation process
}
} = this.props;
// Get all the steps of our account process
const Steps = this.getSteps(isImport);
// Show back button if:
// - we already have some accounts, so we can go back to AccountsList
// - or the step is >1
(step > 1 ||
(accountsInfo && Object.keys(accountsInfo).length > 0)) && (
<a className='icon -back' onClick={this.handleGoBack}>
Back
</a>
)
<h1>{isImport ? 'Import account' : 'Create a new account'}</h1>
<div className='box -padded'>
{Steps.map((StepComponent, index) => (
<Route
component={StepComponent}
key={`Step${index + 1}`}
path={`/accounts/new/${index + 1}`}
/>
))}
</div>
<nav className='footer-nav'>
<div className='footer-nav_option'>
Import account
</button>
</p>
</div>
);
}
}
export default CreateAccount;