From 8da0d60b42d2ea7ea4052a3c1c96f8dce85a2381 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 17 May 2018 09:30:05 -0400 Subject: [PATCH] Fixing function invokation and result showing - Booleans weren't being sent correctly (it always assumed true) - Booleans now are shown on the results - Handling result visualization when there's more than one parameter --- .../contracts/components/function-form.js | 30 ++++++++++++++++++- .../backend/contracts/components/function.js | 9 ++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/lib/modules/webserver/backend/contracts/components/function-form.js b/lib/modules/webserver/backend/contracts/components/function-form.js index 43ca43d69..31cdd61ce 100644 --- a/lib/modules/webserver/backend/contracts/components/function-form.js +++ b/lib/modules/webserver/backend/contracts/components/function-form.js @@ -89,7 +89,35 @@ class FunctionForm extends React.Component { { !this.state.error && this.state.message != null ? - {this.state.message} + { + (this.state.message !== null && typeof this.state.message === 'object') + ? + ( + + ) + : + (typeof this.state.message === "boolean" ? + (this.state.message ? 'true' : 'false') + : + this.state.message) + } : '' } diff --git a/lib/modules/webserver/backend/contracts/components/function.js b/lib/modules/webserver/backend/contracts/components/function.js index 37ff4442e..337fbf069 100644 --- a/lib/modules/webserver/backend/contracts/components/function.js +++ b/lib/modules/webserver/backend/contracts/components/function.js @@ -86,11 +86,14 @@ class Function extends React.Component { } else { if(this.props.abi.type == 'fallback') - _receipt = await this.web3.eth.sendTransaction(executionParams); + _receipt = await web3.eth.sendTransaction(executionParams); else _receipt = await this.props.contract .methods[this.props.abi.name + '(' + this.props.abi.inputs.map(input => input.type).join(',') + ')'] - .apply(null, Object.keys(fields).map(val => fields[val])) + .apply(null, Object.keys(fields).map(val => { + let input = this.props.abi.inputs.filter(x => x.name == val)[0]; + return input.type.indexOf('bool') == -1 ? fields[val] : (fields[val].toLowerCase() === 'true') + })) [this._getMethodType()](executionParams) if(this._getMethodType() == 'call'){ @@ -196,7 +199,7 @@ class Function extends React.Component { _getFunctionParamString(){ if(this.props.abi.type == 'fallback') return ''; return this.props.abi.inputs - .map((input, i) => (input.type.indexOf('int') == -1 ? '"' : '') + (this.state.fields[input.name] || (input.type.indexOf('int') == -1 ? '' : '0')) + (input.type.indexOf('int') == -1 ? '"' : '')) + .map((input, i) => (input.type.indexOf('int') == -1 && input.type.indexOf('bool') == -1 ? '"' : '') + (this.state.fields[input.name] || (input.type.indexOf('int') == -1 ? '' : '0')) + (input.type.indexOf('int') == -1 ? '"' : '')) .join(', '); }