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

Show contract parameters in MethodDecoding #4024

Merged
merged 6 commits into from
Jan 5, 2017
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 7 additions & 1 deletion js/src/abi/spec/param.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export default class Param {
}

static toParams (params) {
return params.map((param) => new Param(param.name, param.type));
return params.map((param) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we just add a relevant test that verifies both behaviours? (these should be one that just verifies the original)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if (param instanceof Param) {
return param;
}

return new Param(param.name, param.type);
});
}
}
12 changes: 9 additions & 3 deletions js/src/api/util/decode.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export function decodeCallData (data) {

if (data.substr(0, 2) === '0x') {
return decodeCallData(data.slice(2));
} else if (data.length < 8) {
}

if (data.length < 8) {
throw new Error('Input to decodeCallData should be method signature + data');
}

Expand All @@ -42,10 +44,14 @@ export function decodeCallData (data) {
export function decodeMethodInput (methodAbi, paramdata) {
if (!methodAbi) {
throw new Error('decodeMethodInput should receive valid method-specific ABI');
} else if (paramdata && paramdata.length) {
}

if (paramdata && paramdata.length) {
if (!isHex(paramdata)) {
throw new Error('Input to decodeMethodInput should be a hex value');
} else if (paramdata.substr(0, 2) === '0x') {
}

if (paramdata.substr(0, 2) === '0x') {
return decodeMethodInput(methodAbi, paramdata.slice(2));
}
}
Expand Down
8 changes: 5 additions & 3 deletions js/src/ui/Form/AddressSelect/addressSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class AddressSelect extends Component {
// Optional props
allowCopy: PropTypes.bool,
allowInput: PropTypes.bool,
className: PropTypes.string,
disabled: PropTypes.bool,
error: nodeOrStringProptype(),
hint: nodeOrStringProptype(),
Expand Down Expand Up @@ -123,13 +124,14 @@ class AddressSelect extends Component {

renderInput () {
const { focused } = this.state;
const { accountsInfo, allowCopy, disabled, error, hint, label, readOnly, value } = this.props;
const { accountsInfo, allowCopy, className, disabled, error, hint, label, readOnly, value } = this.props;

const input = (
<InputAddress
accountsInfo={ accountsInfo }
allowCopy={ allowCopy }
disabled={ disabled }
className={ className }
disabled={ disabled || readOnly }
error={ error }
hint={ hint }
focused={ focused }
Expand Down Expand Up @@ -534,7 +536,7 @@ class AddressSelect extends Component {
});
}

handleFocus = () => {
handleFocus = (e) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the (unused) variable here? Consider at least a description name - no e that can be anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Forgot to remove this one

const { disabled, readOnly } = this.props;

if (disabled || readOnly) {
Expand Down
11 changes: 9 additions & 2 deletions js/src/ui/Form/InputAddress/inputAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,19 @@ class InputAddress extends Component {
containerClasses.push(styles.small);
}

const props = {};

if (!readOnly && !disabled) {
props.focused = focused;
}

return (
<div className={ containerClasses.join(' ') }>
<Input
allowCopy={ allowCopy && ((disabled || readOnly) ? value : false) }
className={ classes.join(' ') }
disabled={ disabled }
error={ error }
focused={ focused }
hideUnderline={ hideUnderline }
hint={ hint }
label={ label }
Expand All @@ -96,7 +101,9 @@ class InputAddress extends Component {
text && account
? account.name
: (nullName || value)
} />
}
{ ...props }
/>
{ icon }
</div>
);
Expand Down
4 changes: 3 additions & 1 deletion js/src/ui/Form/InputAddressSelect/inputAddressSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class InputAddressSelect extends Component {
contracts: PropTypes.object.isRequired,

allowCopy: PropTypes.bool,
className: PropTypes.string,
error: PropTypes.string,
hint: PropTypes.string,
label: PropTypes.string,
Expand All @@ -36,13 +37,14 @@ class InputAddressSelect extends Component {
};

render () {
const { accounts, allowCopy, contacts, contracts, label, hint, error, value, onChange, readOnly } = this.props;
const { accounts, allowCopy, className, contacts, contracts, label, hint, error, value, onChange, readOnly } = this.props;

return (
<AddressSelect
allowCopy={ allowCopy }
allowInput
accounts={ accounts }
className={ className }
contacts={ contacts }
contracts={ contracts }
error={ error }
Expand Down
35 changes: 27 additions & 8 deletions js/src/ui/Form/TypedInput/typedInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default class TypedInput extends Component {

accounts: PropTypes.object,
allowCopy: PropTypes.bool,
className: PropTypes.string,
error: PropTypes.any,
hint: PropTypes.string,
isEth: PropTypes.bool,
Expand Down Expand Up @@ -91,7 +92,7 @@ export default class TypedInput extends Component {
const { type } = param;

if (type === ABI_TYPES.ARRAY) {
const { accounts, label, value = param.default } = this.props;
const { accounts, className, label, value = param.default } = this.props;
const { subtype, length } = param;

const fixedLength = !!length;
Expand All @@ -107,6 +108,7 @@ export default class TypedInput extends Component {
<TypedInput
accounts={ accounts }
allowCopy={ allowCopy }
className={ className }
key={ `${subtype.type}_${index}` }
onChange={ onChange }
param={ subtype }
Expand Down Expand Up @@ -236,17 +238,30 @@ export default class TypedInput extends Component {
);
}

getNumberValue (value) {
if (!value) {
return value;
}

const rawValue = typeof value === 'string'
? value.replace(/,/g, '')
: value;

return new BigNumber(rawValue);
}

renderInteger (value = this.props.value, onChange = this.onChange) {
const { allowCopy, label, error, hint, min, max, readOnly } = this.props;
const { allowCopy, className, label, error, hint, min, max, readOnly } = this.props;
const param = this.getParam();

const realValue = value
? (new BigNumber(value))[readOnly ? 'toFormat' : 'toNumber']()
? this.getNumberValue(value)[readOnly ? 'toFormat' : 'toNumber']()
Copy link
Contributor

Choose a reason for hiding this comment

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

This will probably break when getNumberValue returns from the first test, i.e. where it is null or undefined

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well it checks if value is truthy before. Agreed it could be better though

: value;

return (
<Input
allowCopy={ allowCopy }
className={ className }
label={ label }
hint={ hint }
value={ realValue }
Expand All @@ -269,16 +284,17 @@ export default class TypedInput extends Component {
* @see https://github.com/facebook/react/issues/1549
*/
renderFloat (value = this.props.value, onChange = this.onChange) {
const { allowCopy, label, error, hint, min, max, readOnly } = this.props;
const { allowCopy, className, label, error, hint, min, max, readOnly } = this.props;
const param = this.getParam();

const realValue = value
? (new BigNumber(value))[readOnly ? 'toFormat' : 'toNumber']()
? this.getNumberValue(value)[readOnly ? 'toFormat' : 'toNumber']()
Copy link
Contributor

Choose a reason for hiding this comment

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

Same breakage comment here since the function may return something without toFormat/toNumber

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above

: value;

return (
<Input
allowCopy={ allowCopy }
className={ className }
label={ label }
hint={ hint }
value={ realValue }
Expand All @@ -293,11 +309,12 @@ export default class TypedInput extends Component {
}

renderDefault () {
const { allowCopy, label, value, error, hint, readOnly } = this.props;
const { allowCopy, className, label, value, error, hint, readOnly } = this.props;

return (
<Input
allowCopy={ allowCopy }
className={ className }
label={ label }
hint={ hint }
value={ value }
Expand All @@ -309,12 +326,13 @@ export default class TypedInput extends Component {
}

renderAddress () {
const { accounts, allowCopy, label, value, error, hint, readOnly } = this.props;
const { accounts, allowCopy, className, label, value, error, hint, readOnly } = this.props;

return (
<InputAddressSelect
allowCopy={ allowCopy }
accounts={ accounts }
className={ className }
error={ error }
hint={ hint }
label={ label }
Expand All @@ -326,7 +344,7 @@ export default class TypedInput extends Component {
}

renderBoolean () {
const { allowCopy, label, value, error, hint, readOnly } = this.props;
const { allowCopy, className, label, value, error, hint, readOnly } = this.props;

if (readOnly) {
return this.renderDefault();
Expand All @@ -346,6 +364,7 @@ export default class TypedInput extends Component {
return (
<Select
allowCopy={ allowCopy }
className={ className }
error={ error }
hint={ hint }
label={ label }
Expand Down
58 changes: 29 additions & 29 deletions js/src/ui/MethodDecoding/methodDecoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import BigNumber from 'bignumber.js';
import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import CircularProgress from 'material-ui/CircularProgress';

import { Input, InputAddress } from '../Form';
import { TypedInput, InputAddress } from '../Form';
import MethodDecodingStore from './methodDecodingStore';

import styles from './methodDecoding.css';
Expand Down Expand Up @@ -245,6 +244,7 @@ class MethodDecoding extends Component {

renderDeploy () {
const { historic, transaction } = this.props;
const { methodInputs } = this.state;

if (!historic) {
return (
Expand All @@ -261,6 +261,14 @@ class MethodDecoding extends Component {
</div>

{ this.renderAddressName(transaction.creates, false) }

<div>
{ methodInputs && methodInputs.length ? 'with the following parameters:' : ''}
</div>

<div className={ styles.inputs }>
{ this.renderInputs() }
</div>
</div>
);
}
Expand Down Expand Up @@ -364,39 +372,31 @@ class MethodDecoding extends Component {
renderInputs () {
const { methodInputs } = this.state;

return methodInputs.map((input, index) => {
switch (input.type) {
case 'address':
return (
<InputAddress
disabled
text
key={ index }
className={ styles.input }
value={ input.value }
label={ input.type } />
);

default:
return (
<Input
readOnly
allowCopy
key={ index }
className={ styles.input }
value={ this.renderValue(input.value) }
label={ input.type } />
);
}
if (!methodInputs || methodInputs.length === 0) {
return null;
}

const inputs = methodInputs.map((input, index) => {
return (
<TypedInput
allowCopy
className={ styles.input }
label={ input.type }
key={ index }
param={ input.type }
readOnly
value={ this.renderValue(input.value) }
/>
);
});

return inputs;
}

renderValue (value) {
const { api } = this.context;

if (api.util.isInstanceOf(value, BigNumber)) {
return value.toFormat(0);
} else if (api.util.isArray(value)) {
if (api.util.isArray(value)) {
return api.util.bytesToHex(value);
}

Expand Down
Loading