Alert for error invoking functions

This commit is contained in:
Richard Ramos 2018-05-11 10:13:42 -04:00 committed by Pascal Precht
parent e7d435f03d
commit 10c5b64b1c
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D

View File

@ -3,7 +3,7 @@ import {{contractName}} from 'Embark/contracts/{{contractName}}';
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import { FormGroup, ControlLabel, FormControl, Checkbox, Button } from 'react-bootstrap'; import { FormGroup, ControlLabel, FormControl, Checkbox, Button, Alert } from 'react-bootstrap';
{{#each functions}} {{#each functions}}
@ -21,7 +21,7 @@ class {{capitalize name}}_{{@index}}_Form extends React.Component {
{{#ifview stateMutability}} {{#ifview stateMutability}}
output: null, output: null,
{{/ifview}} {{/ifview}}
message: '' error: null
}; };
} }
@ -37,22 +37,29 @@ class {{capitalize name}}_{{@index}}_Form extends React.Component {
async handleClick(e){ async handleClick(e){
e.preventDefault(); e.preventDefault();
this.setState({output: null}); this.setState({output: null, error: null});
{{#ifview stateMutability}} {{#ifview stateMutability}}
{{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}this.state.input.{{name}}{{#unless @last}}, {{/unless}}{{/each}}) try {
.call() {{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}this.state.input.{{name}}{{#unless @last}}, {{/unless}}{{/each}})
.then((result) => { .call()
{{#iflengthgt outputs 1}} .then((result) => {
this.setState({output: { {{#iflengthgt outputs 1}}
{{#each outputs}} this.setState({output: {
{{emptyname name @index}}: result[{{@index}}]{{#unless @last}},{{/unless}} {{#each outputs}}
{{/each}} {{emptyname name @index}}: result[{{@index}}]{{#unless @last}},{{/unless}}
}}); {{/each}}
{{else}} }});
this.setState({output: result}); {{else}}
{{/iflengthgt}} this.setState({output: result});
}); {{/iflengthgt}}
})
.catch((err) => {
this.setState({error: err.message});
});
} catch(err) {
this.setState({error: err.message});
}
// TODO show on screen // TODO show on screen
{{/ifview}} {{/ifview}}
@ -63,6 +70,11 @@ class {{capitalize name}}_{{@index}}_Form extends React.Component {
render(){ render(){
return <div className="formSection"> return <div className="formSection">
<h3>{{name}}</h3> <h3>{{name}}</h3>
{
this.state.error != null ?
<Alert bsStyle="danger">{this.state.error}</Alert>
: ''
}
<form> <form>
{{#if inputs.length}} {{#if inputs.length}}
{{#each inputs}} {{#each inputs}}