Proposals are able to be created using SNT
This commit is contained in:
parent
226ae6d768
commit
6128390bca
|
@ -1,8 +1,9 @@
|
||||||
import EmbarkJS from 'Embark/EmbarkJS';
|
import EmbarkJS from 'Embark/EmbarkJS';
|
||||||
import ERC20Token from 'Embark/contracts/ERC20Token';
|
import ERC20Token from 'Embark/contracts/ERC20Token';
|
||||||
import ProposalCuration from 'Embark/contracts/ProposalCuration'
|
import ProposalCuration from 'Embark/contracts/ProposalCuration';
|
||||||
|
import SNT from 'Embark/contracts/SNT';
|
||||||
import React, { Fragment } from 'react';
|
import React, { Fragment } from 'react';
|
||||||
import { Form, FormGroup, FormControl, HelpBlock, Button } from 'react-bootstrap';
|
import { Form, FormGroup, FormControl, HelpBlock, Button, Alert } from 'react-bootstrap';
|
||||||
import web3 from "Embark/web3"
|
import web3 from "Embark/web3"
|
||||||
|
|
||||||
class ProposalManager extends React.Component {
|
class ProposalManager extends React.Component {
|
||||||
|
@ -11,13 +12,11 @@ class ProposalManager extends React.Component {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
submitPrice: "Loading...",
|
submitPrice: "Loading...",
|
||||||
to: "",
|
url: "",
|
||||||
value: "",
|
title: "",
|
||||||
data: "",
|
|
||||||
description: "",
|
description: "",
|
||||||
topic: "0x00"
|
canSubmit: true
|
||||||
};
|
};
|
||||||
window['ProposalCuration'] = ProposalCuration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount(){
|
componentDidMount(){
|
||||||
|
@ -33,67 +32,96 @@ class ProposalManager extends React.Component {
|
||||||
try {
|
try {
|
||||||
let _b = await ProposalCuration.methods.getSubmitPrice(web3.eth.defaultAccount).call();
|
let _b = await ProposalCuration.methods.getSubmitPrice(web3.eth.defaultAccount).call();
|
||||||
this.setState({
|
this.setState({
|
||||||
balance: _b
|
submitPrice: _b,
|
||||||
|
canSubmit: true
|
||||||
});
|
});
|
||||||
} catch(err){
|
} catch(err){
|
||||||
console.log("Couldn't get submit price")
|
this.setState({
|
||||||
|
canSubmit: false,
|
||||||
|
submitPrice: "-"
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
render(){
|
render(){
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<h2>Add</h2>
|
{
|
||||||
<h3>Price for submitting proposals: {this.state.submitPrice}</h3>
|
!this.state.canSubmit ?
|
||||||
|
<Alert bsStyle="warning">
|
||||||
|
Account not allowed to submit proposals
|
||||||
|
</Alert>
|
||||||
|
: ''
|
||||||
|
}
|
||||||
|
<h2>Add proposal</h2>
|
||||||
|
<h3>Price: {this.state.submitPrice}</h3>
|
||||||
<Form>
|
<Form>
|
||||||
<FormGroup>
|
<FormGroup>
|
||||||
<label>
|
<label>
|
||||||
To:
|
Title:
|
||||||
<FormControl
|
<FormControl
|
||||||
type="text"
|
type="text"
|
||||||
defaultValue={this.state.to}
|
defaultValue={this.state.title}
|
||||||
onChange={(e) => this.setState({to: e.target.value }) } />
|
onChange={(e) => this.setState({title: e.target.value }) } />
|
||||||
</label>
|
</label>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
<FormGroup>
|
<FormGroup>
|
||||||
<label>
|
<label>
|
||||||
Value:
|
Description:
|
||||||
<FormControl
|
<FormControl
|
||||||
type="text"
|
type="text"
|
||||||
defaultValue={this.state.value}
|
defaultValue={this.state.description}
|
||||||
onChange={(e) => this.setState({value: e.target.value }) } />
|
onChange={(e) => this.setState({description: e.target.value }) } />
|
||||||
</label>
|
</label>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
<FormGroup>
|
<FormGroup>
|
||||||
<label>
|
<label>
|
||||||
Data:
|
URL:
|
||||||
<FormControl
|
<FormControl
|
||||||
type="text"
|
type="text"
|
||||||
defaultValue={this.state.data}
|
defaultValue={this.state.url}
|
||||||
onChange={(e) => this.setState({value: e.target.value }) } />
|
onChange={(e) => this.setState({url: e.target.value }) } />
|
||||||
</label>
|
</label>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
<FormGroup>
|
{
|
||||||
<label>
|
this.state.canSubmit ?
|
||||||
Topic:
|
<FormGroup>
|
||||||
<FormControl
|
<Button onClick={(e) => this.handleClick(e)}>Submit</Button>
|
||||||
type="text"
|
</FormGroup>
|
||||||
defaultValue={this.state.topic}
|
: ''
|
||||||
readOnly={true} />
|
}
|
||||||
</label>
|
|
||||||
</FormGroup>
|
|
||||||
<FormGroup>
|
|
||||||
<label>
|
|
||||||
Description:
|
|
||||||
<FormControl
|
|
||||||
type="text"
|
|
||||||
defaultValue={this.state.description}
|
|
||||||
onChange={(e) => this.setState({value: e.target.value }) } />
|
|
||||||
</label>
|
|
||||||
</FormGroup>
|
|
||||||
</Form>
|
</Form>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import web3 from "Embark/web3"
|
import web3 from "Embark/web3"
|
||||||
import EmbarkJS from 'Embark/EmbarkJS';
|
import EmbarkJS from 'Embark/EmbarkJS';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { Button } from 'react-bootstrap';
|
||||||
|
|
||||||
class ProposalForm extends React.Component {
|
class ProposalForm extends React.Component {
|
||||||
|
|
||||||
|
@ -9,8 +10,16 @@ class ProposalForm extends React.Component {
|
||||||
this.state = {};
|
this.state = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleClick(e){
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
render(){
|
render(){
|
||||||
return <div>TODO: Form</div>;
|
return <div>
|
||||||
|
<Button onClick={(e) => this.handleClick(e) }>Vote</Button>
|
||||||
|
</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import $ from 'jquery';
|
import $ from 'jquery';
|
||||||
import {Button} from 'react-bootstrap';
|
import { Button, Alert } from 'react-bootstrap';
|
||||||
import EmbarkJS from 'Embark/EmbarkJS';
|
import EmbarkJS from 'Embark/EmbarkJS';
|
||||||
import ProposalForm from './proposal-form';
|
import ProposalForm from './proposal-form';
|
||||||
|
|
||||||
|
@ -12,7 +12,8 @@ class Proposal extends React.Component {
|
||||||
this.state = {
|
this.state = {
|
||||||
url: null,
|
url: null,
|
||||||
title: null,
|
title: null,
|
||||||
description: null
|
description: null,
|
||||||
|
error: null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +30,6 @@ class Proposal extends React.Component {
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
if(err){
|
if(err){
|
||||||
// TODO handle error
|
|
||||||
console.log("Storage get Error => " + err.message);
|
console.log("Storage get Error => " + err.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -38,6 +38,13 @@ class Proposal extends React.Component {
|
||||||
|
|
||||||
render(){
|
render(){
|
||||||
return (<div>
|
return (<div>
|
||||||
|
{
|
||||||
|
this.state.error !== null ?
|
||||||
|
<Alert bsStyle="warning">
|
||||||
|
{ this.state.error }
|
||||||
|
</Alert>
|
||||||
|
: ''
|
||||||
|
}
|
||||||
<h3>{ this.state.title }</h3>
|
<h3>{ this.state.title }</h3>
|
||||||
<p>{ this.state.description }</p>
|
<p>{ this.state.description }</p>
|
||||||
<a href={ this.state.url } target="_blank">{ this.state.url }</a>
|
<a href={ this.state.url } target="_blank">{ this.state.url }</a>
|
||||||
|
|
|
@ -19,7 +19,6 @@ class VotingDapp extends React.Component {
|
||||||
return <div>
|
return <div>
|
||||||
<StatusBar {...this.props} />
|
<StatusBar {...this.props} />
|
||||||
<ProposalContainer />
|
<ProposalContainer />
|
||||||
<ProposalForm />
|
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue