2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2016-12-08 15:53:29 +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/>.
|
|
|
|
|
2017-07-17 18:37:33 +02:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-02-10 18:27:18 +01:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2016-12-08 15:53:29 +01:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { observer } from 'mobx-react';
|
|
|
|
import { pick } from 'lodash';
|
|
|
|
|
2017-04-21 11:40:22 +02:00
|
|
|
import { fromWei } from '@parity/api/util/wei';
|
2017-05-12 12:06:16 +02:00
|
|
|
import { AddressSelect, Button, Form, TypedInput, Input, InputAddress, Portal } from '@parity/ui';
|
|
|
|
import { CancelIcon, NextIcon } from '@parity/ui/Icons';
|
2016-12-08 15:53:29 +01:00
|
|
|
|
|
|
|
import WalletSettingsStore from './walletSettingsStore.js';
|
|
|
|
import styles from './walletSettings.css';
|
|
|
|
|
|
|
|
@observer
|
|
|
|
class WalletSettings extends Component {
|
|
|
|
static contextTypes = {
|
|
|
|
api: PropTypes.object.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
static propTypes = {
|
2016-12-30 12:28:12 +01:00
|
|
|
accountsInfo: PropTypes.object.isRequired,
|
2016-12-08 15:53:29 +01:00
|
|
|
wallet: PropTypes.object.isRequired,
|
|
|
|
onClose: PropTypes.func.isRequired,
|
|
|
|
senders: PropTypes.object.isRequired
|
|
|
|
};
|
|
|
|
|
2017-03-28 14:34:31 +02:00
|
|
|
store = new WalletSettingsStore(this.context.api, this.props);
|
2016-12-08 15:53:29 +01:00
|
|
|
|
|
|
|
render () {
|
2017-03-28 14:34:31 +02:00
|
|
|
const { stage, steps } = this.store;
|
2016-12-08 15:53:29 +01:00
|
|
|
|
|
|
|
return (
|
2017-02-22 15:26:58 +01:00
|
|
|
<Portal
|
|
|
|
activeStep={ stage }
|
|
|
|
buttons={ this.renderDialogActions() }
|
|
|
|
onClose={ this.onClose }
|
|
|
|
open
|
|
|
|
steps={ steps.map((step) => step.title) }
|
2016-12-08 15:53:29 +01:00
|
|
|
>
|
|
|
|
{ this.renderPage() }
|
2017-02-22 15:26:58 +01:00
|
|
|
</Portal>
|
2016-12-08 15:53:29 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderPage () {
|
|
|
|
const { step } = this.store;
|
|
|
|
|
|
|
|
switch (step) {
|
|
|
|
case 'CONFIRMATION':
|
|
|
|
const { changes } = this.store;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
2016-12-19 13:16:59 +01:00
|
|
|
{ this.renderChanges(changes) }
|
2016-12-08 15:53:29 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
default:
|
|
|
|
case 'EDIT':
|
2017-02-10 18:27:18 +01:00
|
|
|
const { errors, fromString, wallet } = this.store;
|
2016-12-30 12:28:12 +01:00
|
|
|
const { accountsInfo, senders } = this.props;
|
2016-12-08 15:53:29 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Form>
|
|
|
|
<p>
|
2017-02-10 18:27:18 +01:00
|
|
|
<FormattedMessage
|
|
|
|
id='walletSettings.edit.message'
|
|
|
|
defaultMessage={
|
|
|
|
`In order to edit this contract's settings, at
|
|
|
|
least { owners, number } { owners, plural,
|
|
|
|
one { owner }
|
|
|
|
other { owners }
|
|
|
|
} have to
|
|
|
|
send the very same modifications. You can paste a stringified version
|
|
|
|
of the modifications here.`
|
|
|
|
}
|
|
|
|
values={ {
|
|
|
|
owners: this.store.initialWallet.require.toNumber()
|
|
|
|
} }
|
|
|
|
/>
|
2016-12-08 15:53:29 +01:00
|
|
|
</p>
|
|
|
|
|
2017-02-10 18:27:18 +01:00
|
|
|
<Input
|
2017-02-24 12:26:30 +01:00
|
|
|
autoFocus
|
2017-02-10 18:27:18 +01:00
|
|
|
hint='[ ... ]'
|
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='walletSettings.modifications.fromString.label'
|
|
|
|
defaultMessage='modifications'
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
onChange={ this.store.onModificationsStringChange }
|
|
|
|
/>
|
|
|
|
|
2016-12-08 15:53:29 +01:00
|
|
|
<AddressSelect
|
2017-02-10 18:27:18 +01:00
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='walletSettings.modifications.sender.label'
|
|
|
|
defaultMessage='from account (wallet owner)'
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
hint={
|
|
|
|
<FormattedMessage
|
|
|
|
id='walletSettings.modifications.sender.hint'
|
|
|
|
defaultMessage='send modifications as this owner'
|
|
|
|
/>
|
|
|
|
}
|
2016-12-08 15:53:29 +01:00
|
|
|
value={ wallet.sender }
|
|
|
|
error={ errors.sender }
|
|
|
|
onChange={ this.store.onSenderChange }
|
|
|
|
accounts={ senders }
|
|
|
|
/>
|
|
|
|
|
2017-02-10 18:27:18 +01:00
|
|
|
<br />
|
2016-12-08 15:53:29 +01:00
|
|
|
|
2017-02-10 18:27:18 +01:00
|
|
|
{
|
|
|
|
fromString
|
|
|
|
? null
|
|
|
|
: (
|
|
|
|
<div>
|
|
|
|
<TypedInput
|
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='walletSettings.modifications.owners.label'
|
|
|
|
defaultMessage='other wallet owners'
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
value={ wallet.owners.slice() }
|
|
|
|
onChange={ this.store.onOwnersChange }
|
|
|
|
accounts={ accountsInfo }
|
|
|
|
param='address[]'
|
|
|
|
/>
|
2016-12-08 15:53:29 +01:00
|
|
|
|
2017-02-10 18:27:18 +01:00
|
|
|
<div className={ styles.splitInput }>
|
|
|
|
<TypedInput
|
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='walletSettings.modifications.required.label'
|
|
|
|
defaultMessage='required owners'
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
hint={
|
|
|
|
<FormattedMessage
|
|
|
|
id='walletSettings.modifications.required.hint'
|
|
|
|
defaultMessage='number of required owners to accept a transaction'
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
error={ errors.require }
|
|
|
|
min={ 1 }
|
|
|
|
onChange={ this.store.onRequireChange }
|
|
|
|
max={ wallet.owners.length }
|
|
|
|
param='uint'
|
|
|
|
value={ wallet.require }
|
|
|
|
/>
|
|
|
|
|
|
|
|
<TypedInput
|
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='walletSettings.modifications.daylimit.label'
|
|
|
|
defaultMessage='wallet day limit'
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
hint={
|
|
|
|
<FormattedMessage
|
|
|
|
id='walletSettings.modifications.daylimit.hint'
|
|
|
|
defaultMessage='amount of ETH spendable without confirmations'
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
value={ wallet.dailylimit }
|
|
|
|
error={ errors.dailylimit }
|
|
|
|
onChange={ this.store.onDailylimitChange }
|
|
|
|
param='uint'
|
|
|
|
isEth
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2016-12-08 15:53:29 +01:00
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renderChanges (changes) {
|
2016-12-19 13:16:59 +01:00
|
|
|
if (changes.length === 0) {
|
|
|
|
return (
|
2017-02-10 18:27:18 +01:00
|
|
|
<p>
|
|
|
|
<FormattedMessage
|
|
|
|
id='walletSettings.changes.none'
|
|
|
|
defaultMessage='No modifications have been made to the Wallet settings.'
|
|
|
|
/>
|
|
|
|
</p>
|
2016-12-19 13:16:59 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const modifications = changes.map((change, index) => (
|
2016-12-08 15:53:29 +01:00
|
|
|
<div key={ `${change.type}_${index}` }>
|
|
|
|
{ this.renderChange(change) }
|
|
|
|
</div>
|
|
|
|
));
|
2016-12-19 13:16:59 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
2017-02-10 18:27:18 +01:00
|
|
|
<p className={ styles.modifications }>
|
|
|
|
<FormattedMessage
|
|
|
|
id='walletSettings.changes.modificationString'
|
|
|
|
defaultMessage={
|
|
|
|
`For your modifications to be taken into account,
|
|
|
|
other owners have to send the same modifications. They can paste
|
|
|
|
this string to make it easier:`
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</p>
|
|
|
|
<Input
|
|
|
|
allowCopy
|
|
|
|
label='modifications'
|
|
|
|
readOnly
|
|
|
|
value={ this.store.changesToString() }
|
|
|
|
/>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
<FormattedMessage
|
|
|
|
id='walletSettings.changes.overview'
|
2017-02-22 15:26:58 +01:00
|
|
|
defaultMessage='You are about to make the following modifications'
|
2017-02-10 18:27:18 +01:00
|
|
|
/>
|
|
|
|
</p>
|
2016-12-19 13:16:59 +01:00
|
|
|
{ modifications }
|
|
|
|
</div>
|
|
|
|
);
|
2016-12-08 15:53:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
renderChange (change) {
|
|
|
|
switch (change.type) {
|
|
|
|
case 'dailylimit':
|
|
|
|
return (
|
|
|
|
<div className={ styles.change }>
|
|
|
|
<div className={ styles.label }>Change Daily Limit</div>
|
|
|
|
<div>
|
|
|
|
<span> from </span>
|
|
|
|
<code> { fromWei(change.initial).toFormat() }</code>
|
|
|
|
<span className={ styles.eth } />
|
|
|
|
<span> to </span>
|
|
|
|
<code> { fromWei(change.value).toFormat() }</code>
|
|
|
|
<span className={ styles.eth } />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
case 'require':
|
|
|
|
return (
|
|
|
|
<div className={ styles.change }>
|
2017-02-22 15:26:58 +01:00
|
|
|
<div className={ styles.label }>
|
|
|
|
<FormattedMessage
|
|
|
|
id='walletSettings.ownersChange.title'
|
|
|
|
defaultMessage='Change Required Owners'
|
|
|
|
/>
|
|
|
|
</div>
|
2016-12-08 15:53:29 +01:00
|
|
|
<div>
|
2017-02-22 15:26:58 +01:00
|
|
|
<FormattedMessage
|
|
|
|
id='walletSettings.ownersChange.details'
|
|
|
|
defaultMessage=' from {from} to {to} '
|
|
|
|
values={ {
|
2017-05-09 12:55:35 +02:00
|
|
|
from: <code>{ change.initial.toNumber() }</code>,
|
|
|
|
to: <code>{ change.value.toNumber() }</code>
|
2017-02-22 15:26:58 +01:00
|
|
|
} }
|
|
|
|
/>
|
2016-12-08 15:53:29 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2017-05-09 12:55:35 +02:00
|
|
|
case 'change_owner':
|
|
|
|
return (
|
|
|
|
<div className={ [ styles.change ].join(' ') }>
|
|
|
|
<div className={ styles.label }>
|
|
|
|
<FormattedMessage
|
|
|
|
id='walletSettings.changeOwner.title'
|
|
|
|
defaultMessage='Change Owner'
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<InputAddress
|
|
|
|
disabled
|
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='walletSettings.changeOwner.labelFrom'
|
|
|
|
defaultMessage='From'
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
text
|
|
|
|
value={ change.value.from }
|
|
|
|
/>
|
|
|
|
<InputAddress
|
|
|
|
disabled
|
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='walletSettings.changeOwner.labelTo'
|
|
|
|
defaultMessage='To'
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
text
|
|
|
|
value={ change.value.to }
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2016-12-08 15:53:29 +01:00
|
|
|
case 'add_owner':
|
|
|
|
return (
|
|
|
|
<div className={ [ styles.change, styles.add ].join(' ') }>
|
2017-02-22 15:26:58 +01:00
|
|
|
<div className={ styles.label }>
|
|
|
|
<FormattedMessage
|
|
|
|
id='walletSettings.addOwner.title'
|
|
|
|
defaultMessage='Add Owner'
|
|
|
|
/>
|
|
|
|
</div>
|
2016-12-08 15:53:29 +01:00
|
|
|
<div>
|
|
|
|
<InputAddress
|
|
|
|
disabled
|
2017-05-09 12:55:35 +02:00
|
|
|
text
|
2016-12-08 15:53:29 +01:00
|
|
|
value={ change.value }
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
case 'remove_owner':
|
|
|
|
return (
|
|
|
|
<div className={ [ styles.change, styles.remove ].join(' ') }>
|
2017-02-22 15:26:58 +01:00
|
|
|
<div className={ styles.label }>
|
|
|
|
<FormattedMessage
|
|
|
|
id='walletSettings.removeOwner.title'
|
|
|
|
defaultMessage='Remove Owner'
|
|
|
|
/>
|
|
|
|
</div>
|
2016-12-08 15:53:29 +01:00
|
|
|
<div>
|
|
|
|
<InputAddress
|
|
|
|
disabled
|
2017-05-09 12:55:35 +02:00
|
|
|
text
|
2016-12-08 15:53:29 +01:00
|
|
|
value={ change.value }
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renderDialogActions () {
|
2017-03-28 14:34:31 +02:00
|
|
|
const { step, hasErrors, onNext, send } = this.store;
|
2016-12-08 15:53:29 +01:00
|
|
|
|
|
|
|
const cancelBtn = (
|
|
|
|
<Button
|
2017-02-22 15:26:58 +01:00
|
|
|
icon={ <CancelIcon /> }
|
2017-03-07 20:19:55 +01:00
|
|
|
key='cancelBtn'
|
2017-02-22 15:26:58 +01:00
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='walletSettings.buttons.cancel'
|
|
|
|
defaultMessage='Cancel'
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
onClick={ this.onClose }
|
2016-12-08 15:53:29 +01:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const closeBtn = (
|
|
|
|
<Button
|
2017-02-22 15:26:58 +01:00
|
|
|
icon={ <CancelIcon /> }
|
2017-03-07 20:19:55 +01:00
|
|
|
key='closeBtn'
|
2017-02-22 15:26:58 +01:00
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='walletSettings.buttons.close'
|
|
|
|
defaultMessage='Close'
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
onClick={ this.onClose }
|
2016-12-08 15:53:29 +01:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const nextBtn = (
|
|
|
|
<Button
|
2017-02-22 15:26:58 +01:00
|
|
|
icon={ <NextIcon /> }
|
2017-03-07 20:19:55 +01:00
|
|
|
key='nextBtn'
|
2017-02-22 15:26:58 +01:00
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='walletSettings.buttons.next'
|
|
|
|
defaultMessage='Next'
|
|
|
|
/>
|
|
|
|
}
|
2016-12-08 15:53:29 +01:00
|
|
|
onClick={ onNext }
|
|
|
|
disabled={ hasErrors }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const sendBtn = (
|
|
|
|
<Button
|
2017-02-22 15:26:58 +01:00
|
|
|
icon={ <NextIcon /> }
|
2017-03-07 20:19:55 +01:00
|
|
|
key='sendBtn'
|
2017-02-22 15:26:58 +01:00
|
|
|
label={
|
|
|
|
<FormattedMessage
|
|
|
|
id='walletSettings.buttons.send'
|
|
|
|
defaultMessage='Send'
|
|
|
|
/>
|
|
|
|
}
|
2016-12-08 15:53:29 +01:00
|
|
|
onClick={ send }
|
|
|
|
disabled={ hasErrors }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
switch (step) {
|
|
|
|
case 'CONFIRMATION':
|
2016-12-19 13:16:59 +01:00
|
|
|
const { changes } = this.store;
|
|
|
|
|
|
|
|
if (changes.length === 0) {
|
|
|
|
return [ closeBtn ];
|
|
|
|
}
|
|
|
|
|
2016-12-08 15:53:29 +01:00
|
|
|
return [ cancelBtn, sendBtn ];
|
|
|
|
|
|
|
|
default:
|
|
|
|
case 'TYPE':
|
|
|
|
return [ cancelBtn, nextBtn ];
|
|
|
|
}
|
|
|
|
}
|
2017-02-22 15:26:58 +01:00
|
|
|
|
|
|
|
onClose = () => {
|
|
|
|
this.props.onClose();
|
|
|
|
}
|
2016-12-08 15:53:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps (initState, initProps) {
|
|
|
|
const { accountsInfo, accounts } = initState.personal;
|
|
|
|
const { owners } = initProps.wallet;
|
|
|
|
|
|
|
|
const senders = pick(accounts, owners);
|
|
|
|
|
|
|
|
return () => {
|
2016-12-30 12:28:12 +01:00
|
|
|
return { accountsInfo, senders };
|
2016-12-08 15:53:29 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-01-18 13:05:01 +01:00
|
|
|
export default connect(
|
|
|
|
mapStateToProps,
|
|
|
|
null
|
|
|
|
)(WalletSettings);
|