Fix Wallet Settings Modal (#3856)

* Fixes wallet settings modal

* Fix linting
This commit is contained in:
Nicolas Gotchac 2016-12-19 13:16:59 +01:00 committed by Jaco Greeff
parent 14a9942d14
commit 670be41b62
6 changed files with 74 additions and 25 deletions

View File

@ -17,7 +17,6 @@
import React, { Component, PropTypes } from 'react'; import React, { Component, PropTypes } from 'react';
import { Form, TypedInput, Input, AddressSelect, InputAddress } from '~/ui'; import { Form, TypedInput, Input, AddressSelect, InputAddress } from '~/ui';
import { parseAbiType } from '~/util/abi';
import styles from '../createWallet.css'; import styles from '../createWallet.css';
@ -105,7 +104,7 @@ export default class WalletDetails extends Component {
value={ wallet.owners.slice() } value={ wallet.owners.slice() }
onChange={ this.onOwnersChange } onChange={ this.onOwnersChange }
accounts={ accounts } accounts={ accounts }
param={ parseAbiType('address[]') } param='address[]'
/> />
<div className={ styles.splitInput }> <div className={ styles.splitInput }>
@ -115,7 +114,7 @@ export default class WalletDetails extends Component {
value={ wallet.required } value={ wallet.required }
error={ errors.required } error={ errors.required }
onChange={ this.onRequiredChange } onChange={ this.onRequiredChange }
param={ parseAbiType('uint') } param='uint'
min={ 1 } min={ 1 }
max={ wallet.owners.length + 1 } max={ wallet.owners.length + 1 }
/> />
@ -126,7 +125,7 @@ export default class WalletDetails extends Component {
value={ wallet.daylimit } value={ wallet.daylimit }
error={ errors.daylimit } error={ errors.daylimit }
onChange={ this.onDaylimitChange } onChange={ this.onDaylimitChange }
param={ parseAbiType('uint') } param='uint'
isEth isEth
/> />
</div> </div>

View File

@ -83,6 +83,7 @@ export default class ParametersStep extends Component {
accounts={ accounts } accounts={ accounts }
onChange={ onChange } onChange={ onChange }
param={ param } param={ param }
isEth={ false }
/> />
</div> </div>
); );

View File

@ -18,7 +18,6 @@ import React, { Component, PropTypes } from 'react';
import { Checkbox, MenuItem } from 'material-ui'; import { Checkbox, MenuItem } from 'material-ui';
import { AddressSelect, Form, Input, Select, TypedInput } from '~/ui'; import { AddressSelect, Form, Input, Select, TypedInput } from '~/ui';
import { parseAbiType } from '~/util/abi';
import styles from '../executeContract.css'; import styles from '../executeContract.css';
@ -162,7 +161,8 @@ export default class DetailsStep extends Component {
error={ valuesError[index] } error={ valuesError[index] }
onChange={ onChange } onChange={ onChange }
accounts={ accounts } accounts={ accounts }
param={ parseAbiType(input.type) } param={ input.type }
isEth={ false }
/> />
</div> </div>
); );

View File

@ -22,7 +22,6 @@ import { pick } from 'lodash';
import ActionDone from 'material-ui/svg-icons/action/done'; import ActionDone from 'material-ui/svg-icons/action/done';
import ContentClear from 'material-ui/svg-icons/content/clear'; import ContentClear from 'material-ui/svg-icons/content/clear';
import NavigationArrowForward from 'material-ui/svg-icons/navigation/arrow-forward'; import NavigationArrowForward from 'material-ui/svg-icons/navigation/arrow-forward';
import { parseAbiType } from '~/util/abi';
import { Button, Modal, TxHash, BusyStep, Form, TypedInput, InputAddress, AddressSelect } from '~/ui'; import { Button, Modal, TxHash, BusyStep, Form, TypedInput, InputAddress, AddressSelect } from '~/ui';
import { fromWei } from '~/api/util/wei'; import { fromWei } from '~/api/util/wei';
@ -107,10 +106,7 @@ class WalletSettings extends Component {
return ( return (
<div> <div>
<p>You are about to make the following modifications</p> { this.renderChanges(changes) }
<div>
{ this.renderChanges(changes) }
</div>
</div> </div>
); );
@ -142,19 +138,19 @@ class WalletSettings extends Component {
value={ wallet.owners.slice() } value={ wallet.owners.slice() }
onChange={ this.store.onOwnersChange } onChange={ this.store.onOwnersChange }
accounts={ accounts } accounts={ accounts }
param={ parseAbiType('address[]') } param='address[]'
/> />
<div className={ styles.splitInput }> <div className={ styles.splitInput }>
<TypedInput <TypedInput
label='required owners' label='required owners'
hint='number of required owners to accept a transaction' hint='number of required owners to accept a transaction'
value={ wallet.require }
error={ errors.require } error={ errors.require }
onChange={ this.store.onRequireChange }
param={ parseAbiType('uint') }
min={ 1 } min={ 1 }
onChange={ this.store.onRequireChange }
max={ wallet.owners.length } max={ wallet.owners.length }
param='uint'
value={ wallet.require }
/> />
<TypedInput <TypedInput
@ -163,7 +159,7 @@ class WalletSettings extends Component {
value={ wallet.dailylimit } value={ wallet.dailylimit }
error={ errors.dailylimit } error={ errors.dailylimit }
onChange={ this.store.onDailylimitChange } onChange={ this.store.onDailylimitChange }
param={ parseAbiType('uint') } param='uint'
isEth isEth
/> />
</div> </div>
@ -173,11 +169,24 @@ class WalletSettings extends Component {
} }
renderChanges (changes) { renderChanges (changes) {
return changes.map((change, index) => ( if (changes.length === 0) {
return (
<p>No modifications have been made to the Wallet settings.</p>
);
}
const modifications = changes.map((change, index) => (
<div key={ `${change.type}_${index}` }> <div key={ `${change.type}_${index}` }>
{ this.renderChange(change) } { this.renderChange(change) }
</div> </div>
)); ));
return (
<div>
<p>You are about to make the following modifications</p>
{ modifications }
</div>
);
} }
renderChange (change) { renderChange (change) {
@ -297,6 +306,12 @@ class WalletSettings extends Component {
return done ? [ closeBtn ] : [ closeBtn, sendingBtn ]; return done ? [ closeBtn ] : [ closeBtn, sendingBtn ];
case 'CONFIRMATION': case 'CONFIRMATION':
const { changes } = this.store;
if (changes.length === 0) {
return [ closeBtn ];
}
return [ cancelBtn, sendBtn ]; return [ cancelBtn, sendBtn ];
default: default:

View File

@ -26,7 +26,7 @@ import { fromWei, toWei } from '~/api/util/wei';
import Input from '~/ui/Form/Input'; import Input from '~/ui/Form/Input';
import InputAddressSelect from '~/ui/Form/InputAddressSelect'; import InputAddressSelect from '~/ui/Form/InputAddressSelect';
import Select from '~/ui/Form/Select'; import Select from '~/ui/Form/Select';
import { ABI_TYPES } from '~/util/abi'; import { ABI_TYPES, parseAbiType } from '~/util/abi';
import styles from './typedInput.css'; import styles from './typedInput.css';
@ -34,22 +34,25 @@ export default class TypedInput extends Component {
static propTypes = { static propTypes = {
onChange: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired,
param: PropTypes.object.isRequired,
accounts: PropTypes.object, accounts: PropTypes.object,
error: PropTypes.any, error: PropTypes.any,
value: PropTypes.any,
label: PropTypes.string,
hint: PropTypes.string, hint: PropTypes.string,
min: PropTypes.number, isEth: PropTypes.bool,
label: PropTypes.string,
max: PropTypes.number, max: PropTypes.number,
isEth: PropTypes.bool min: PropTypes.number,
param: PropTypes.oneOfType([
PropTypes.object,
PropTypes.string
]).isRequired,
value: PropTypes.any
}; };
static defaultProps = { static defaultProps = {
min: null, min: null,
max: null, max: null,
isEth: false isEth: null
}; };
state = { state = {
@ -64,7 +67,26 @@ export default class TypedInput extends Component {
} }
render () { render () {
const { param, isEth } = this.props; const { param } = this.props;
if (typeof param === 'string') {
const parsedParam = parseAbiType(param);
if (parsedParam) {
return this.renderParam(parsedParam);
}
}
if (param) {
return this.renderParam(param);
}
console.error('<TypedInput>', `unkown "${param}" param passed to props`);
return null;
}
renderParam (param) {
const { isEth } = this.props;
const { type } = param; const { type } = param;
if (type === ABI_TYPES.ARRAY) { if (type === ABI_TYPES.ARRAY) {
@ -163,7 +185,16 @@ export default class TypedInput extends Component {
return this.renderDefault(); return this.renderDefault();
} }
// If the `isEth` prop is present (true or false)
// then render the ETH toggle (usefull for contract execution)
// Don't by default
if (type === ABI_TYPES.INT) { if (type === ABI_TYPES.INT) {
const { isEth } = this.props;
if (typeof isEth !== 'boolean') {
return this.renderInteger();
}
return this.renderEth(); return this.renderEth();
} }

View File

@ -143,4 +143,7 @@ export function parseAbiType (type) {
signed: true signed: true
}; };
} }
// If no matches, return null
return null;
} }