import EmbarkJS from 'Embark/EmbarkJS'; import {{contractName}} from 'Embark/contracts/{{contractName}}'; import React from 'react'; import ReactDOM from 'react-dom'; import { FormGroup, ControlLabel, FormControl, Checkbox, Button, Alert, InputGroup } from 'react-bootstrap'; class {{contractName}}UI extends React.Component { constructor (props) { super(props); this.state = { }; } render(){ return (
{{#each functions}} <{{capitalize name}}Form{{@index}} /> {{/each}}
); } } ReactDOM.render(

{{title}}

<{{contractName}}UI />
, document.getElementById('app') ); {{#each functions}} class {{capitalize name}}Form{{@index}} extends React.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){ this.state.input[name] = e.target.value; this.setState(this.state); } handleCheckbox(e, name){ this.state.input[name] = e.target.checked; this.setState(this.state); } async handleClick(e){ e.preventDefault(); this.setState({output: null, error: null, receipt: null}); try { {{#ifview stateMutability}} {{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}this.state.input.{{name}}{{#unless @last}}, {{/unless}}{{/each}}) .call() .then((result) => { {{#iflengthgt outputs 1}} this.setState({output: { {{#each outputs}} {{emptyname name @index}}: result[{{@index}}]{{#unless @last}},{{/unless}} {{/each}} }}); {{else}} this.setState({output: result}); {{/iflengthgt}} }) .catch((err) => { this.setState({error: err.message}); }); {{else}} {{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}this.state.input.{{name}}{{#unless @last}}, {{/unless}}{{/each}}) .send({ {{#if payable}} value: this.state.value, {{/if}} from: web3.eth.defaultAccount }) .then((_receipt) => { console.log(_receipt); this.setState({receipt: _receipt}) }) .catch((err) => { console.log(err); this.setState({error: err.message}); }); {{/ifview}} } catch(err) { this.setState({error: err.message}); } } render(){ return

{{name}}

{{#if inputs.length}} {{#each inputs}} {{name}} {{#ifeq type 'bool'}} this.handleCheckbox(e, '{{name}}')} /> {{else}} this.handleChange(e, '{{name}}')} /> {{/ifeq}} {{/each}} {{/if}} {{#if payable}} Value Ξ { this.setState({value: e.target.value}); }} /> wei {{/if}} { this.state.error != null ? {this.state.error} : '' } {{#ifview stateMutability}} { this.state.output != null ?

Results

{{#iflengthgt outputs 1}}
    {{#each outputs}}
  • {{emptyname name @index}}: { this.state.output.{{emptyname name @index}} }
  • {{/each}}
{{else}} {this.state.output.toString()} {{/iflengthgt}}
: '' } {{else}} { this.state.receipt != null ? {this.state.receipt.status == "0x1" ? 'Success' : 'Failure / Revert'} - Transaction Hash: {this.state.receipt.transactionHash} : '' } {{/ifview}}
; } } {{/each}}