2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2016-12-06 09:37:59 +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 { observer } from 'mobx-react';
|
2017-01-26 16:11:04 +01:00
|
|
|
import React, { Component, PropTypes } from 'react';
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
2016-12-06 09:37:59 +01:00
|
|
|
|
2017-02-22 15:26:58 +01:00
|
|
|
import { BusyStep, Button, Portal, TxHash } from '~/ui';
|
2017-01-26 16:11:04 +01:00
|
|
|
import { CancelIcon, DoneIcon, NextIcon } from '~/ui/Icons';
|
2016-12-06 09:37:59 +01:00
|
|
|
|
2016-12-07 12:47:44 +01:00
|
|
|
import WalletType from './WalletType';
|
2016-12-06 09:37:59 +01:00
|
|
|
import WalletDetails from './WalletDetails';
|
|
|
|
import WalletInfo from './WalletInfo';
|
|
|
|
import CreateWalletStore from './createWalletStore';
|
|
|
|
|
|
|
|
@observer
|
|
|
|
export default class CreateWallet extends Component {
|
|
|
|
static contextTypes = {
|
|
|
|
api: PropTypes.object.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
accounts: PropTypes.object.isRequired,
|
|
|
|
onClose: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
store = new CreateWalletStore(this.context.api, this.props.accounts);
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { stage, steps, waiting, rejected } = this.store;
|
|
|
|
|
|
|
|
if (rejected) {
|
|
|
|
return (
|
2017-02-22 15:26:58 +01:00
|
|
|
<Portal
|
|
|
|
buttons={ this.renderDialogActions() }
|
|
|
|
onClose={ this.onClose }
|
|
|
|
open
|
2017-01-26 16:11:04 +01:00
|
|
|
title={
|
|
|
|
<FormattedMessage
|
|
|
|
id='createWallet.rejected.title'
|
|
|
|
defaultMessage='rejected'
|
|
|
|
/>
|
|
|
|
}
|
2016-12-06 09:37:59 +01:00
|
|
|
>
|
|
|
|
<BusyStep
|
2017-01-26 16:11:04 +01:00
|
|
|
title={
|
|
|
|
<FormattedMessage
|
|
|
|
id='createWallet.rejected.message'
|
|
|
|
defaultMessage='The deployment has been rejected'
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
state={
|
|
|
|
<FormattedMessage
|
|
|
|
id='createWallet.rejected.state'
|
|
|
|
defaultMessage='The wallet will not be created. You can safely close this window.'
|
|
|
|
/>
|
|
|
|
}
|
2016-12-06 09:37:59 +01:00
|
|
|
/>
|
2017-02-22 15:26:58 +01:00
|
|
|
</Portal>
|
2016-12-06 09:37:59 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2017-02-22 15:26:58 +01:00
|
|
|
<Portal
|
|
|
|
activeStep={ stage }
|
|
|
|
busySteps={ waiting }
|
|
|
|
buttons={ this.renderDialogActions() }
|
|
|
|
onClose={ this.onClose }
|
|
|
|
open
|
2017-01-26 16:11:04 +01:00
|
|
|
steps={ steps.map((step) => step.title) }
|
2016-12-06 09:37:59 +01:00
|
|
|
>
|
|
|
|
{ this.renderPage() }
|
2017-02-22 15:26:58 +01:00
|
|
|
</Portal>
|
2016-12-06 09:37:59 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderPage () {
|
|
|
|
const { step } = this.store;
|
|
|
|
const { accounts } = this.props;
|
|
|
|
|
|
|
|
switch (step) {
|
|
|
|
case 'DEPLOYMENT':
|
|
|
|
return (
|
|
|
|
<BusyStep
|
2017-01-26 16:11:04 +01:00
|
|
|
title={
|
|
|
|
<FormattedMessage
|
|
|
|
id='createWallet.deployment.message'
|
|
|
|
defaultMessage='The deployment is currently in progress'
|
|
|
|
/>
|
|
|
|
}
|
2016-12-06 09:37:59 +01:00
|
|
|
state={ this.store.deployState }
|
|
|
|
>
|
2017-01-26 16:11:04 +01:00
|
|
|
{
|
|
|
|
this.store.txhash
|
|
|
|
? <TxHash hash={ this.store.txhash } />
|
|
|
|
: null
|
|
|
|
}
|
2016-12-06 09:37:59 +01:00
|
|
|
</BusyStep>
|
|
|
|
);
|
|
|
|
|
|
|
|
case 'INFO':
|
|
|
|
return (
|
|
|
|
<WalletInfo
|
|
|
|
accounts={ accounts }
|
|
|
|
account={ this.store.wallet.account }
|
|
|
|
address={ this.store.wallet.address }
|
|
|
|
daylimit={ this.store.wallet.daylimit }
|
2016-12-07 12:47:44 +01:00
|
|
|
deployed={ this.store.deployed }
|
2017-01-26 16:11:04 +01:00
|
|
|
name={ this.store.wallet.name }
|
|
|
|
owners={ this.store.wallet.owners.slice() }
|
|
|
|
required={ this.store.wallet.required }
|
2016-12-06 09:37:59 +01:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
case 'DETAILS':
|
|
|
|
return (
|
|
|
|
<WalletDetails
|
|
|
|
accounts={ accounts }
|
|
|
|
errors={ this.store.errors }
|
|
|
|
onChange={ this.store.onChange }
|
2017-01-26 16:11:04 +01:00
|
|
|
wallet={ this.store.wallet }
|
|
|
|
walletType={ this.store.walletType }
|
2016-12-06 09:37:59 +01:00
|
|
|
/>
|
|
|
|
);
|
2016-12-07 12:47:44 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
case 'TYPE':
|
|
|
|
return (
|
|
|
|
<WalletType
|
|
|
|
onChange={ this.store.onTypeChange }
|
|
|
|
type={ this.store.walletType }
|
|
|
|
/>
|
|
|
|
);
|
2016-12-06 09:37:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renderDialogActions () {
|
2016-12-07 12:47:44 +01:00
|
|
|
const { step, hasErrors, rejected, onCreate, onNext, onAdd } = this.store;
|
2016-12-06 09:37:59 +01:00
|
|
|
|
|
|
|
const cancelBtn = (
|
|
|
|
<Button
|
2017-01-26 16:11:04 +01:00
|
|
|
icon={ <CancelIcon /> }
|
2017-02-22 15:26:58 +01:00
|
|
|
key='cancel'
|
2017-01-26 16:11:04 +01:00
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='createWallet.button.cancel'
|
|
|
|
defaultMessage='Cancel'
|
|
|
|
/>
|
|
|
|
}
|
2016-12-06 09:37:59 +01:00
|
|
|
onClick={ this.onClose }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const closeBtn = (
|
|
|
|
<Button
|
2017-01-26 16:11:04 +01:00
|
|
|
icon={ <CancelIcon /> }
|
2017-02-22 15:26:58 +01:00
|
|
|
key='close'
|
2017-01-26 16:11:04 +01:00
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='createWallet.button.close'
|
|
|
|
defaultMessage='Close'
|
|
|
|
/>
|
|
|
|
}
|
2016-12-06 09:37:59 +01:00
|
|
|
onClick={ this.onClose }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const doneBtn = (
|
|
|
|
<Button
|
2017-01-26 16:11:04 +01:00
|
|
|
icon={ <DoneIcon /> }
|
2017-02-22 15:26:58 +01:00
|
|
|
key='done'
|
2017-01-26 16:11:04 +01:00
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='createWallet.button.done'
|
|
|
|
defaultMessage='Done'
|
|
|
|
/>
|
|
|
|
}
|
2016-12-06 09:37:59 +01:00
|
|
|
onClick={ this.onClose }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const sendingBtn = (
|
|
|
|
<Button
|
2017-01-26 16:11:04 +01:00
|
|
|
icon={ <DoneIcon /> }
|
2017-02-22 15:26:58 +01:00
|
|
|
key='sending'
|
2017-01-26 16:11:04 +01:00
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='createWallet.button.sending'
|
|
|
|
defaultMessage='Sending...'
|
|
|
|
/>
|
|
|
|
}
|
2016-12-06 09:37:59 +01:00
|
|
|
disabled
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2016-12-07 12:47:44 +01:00
|
|
|
const nextBtn = (
|
2016-12-06 09:37:59 +01:00
|
|
|
<Button
|
2017-01-26 16:11:04 +01:00
|
|
|
icon={ <NextIcon /> }
|
2017-02-22 15:26:58 +01:00
|
|
|
key='next'
|
2017-01-26 16:11:04 +01:00
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='createWallet.button.next'
|
|
|
|
defaultMessage='Next'
|
|
|
|
/>
|
|
|
|
}
|
2016-12-07 12:47:44 +01:00
|
|
|
onClick={ onNext }
|
2016-12-06 09:37:59 +01:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
if (rejected) {
|
|
|
|
return [ closeBtn ];
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (step) {
|
|
|
|
case 'DEPLOYMENT':
|
|
|
|
return [ closeBtn, sendingBtn ];
|
|
|
|
|
|
|
|
case 'INFO':
|
|
|
|
return [ doneBtn ];
|
|
|
|
|
|
|
|
case 'DETAILS':
|
2016-12-07 12:47:44 +01:00
|
|
|
if (this.store.walletType === 'WATCH') {
|
|
|
|
return [ cancelBtn, (
|
|
|
|
<Button
|
|
|
|
disabled={ hasErrors }
|
2017-01-26 16:11:04 +01:00
|
|
|
icon={ <NextIcon /> }
|
2017-02-22 15:26:58 +01:00
|
|
|
key='add'
|
2017-01-26 16:11:04 +01:00
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='createWallet.button.add'
|
|
|
|
defaultMessage='Add'
|
|
|
|
/>
|
|
|
|
}
|
2016-12-07 12:47:44 +01:00
|
|
|
onClick={ onAdd }
|
|
|
|
/>
|
|
|
|
) ];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [ cancelBtn, (
|
|
|
|
<Button
|
|
|
|
disabled={ hasErrors }
|
2017-01-26 16:11:04 +01:00
|
|
|
icon={ <NextIcon /> }
|
2017-02-22 15:26:58 +01:00
|
|
|
key='create'
|
2017-01-26 16:11:04 +01:00
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='createWallet.button.create'
|
|
|
|
defaultMessage='Create'
|
|
|
|
/>
|
|
|
|
}
|
2016-12-07 12:47:44 +01:00
|
|
|
onClick={ onCreate }
|
|
|
|
/>
|
|
|
|
) ];
|
|
|
|
|
|
|
|
default:
|
|
|
|
case 'TYPE':
|
|
|
|
return [ cancelBtn, nextBtn ];
|
2016-12-06 09:37:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onClose = () => {
|
|
|
|
this.props.onClose();
|
|
|
|
}
|
|
|
|
}
|