mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-09 21:46:12 +00:00
Base logic for invoking send functions and showin results
This commit is contained in:
parent
2679e60860
commit
a043816750
@ -21,7 +21,8 @@ class {{capitalize name}}_{{@index}}_Form extends React.Component {
|
|||||||
{{#ifview stateMutability}}
|
{{#ifview stateMutability}}
|
||||||
output: null,
|
output: null,
|
||||||
{{/ifview}}
|
{{/ifview}}
|
||||||
error: null
|
error: null,
|
||||||
|
mined: null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,10 +38,10 @@ class {{capitalize name}}_{{@index}}_Form extends React.Component {
|
|||||||
|
|
||||||
async handleClick(e){
|
async handleClick(e){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.setState({output: null, error: null});
|
this.setState({output: null, error: null, receipt: null});
|
||||||
|
|
||||||
{{#ifview stateMutability}}
|
|
||||||
try {
|
try {
|
||||||
|
{{#ifview stateMutability}}
|
||||||
{{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}this.state.input.{{name}}{{#unless @last}}, {{/unless}}{{/each}})
|
{{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}this.state.input.{{name}}{{#unless @last}}, {{/unless}}{{/each}})
|
||||||
.call()
|
.call()
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
@ -57,44 +58,56 @@ class {{capitalize name}}_{{@index}}_Form extends React.Component {
|
|||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
this.setState({error: err.message});
|
this.setState({error: err.message});
|
||||||
});
|
});
|
||||||
|
{{else}}
|
||||||
|
{{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}this.state.input.{{name}}{{#unless @last}}, {{/unless}}{{/each}})
|
||||||
|
.send({
|
||||||
|
from: web3.eth.defaultAccount
|
||||||
|
})
|
||||||
|
.then((_receipt) => {
|
||||||
|
console.log(_receipt);
|
||||||
|
this.setState({receipt: _receipt})
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
this.setState({error: err.message});
|
||||||
|
});
|
||||||
|
// TODO payable
|
||||||
|
{{/ifview}}
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
this.setState({error: err.message});
|
this.setState({error: err.message});
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO show on screen
|
|
||||||
{{/ifview}}
|
|
||||||
|
|
||||||
// TODO validate
|
// TODO validate
|
||||||
}
|
}
|
||||||
|
|
||||||
render(){
|
render(){
|
||||||
return <div className="formSection">
|
return <div className="formSection">
|
||||||
<h3>{{name}}</h3>
|
<h3>{{name}}</h3>
|
||||||
|
<form>
|
||||||
|
{{#if inputs.length}}
|
||||||
|
{{#each inputs}}
|
||||||
|
<FormGroup>
|
||||||
|
<ControlLabel>{{name}}</ControlLabel>
|
||||||
|
{{#ifeq type 'bool'}}
|
||||||
|
<Checkbox
|
||||||
|
onClick={(e) => this.handleCheckbox(e, '{{name}}')}
|
||||||
|
/>
|
||||||
|
{{else}}
|
||||||
|
<FormControl
|
||||||
|
type="text"
|
||||||
|
defaultValue={ this.state.input.{{name}} }
|
||||||
|
placeholder="{{type}}"
|
||||||
|
onChange={(e) => this.handleChange(e, '{{name}}')}
|
||||||
|
/>
|
||||||
|
{{/ifeq}}
|
||||||
|
</FormGroup>
|
||||||
|
{{/each}}
|
||||||
|
{{/if}}
|
||||||
{
|
{
|
||||||
this.state.error != null ?
|
this.state.error != null ?
|
||||||
<Alert bsStyle="danger">{this.state.error}</Alert>
|
<Alert bsStyle="danger">{this.state.error}</Alert>
|
||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
<form>
|
|
||||||
{{#if inputs.length}}
|
|
||||||
{{#each inputs}}
|
|
||||||
<FormGroup>
|
|
||||||
<ControlLabel>{{name}}</ControlLabel>
|
|
||||||
{{#ifeq type 'bool'}}
|
|
||||||
<Checkbox
|
|
||||||
onClick={(e) => this.handleCheckbox(e, '{{name}}')}
|
|
||||||
/>
|
|
||||||
{{else}}
|
|
||||||
<FormControl
|
|
||||||
type="text"
|
|
||||||
defaultValue={ this.state.input.{{name}} }
|
|
||||||
placeholder="{{type}}"
|
|
||||||
onChange={(e) => this.handleChange(e, '{{name}}')}
|
|
||||||
/>
|
|
||||||
{{/ifeq}}
|
|
||||||
</FormGroup>
|
|
||||||
{{/each}}
|
|
||||||
{{/if}}
|
|
||||||
{{#ifview stateMutability}}
|
{{#ifview stateMutability}}
|
||||||
<Button type="submit" bsStyle="primary" onClick={(e) => this.handleClick(e)}>Call</Button>
|
<Button type="submit" bsStyle="primary" onClick={(e) => this.handleClick(e)}>Call</Button>
|
||||||
{
|
{
|
||||||
@ -113,7 +126,13 @@ class {{capitalize name}}_{{@index}}_Form extends React.Component {
|
|||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
|
{{else}}
|
||||||
|
<Button type="submit" bsStyle="primary" onClick={(e) => this.handleClick(e)}>Send</Button>
|
||||||
|
{
|
||||||
|
this.state.receipt != null ?
|
||||||
|
<Alert bsStyle={this.state.receipt.status == "0x1" ? 'success' : 'danger'}>{this.state.receipt.status == "0x1" ? 'Success' : 'Failure / Revert'} - Transaction Hash: {this.state.receipt.transactionHash}</Alert>
|
||||||
|
: ''
|
||||||
|
}
|
||||||
{{/ifview}}
|
{{/ifview}}
|
||||||
</form>
|
</form>
|
||||||
</div>;
|
</div>;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user