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 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 { Form, FormGroup, FormControl, HelpBlock, Button } from 'react-bootstrap';
|
||||
import { Form, FormGroup, FormControl, HelpBlock, Button, Alert } from 'react-bootstrap';
|
||||
import web3 from "Embark/web3"
|
||||
|
||||
class ProposalManager extends React.Component {
|
||||
|
@ -11,13 +12,11 @@ class ProposalManager extends React.Component {
|
|||
super(props);
|
||||
this.state = {
|
||||
submitPrice: "Loading...",
|
||||
to: "",
|
||||
value: "",
|
||||
data: "",
|
||||
url: "",
|
||||
title: "",
|
||||
description: "",
|
||||
topic: "0x00"
|
||||
canSubmit: true
|
||||
};
|
||||
window['ProposalCuration'] = ProposalCuration;
|
||||
}
|
||||
|
||||
componentDidMount(){
|
||||
|
@ -33,54 +32,67 @@ class ProposalManager extends React.Component {
|
|||
try {
|
||||
let _b = await ProposalCuration.methods.getSubmitPrice(web3.eth.defaultAccount).call();
|
||||
this.setState({
|
||||
balance: _b
|
||||
submitPrice: _b,
|
||||
canSubmit: true
|
||||
});
|
||||
} 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(){
|
||||
return (
|
||||
<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>
|
||||
<FormGroup>
|
||||
<label>
|
||||
To:
|
||||
Title:
|
||||
<FormControl
|
||||
type="text"
|
||||
defaultValue={this.state.to}
|
||||
onChange={(e) => this.setState({to: e.target.value }) } />
|
||||
</label>
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<label>
|
||||
Value:
|
||||
<FormControl
|
||||
type="text"
|
||||
defaultValue={this.state.value}
|
||||
onChange={(e) => this.setState({value: e.target.value }) } />
|
||||
</label>
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<label>
|
||||
Data:
|
||||
<FormControl
|
||||
type="text"
|
||||
defaultValue={this.state.data}
|
||||
onChange={(e) => this.setState({value: e.target.value }) } />
|
||||
</label>
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
<label>
|
||||
Topic:
|
||||
<FormControl
|
||||
type="text"
|
||||
defaultValue={this.state.topic}
|
||||
readOnly={true} />
|
||||
defaultValue={this.state.title}
|
||||
onChange={(e) => this.setState({title: e.target.value }) } />
|
||||
</label>
|
||||
</FormGroup>
|
||||
<FormGroup>
|
||||
|
@ -89,9 +101,25 @@ class ProposalManager extends React.Component {
|
|||
<FormControl
|
||||
type="text"
|
||||
defaultValue={this.state.description}
|
||||
onChange={(e) => this.setState({value: e.target.value }) } />
|
||||
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>
|
||||
: ''
|
||||
}
|
||||
</Form>
|
||||
</Fragment>
|
||||
)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import web3 from "Embark/web3"
|
||||
import EmbarkJS from 'Embark/EmbarkJS';
|
||||
import React from 'react';
|
||||
import { Button } from 'react-bootstrap';
|
||||
|
||||
class ProposalForm extends React.Component {
|
||||
|
||||
|
@ -9,8 +10,16 @@ class ProposalForm extends React.Component {
|
|||
this.state = {};
|
||||
}
|
||||
|
||||
handleClick(e){
|
||||
e.preventDefault();
|
||||
|
||||
|
||||
}
|
||||
|
||||
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 $ from 'jquery';
|
||||
import {Button} from 'react-bootstrap';
|
||||
import { Button, Alert } from 'react-bootstrap';
|
||||
import EmbarkJS from 'Embark/EmbarkJS';
|
||||
import ProposalForm from './proposal-form';
|
||||
|
||||
|
@ -12,7 +12,8 @@ class Proposal extends React.Component {
|
|||
this.state = {
|
||||
url: null,
|
||||
title: null,
|
||||
description: null
|
||||
description: null,
|
||||
error: null
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -29,7 +30,6 @@ class Proposal extends React.Component {
|
|||
})
|
||||
.catch((err) => {
|
||||
if(err){
|
||||
// TODO handle error
|
||||
console.log("Storage get Error => " + err.message);
|
||||
}
|
||||
});
|
||||
|
@ -38,6 +38,13 @@ class Proposal extends React.Component {
|
|||
|
||||
render(){
|
||||
return (<div>
|
||||
{
|
||||
this.state.error !== null ?
|
||||
<Alert bsStyle="warning">
|
||||
{ this.state.error }
|
||||
</Alert>
|
||||
: ''
|
||||
}
|
||||
<h3>{ this.state.title }</h3>
|
||||
<p>{ this.state.description }</p>
|
||||
<a href={ this.state.url } target="_blank">{ this.state.url }</a>
|
||||
|
|
|
@ -19,7 +19,6 @@ class VotingDapp extends React.Component {
|
|||
return <div>
|
||||
<StatusBar {...this.props} />
|
||||
<ProposalContainer />
|
||||
<ProposalForm />
|
||||
</div>;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue