Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Fix Wallet Settings Modal #3856

Merged
merged 2 commits into from
Dec 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions js/src/modals/CreateWallet/WalletDetails/walletDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import React, { Component, PropTypes } from 'react';

import { Form, TypedInput, Input, AddressSelect, InputAddress } from '~/ui';
import { parseAbiType } from '~/util/abi';

import styles from '../createWallet.css';

Expand Down Expand Up @@ -105,7 +104,7 @@ export default class WalletDetails extends Component {
value={ wallet.owners.slice() }
onChange={ this.onOwnersChange }
accounts={ accounts }
param={ parseAbiType('address[]') }
param='address[]'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would have been good to just order here, however not a crisis.

/>

<div className={ styles.splitInput }>
Expand All @@ -115,7 +114,7 @@ export default class WalletDetails extends Component {
value={ wallet.required }
error={ errors.required }
onChange={ this.onRequiredChange }
param={ parseAbiType('uint') }
param='uint'
min={ 1 }
max={ wallet.owners.length + 1 }
/>
Expand All @@ -126,7 +125,7 @@ export default class WalletDetails extends Component {
value={ wallet.daylimit }
error={ errors.daylimit }
onChange={ this.onDaylimitChange }
param={ parseAbiType('uint') }
param='uint'
isEth
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export default class ParametersStep extends Component {
accounts={ accounts }
onChange={ onChange }
param={ param }
isEth={ false }
/>
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions js/src/modals/ExecuteContract/DetailsStep/detailsStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import React, { Component, PropTypes } from 'react';
import { Checkbox, MenuItem } from 'material-ui';

import { AddressSelect, Form, Input, Select, TypedInput } from '~/ui';
import { parseAbiType } from '~/util/abi';

import styles from '../executeContract.css';

Expand Down Expand Up @@ -162,7 +161,8 @@ export default class DetailsStep extends Component {
error={ valuesError[index] }
onChange={ onChange }
accounts={ accounts }
param={ parseAbiType(input.type) }
param={ input.type }
isEth={ false }
/>
</div>
);
Expand Down
37 changes: 26 additions & 11 deletions js/src/modals/WalletSettings/walletSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { pick } from 'lodash';
import ActionDone from 'material-ui/svg-icons/action/done';
import ContentClear from 'material-ui/svg-icons/content/clear';
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 { fromWei } from '~/api/util/wei';
Expand Down Expand Up @@ -107,10 +106,7 @@ class WalletSettings extends Component {

return (
<div>
<p>You are about to make the following modifications</p>
<div>
{ this.renderChanges(changes) }
</div>
{ this.renderChanges(changes) }
</div>
);

Expand Down Expand Up @@ -142,19 +138,19 @@ class WalletSettings extends Component {
value={ wallet.owners.slice() }
onChange={ this.store.onOwnersChange }
accounts={ accounts }
param={ parseAbiType('address[]') }
param='address[]'
/>

<div className={ styles.splitInput }>
<TypedInput
label='required owners'
hint='number of required owners to accept a transaction'
value={ wallet.require }
error={ errors.require }
onChange={ this.store.onRequireChange }
param={ parseAbiType('uint') }
min={ 1 }
onChange={ this.store.onRequireChange }
max={ wallet.owners.length }
param='uint'
value={ wallet.require }
/>

<TypedInput
Expand All @@ -163,7 +159,7 @@ class WalletSettings extends Component {
value={ wallet.dailylimit }
error={ errors.dailylimit }
onChange={ this.store.onDailylimitChange }
param={ parseAbiType('uint') }
param='uint'
isEth
/>
</div>
Expand All @@ -173,11 +169,24 @@ class WalletSettings extends Component {
}

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}` }>
{ this.renderChange(change) }
</div>
));

return (
<div>
<p>You are about to make the following modifications</p>
{ modifications }
</div>
);
}

renderChange (change) {
Expand Down Expand Up @@ -297,6 +306,12 @@ class WalletSettings extends Component {
return done ? [ closeBtn ] : [ closeBtn, sendingBtn ];

case 'CONFIRMATION':
const { changes } = this.store;

if (changes.length === 0) {
return [ closeBtn ];
}

return [ cancelBtn, sendBtn ];

default:
Expand Down
47 changes: 39 additions & 8 deletions js/src/ui/Form/TypedInput/typedInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,33 @@ import { fromWei, toWei } from '~/api/util/wei';
import Input from '~/ui/Form/Input';
import InputAddressSelect from '~/ui/Form/InputAddressSelect';
import Select from '~/ui/Form/Select';
import { ABI_TYPES } from '~/util/abi';
import { ABI_TYPES, parseAbiType } from '~/util/abi';

import styles from './typedInput.css';

export default class TypedInput extends Component {

static propTypes = {
onChange: PropTypes.func.isRequired,
param: PropTypes.object.isRequired,

accounts: PropTypes.object,
error: PropTypes.any,
value: PropTypes.any,
label: PropTypes.string,
hint: PropTypes.string,
min: PropTypes.number,
isEth: PropTypes.bool,
label: PropTypes.string,
max: PropTypes.number,
isEth: PropTypes.bool
min: PropTypes.number,
param: PropTypes.oneOfType([
PropTypes.object,
PropTypes.string
]).isRequired,
value: PropTypes.any
};

static defaultProps = {
min: null,
max: null,
isEth: false
isEth: null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null for bool? Going to run into issues again, need to stop doing tri-states.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively just fix the PropTypes to be explicit on what it required, null or bool

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes missed that one. The idea is just that by default it's using the given param, but if isEth is passed, then it will show the ETH toggle. If isEth is true => default to ETH value, if not, default to integer value. Will change the PropTypes though

};

state = {
Expand All @@ -64,7 +67,26 @@ export default class TypedInput extends Component {
}

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;

if (type === ABI_TYPES.ARRAY) {
Expand Down Expand Up @@ -163,7 +185,16 @@ export default class TypedInput extends Component {
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) {
const { isEth } = this.props;

if (typeof isEth !== 'boolean') {
return this.renderInteger();
}

return this.renderEth();
}

Expand Down
3 changes: 3 additions & 0 deletions js/src/util/abi.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,7 @@ export function parseAbiType (type) {
signed: true
};
}

// If no matches, return null
return null;
}