import EmbarkJS from 'Embark/EmbarkJS'; import {{contractName}} from 'Embark/contracts/{{contractName}}'; import React, { Component, Fragment } from 'react'; import ReactDOM from 'react-dom'; import { FormGroup, ControlLabel, FormControl, Checkbox, Button, Alert, InputGroup } from 'react-bootstrap'; {{#each functions}} class {{capitalize name}}Form{{@index}} extends Component { constructor(props){ super(props); this.state = { {{#if inputs.length}} input: { {{#each inputs}} {{name}}: {{#ifeq type 'bool'}}false{{else}}''{{/ifeq}}{{#unless @last}},{{/unless}} {{/each}} }, {{/if}} {{#if payable}} value: 0, {{/if}} {{#ifview stateMutability}} output: null, {{/ifview}} error: null, mined: null }; } handleChange(e, name){ const {input} = this.state; input[name] = e.target.value; this.setState({input}); } handleCheckbox(e, name){ const {input} = this.state; input[name] = e.target.checked; this.setState({input}); } async handleClick(e){ e.preventDefault(); const {input, value} = this.state; this.setState({output: null, error: null, receipt: null}); try { {{#ifview stateMutability}} const result = await {{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}input.{{name}}{{#unless @last}}, {{/unless}}{{/each}}).call() {{#iflengthgt outputs 1}} this.setState({output: { {{#each outputs}} {{emptyname name @index}}: result[{{@index}}]{{#unless @last}},{{/unless}} {{/each}} }}); {{else}} this.setState({output: result}); {{/iflengthgt}} {{else}} const toSend = {{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}input.{{name}}{{#unless @last}}, {{/unless}}{{/each}}); const estimatedGas = await toSend.estimateGas({from: web3.eth.defaultAccount}); const receipt = await toSend.send({ {{#if payable}} value: value, {{/if}} from: web3.eth.defaultAccount, gasLimit: estimatedGas }); console.log(receipt); this.setState({receipt}); {{/ifview}} } catch(err) { console.error(err); this.setState({error: err.message}); } } render(){ const {input, value, error, output, receipt} = this.state; return