Change contract Execute bool values & query bool value display (#3024)

* Allow for boolean value selection

* Updated

* Explicitly display bool as true/false (string)

* Really fix boolean display
This commit is contained in:
Jaco Greeff 2016-11-01 18:42:36 +01:00 committed by GitHub
parent 556827400c
commit 314eb59081
3 changed files with 37 additions and 10 deletions

View File

@ -124,6 +124,7 @@ export default class DetailsStep extends Component {
return (func.abi.inputs || []).map((input, index) => { return (func.abi.inputs || []).map((input, index) => {
const onChange = (event, value) => onValueChange(event, index, value); const onChange = (event, value) => onValueChange(event, index, value);
const onSelect = (event, _index, value) => onValueChange(event, index, value);
const onSubmit = (value) => onValueChange(null, index, value); const onSubmit = (value) => onValueChange(null, index, value);
const label = `${input.name}: ${input.type}`; const label = `${input.name}: ${input.type}`;
let inputbox; let inputbox;
@ -141,6 +142,24 @@ export default class DetailsStep extends Component {
); );
break; break;
case 'bool':
const boolitems = ['false', 'true'].map((bool) => {
return (
<MenuItem
key={ bool }
value={ bool }
label={ bool }>{ bool }</MenuItem>
);
});
inputbox = (
<Select
label={ label }
value={ values[index] ? 'true' : 'false' }
error={ valuesError[index] }
onChange={ onSelect }>{ boolitems }</Select>
);
break;
default: default:
inputbox = ( inputbox = (
<Input <Input

View File

@ -150,6 +150,9 @@ export default class ExecuteContract extends Component {
case 'address': case 'address':
return '0x'; return '0x';
case 'bool':
return false;
case 'bytes': case 'bytes':
return '0x'; return '0x';
@ -170,17 +173,16 @@ export default class ExecuteContract extends Component {
onValueChange = (event, index, _value) => { onValueChange = (event, index, _value) => {
const { func, values, valuesError } = this.state; const { func, values, valuesError } = this.state;
const input = func.inputs.find((input, _index) => index === _index); const input = func.inputs.find((input, _index) => index === _index);
let value; let value = _value;
let valueError; let valueError = null;
switch (input.kind.type) { switch (input.kind.type) {
case 'address': case 'bool':
value = _value; value = _value === 'true';
valueError = validateAddress(_value).addressError;
break; break;
default:
value = _value; case 'address':
valueError = null; valueError = validateAddress(_value).addressError;
break; break;
} }

View File

@ -108,15 +108,21 @@ export default class Queries extends Component {
} }
renderValue (value) { renderValue (value) {
if (!value) return null; if (typeof value === 'undefined') {
return null;
}
const { api } = this.context; const { api } = this.context;
let valueToDisplay = value.toString(); let valueToDisplay = null;
if (api.util.isInstanceOf(value, BigNumber)) { if (api.util.isInstanceOf(value, BigNumber)) {
valueToDisplay = value.toFormat(0); valueToDisplay = value.toFormat(0);
} else if (api.util.isArray(value)) { } else if (api.util.isArray(value)) {
valueToDisplay = api.util.bytesToHex(value); valueToDisplay = api.util.bytesToHex(value);
} else if (typeof value === 'boolean') {
valueToDisplay = value ? 'true' : 'false';
} else {
valueToDisplay = value.toString();
} }
return ( return (