From 314eb59081a299b42ee77b99141127798c96fa60 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 1 Nov 2016 18:42:36 +0100 Subject: [PATCH] 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 --- .../DetailsStep/detailsStep.js | 19 +++++++++++++++++++ .../modals/ExecuteContract/executeContract.js | 18 ++++++++++-------- js/src/views/Contract/Queries/queries.js | 10 ++++++++-- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/js/src/modals/ExecuteContract/DetailsStep/detailsStep.js b/js/src/modals/ExecuteContract/DetailsStep/detailsStep.js index 33d23fe5c..b549abb18 100644 --- a/js/src/modals/ExecuteContract/DetailsStep/detailsStep.js +++ b/js/src/modals/ExecuteContract/DetailsStep/detailsStep.js @@ -124,6 +124,7 @@ export default class DetailsStep extends Component { return (func.abi.inputs || []).map((input, index) => { 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 label = `${input.name}: ${input.type}`; let inputbox; @@ -141,6 +142,24 @@ export default class DetailsStep extends Component { ); break; + case 'bool': + const boolitems = ['false', 'true'].map((bool) => { + return ( + { bool } + ); + }); + inputbox = ( + + ); + break; + default: inputbox = ( { const { func, values, valuesError } = this.state; const input = func.inputs.find((input, _index) => index === _index); - let value; - let valueError; + let value = _value; + let valueError = null; switch (input.kind.type) { - case 'address': - value = _value; - valueError = validateAddress(_value).addressError; + case 'bool': + value = _value === 'true'; break; - default: - value = _value; - valueError = null; + + case 'address': + valueError = validateAddress(_value).addressError; break; } diff --git a/js/src/views/Contract/Queries/queries.js b/js/src/views/Contract/Queries/queries.js index 915acd258..a2dcba16e 100644 --- a/js/src/views/Contract/Queries/queries.js +++ b/js/src/views/Contract/Queries/queries.js @@ -108,15 +108,21 @@ export default class Queries extends Component { } renderValue (value) { - if (!value) return null; + if (typeof value === 'undefined') { + return null; + } const { api } = this.context; - let valueToDisplay = value.toString(); + let valueToDisplay = null; if (api.util.isInstanceOf(value, BigNumber)) { valueToDisplay = value.toFormat(0); } else if (api.util.isArray(value)) { valueToDisplay = api.util.bytesToHex(value); + } else if (typeof value === 'boolean') { + valueToDisplay = value ? 'true' : 'false'; + } else { + valueToDisplay = value.toString(); } return (