2018-05-21 21:43:31 +00:00
|
|
|
import EmbarkJS from 'Embark/EmbarkJS';
|
|
|
|
import ERC20Token from 'Embark/contracts/ERC20Token';
|
2018-05-29 20:51:59 +00:00
|
|
|
import ProposalCuration from 'Embark/contracts/ProposalCuration';
|
|
|
|
import SNT from 'Embark/contracts/SNT';
|
2018-05-21 21:43:31 +00:00
|
|
|
import React, { Fragment } from 'react';
|
2018-05-29 20:51:59 +00:00
|
|
|
import { Form, FormGroup, FormControl, HelpBlock, Button, Alert } from 'react-bootstrap';
|
2018-05-24 14:27:28 +00:00
|
|
|
import web3 from "Embark/web3"
|
2018-05-21 21:43:31 +00:00
|
|
|
|
2018-05-24 14:27:28 +00:00
|
|
|
class ProposalManager extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
submitPrice: "Loading...",
|
2018-05-29 20:51:59 +00:00
|
|
|
url: "",
|
|
|
|
title: "",
|
2018-05-24 14:27:28 +00:00
|
|
|
description: "",
|
2018-05-29 20:51:59 +00:00
|
|
|
canSubmit: true
|
2018-05-24 14:27:28 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount(){
|
|
|
|
this.loadPrice();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(){
|
|
|
|
this.loadPrice();
|
|
|
|
}
|
|
|
|
|
|
|
|
async loadPrice(){
|
|
|
|
__embarkContext.execWhenReady(async () => {
|
|
|
|
try {
|
|
|
|
let _b = await ProposalCuration.methods.getSubmitPrice(web3.eth.defaultAccount).call();
|
|
|
|
this.setState({
|
2018-05-29 20:51:59 +00:00
|
|
|
submitPrice: _b,
|
|
|
|
canSubmit: true
|
2018-05-24 14:27:28 +00:00
|
|
|
});
|
|
|
|
} catch(err){
|
2018-05-29 20:51:59 +00:00
|
|
|
this.setState({
|
|
|
|
canSubmit: false,
|
|
|
|
submitPrice: "-"
|
|
|
|
});
|
2018-05-24 14:27:28 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-05-29 20:51:59 +00:00
|
|
|
async handleClick(){
|
|
|
|
let description = {
|
|
|
|
"url": this.state.url,
|
|
|
|
"title": this.state.title,
|
|
|
|
"description": this.state.description
|
|
|
|
};
|
|
|
|
|
|
|
|
let hexDescription = web3.utils.toHex(JSON.stringify(description));
|
|
|
|
|
|
|
|
let receipt = await SNT.methods.approve(
|
|
|
|
ProposalCuration.options.address,
|
|
|
|
this.state.submitPrice)
|
|
|
|
.send({from: web3.eth.defaultAccount, gasLimit: 1000000});
|
|
|
|
|
|
|
|
console.log(receipt);
|
|
|
|
|
|
|
|
receipt = await ProposalCuration.methods.submitProposal(
|
|
|
|
"0x00",
|
|
|
|
"0x0000000000000000000000000000000000000000",
|
|
|
|
0,
|
|
|
|
"0x00",
|
|
|
|
hexDescription
|
|
|
|
)
|
|
|
|
.send({from: web3.eth.defaultAccount, gasLimit: 1000000});
|
|
|
|
|
|
|
|
console.log(receipt);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-24 14:27:28 +00:00
|
|
|
render(){
|
|
|
|
return (
|
|
|
|
<Fragment>
|
2018-05-29 20:51:59 +00:00
|
|
|
{
|
|
|
|
!this.state.canSubmit ?
|
|
|
|
<Alert bsStyle="warning">
|
|
|
|
Account not allowed to submit proposals
|
|
|
|
</Alert>
|
|
|
|
: ''
|
|
|
|
}
|
|
|
|
<h2>Add proposal</h2>
|
|
|
|
<h3>Price: {this.state.submitPrice}</h3>
|
2018-05-24 14:27:28 +00:00
|
|
|
<Form>
|
2018-05-29 20:51:59 +00:00
|
|
|
<FormGroup>
|
|
|
|
<label>
|
|
|
|
Title:
|
|
|
|
<FormControl
|
|
|
|
type="text"
|
|
|
|
defaultValue={this.state.title}
|
|
|
|
onChange={(e) => this.setState({title: e.target.value }) } />
|
|
|
|
</label>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup>
|
|
|
|
<label>
|
|
|
|
Description:
|
|
|
|
<FormControl
|
|
|
|
type="text"
|
|
|
|
defaultValue={this.state.description}
|
|
|
|
onChange={(e) => this.setState({description: e.target.value }) } />
|
|
|
|
</label>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup>
|
|
|
|
<label>
|
|
|
|
URL:
|
|
|
|
<FormControl
|
|
|
|
type="text"
|
|
|
|
defaultValue={this.state.url}
|
|
|
|
onChange={(e) => this.setState({url: e.target.value }) } />
|
|
|
|
</label>
|
|
|
|
</FormGroup>
|
|
|
|
{
|
|
|
|
this.state.canSubmit ?
|
|
|
|
<FormGroup>
|
|
|
|
<Button onClick={(e) => this.handleClick(e)}>Submit</Button>
|
|
|
|
</FormGroup>
|
|
|
|
: ''
|
|
|
|
}
|
2018-05-24 14:27:28 +00:00
|
|
|
</Form>
|
2018-05-29 20:51:59 +00:00
|
|
|
</Fragment>
|
2018-05-24 14:27:28 +00:00
|
|
|
)
|
|
|
|
}
|
2018-05-21 21:43:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default ProposalManager;
|