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';
|
2017-03-28 14:34:31 +02:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { bindActionCreators } from 'redux';
|
2016-12-06 09:37:59 +01:00
|
|
|
|
2017-03-28 14:34:31 +02:00
|
|
|
import { Button, Portal } from '~/ui';
|
2017-01-26 16:11:04 +01:00
|
|
|
import { CancelIcon, DoneIcon, NextIcon } from '~/ui/Icons';
|
2017-03-28 14:34:31 +02:00
|
|
|
import { setRequest } from '~/redux/providers/requestsActions';
|
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
|
2017-03-28 14:34:31 +02:00
|
|
|
export class CreateWallet extends Component {
|
2016-12-06 09:37:59 +01:00
|
|
|
static contextTypes = {
|
|
|
|
api: PropTypes.object.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
accounts: PropTypes.object.isRequired,
|
2017-03-28 14:34:31 +02:00
|
|
|
onClose: PropTypes.func.isRequired,
|
|
|
|
onSetRequest: PropTypes.func.isRequired
|
2016-12-06 09:37:59 +01:00
|
|
|
};
|
|
|
|
|
2017-03-28 14:34:31 +02:00
|
|
|
store = new CreateWalletStore(this.context.api, this.props);
|
2016-12-06 09:37:59 +01:00
|
|
|
|
|
|
|
render () {
|
2017-03-28 14:34:31 +02:00
|
|
|
const { stage, steps } = this.store;
|
2016-12-06 09:37:59 +01:00
|
|
|
|
|
|
|
return (
|
2017-02-22 15:26:58 +01:00
|
|
|
<Portal
|
|
|
|
activeStep={ stage }
|
|
|
|
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 '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 () {
|
2017-03-28 14:34:31 +02:00
|
|
|
const { step, hasErrors, 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 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 }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
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
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
switch (step) {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2017-03-28 14:34:31 +02:00
|
|
|
|
|
|
|
function mapDispatchToProps (dispatch) {
|
|
|
|
return bindActionCreators({
|
|
|
|
onSetRequest: setRequest
|
|
|
|
}, dispatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
null,
|
|
|
|
mapDispatchToProps
|
|
|
|
)(CreateWallet);
|