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
This commit is contained in:
Richard Ramos 2018-05-17 09:30:05 -04:00 committed by Pascal Precht
parent 42db8258e0
commit 8da0d60b42
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
2 changed files with 35 additions and 4 deletions

View File

@ -89,7 +89,35 @@ class FunctionForm extends React.Component {
{
!this.state.error && this.state.message != null
?
<React.Fragment>{this.state.message}</React.Fragment>
<React.Fragment>{
(this.state.message !== null && typeof this.state.message === 'object')
?
(
<ul>
{
this.props.abi.outputs.filter(x => x.name !== "").length > 0
?
Object.keys(this.state.message).map((key, index) => {
if(isNaN(key)){
return <li key={index}>{key}: {this.state.message[key]}</li>
} else {
return '';
}
})
:
Object.keys(this.state.message).map((key, index) => {
return <li key={index}>{key}: {this.state.message[key]}</li>
})
}
</ul>
)
:
(typeof this.state.message === "boolean" ?
(this.state.message ? 'true' : 'false')
:
this.state.message)
}</React.Fragment>
: '' }
</div>

View File

@ -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(', ');
}