voting on ballots
This commit is contained in:
parent
00a08dbd4e
commit
500a04c102
|
@ -2,9 +2,10 @@ import React from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { observable, action, computed } from "mobx";
|
import { observable, action, computed } from "mobx";
|
||||||
import { inject, observer } from "mobx-react";
|
import { inject, observer } from "mobx-react";
|
||||||
import { toAscii } from "../helpers"
|
import { toAscii } from "../helpers";
|
||||||
|
import swal from 'sweetalert2';
|
||||||
|
|
||||||
@inject("contractsStore", "ballotStore")
|
@inject("commonStore", "contractsStore", "ballotStore", "routing")
|
||||||
@observer
|
@observer
|
||||||
export class BallotKeysCard extends React.Component {
|
export class BallotKeysCard extends React.Component {
|
||||||
@observable startTime;
|
@observable startTime;
|
||||||
|
@ -163,6 +164,24 @@ export class BallotKeysCard extends React.Component {
|
||||||
this.progress = await contractsStore.votingToChangeKeys.votingToChangeKeysInstance.methods.getProgress(_id).call
|
this.progress = await contractsStore.votingToChangeKeys.votingToChangeKeysInstance.methods.getProgress(_id).call
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@action("Vote")
|
||||||
|
vote = async (e, _id, _type) => {
|
||||||
|
const { commonStore, contractsStore } = this.props;
|
||||||
|
commonStore.showLoading();
|
||||||
|
const { push } = this.props.routing;
|
||||||
|
contractsStore.votingToChangeKeys.vote(this.props.id, _type, contractsStore.votingKey)
|
||||||
|
.on("receipt", () => {
|
||||||
|
commonStore.hideLoading();
|
||||||
|
swal("Congratulations!", "You successfully voted", "success").then((result) => {
|
||||||
|
push(`${commonStore.rootPath}`);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.on("error", (e) => {
|
||||||
|
commonStore.hideLoading();
|
||||||
|
swal("Error!", e.message, "error");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.votesForNumber = 0;
|
this.votesForNumber = 0;
|
||||||
|
@ -230,7 +249,7 @@ export class BallotKeysCard extends React.Component {
|
||||||
</div>
|
</div>
|
||||||
<div className="ballots-i-scale">
|
<div className="ballots-i-scale">
|
||||||
<div className="ballots-i-scale-column">
|
<div className="ballots-i-scale-column">
|
||||||
<a href="#" className="ballots-i--vote ballots-i--vote_yes">Vote</a>
|
<button type="button" onClick={(e) => this.vote(e, this.props.id, 1)} className="ballots-i--vote ballots-i--vote_yes">Vote</button>
|
||||||
<div className="vote-scale--container">
|
<div className="vote-scale--container">
|
||||||
<p className="vote-scale--value">Yes</p>
|
<p className="vote-scale--value">Yes</p>
|
||||||
<p className="vote-scale--votes">Votes: {this.votesForNumber}</p>
|
<p className="vote-scale--votes">Votes: {this.votesForNumber}</p>
|
||||||
|
@ -249,7 +268,7 @@ export class BallotKeysCard extends React.Component {
|
||||||
<div className="vote-scale--fill vote-scale--fill_no" style={{width: `${this.votesAgainstPercents}%`}}></div>
|
<div className="vote-scale--fill vote-scale--fill_no" style={{width: `${this.votesAgainstPercents}%`}}></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<a href="#" className="ballots-i--vote ballots-i--vote_no">Vote</a>
|
<button type="button" onClick={(e) => this.vote(e, this.props.id, 2)} className="ballots-i--vote ballots-i--vote_no">Vote</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="info">
|
<div className="info">
|
||||||
|
|
|
@ -2,9 +2,10 @@ import React from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { observable, action } from "mobx";
|
import { observable, action } from "mobx";
|
||||||
import { inject, observer } from "mobx-react";
|
import { inject, observer } from "mobx-react";
|
||||||
import { toAscii } from "../helpers"
|
import { toAscii } from "../helpers";
|
||||||
|
import swal from 'sweetalert2';
|
||||||
|
|
||||||
@inject("contractsStore")
|
@inject("commonStore", "contractsStore", "routing")
|
||||||
@observer
|
@observer
|
||||||
export class BallotMinThresholdCard extends React.Component {
|
export class BallotMinThresholdCard extends React.Component {
|
||||||
@observable startTime;
|
@observable startTime;
|
||||||
|
@ -86,6 +87,24 @@ export class BallotMinThresholdCard extends React.Component {
|
||||||
this.progress = await contractsStore.votingToChangeKeys.votingToChangeKeysInstance.methods.getProgress(_id).call
|
this.progress = await contractsStore.votingToChangeKeys.votingToChangeKeysInstance.methods.getProgress(_id).call
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@action("Vote")
|
||||||
|
vote = async (e, _id, _type) => {
|
||||||
|
const { commonStore, contractsStore } = this.props;
|
||||||
|
commonStore.showLoading();
|
||||||
|
const { push } = this.props.routing;
|
||||||
|
contractsStore.votingToChangeKeys.vote(this.props.id, _type, contractsStore.votingKey)
|
||||||
|
.on("receipt", () => {
|
||||||
|
commonStore.hideLoading();
|
||||||
|
swal("Congratulations!", "You successfully voted", "success").then((result) => {
|
||||||
|
push(`${commonStore.rootPath}`);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.on("error", (e) => {
|
||||||
|
commonStore.hideLoading();
|
||||||
|
swal("Error!", e.message, "error");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.votesForNumber = 0;
|
this.votesForNumber = 0;
|
||||||
|
@ -135,7 +154,7 @@ export class BallotMinThresholdCard extends React.Component {
|
||||||
</div>
|
</div>
|
||||||
<div className="ballots-i-scale">
|
<div className="ballots-i-scale">
|
||||||
<div className="ballots-i-scale-column">
|
<div className="ballots-i-scale-column">
|
||||||
<a href="#" className="ballots-i--vote ballots-i--vote_yes">Vote</a>
|
<button type="button" onClick={(e) => this.vote(e, this.props.id, 1)} className="ballots-i--vote ballots-i--vote_yes">Vote</button>
|
||||||
<div className="vote-scale--container">
|
<div className="vote-scale--container">
|
||||||
<p className="vote-scale--value">Yes</p>
|
<p className="vote-scale--value">Yes</p>
|
||||||
<p className="vote-scale--votes">Votes: {this.votesForNumber}</p>
|
<p className="vote-scale--votes">Votes: {this.votesForNumber}</p>
|
||||||
|
@ -154,7 +173,7 @@ export class BallotMinThresholdCard extends React.Component {
|
||||||
<div className="vote-scale--fill vote-scale--fill_no" style={{width: `${this.votesAgainstPercents}%`}}></div>
|
<div className="vote-scale--fill vote-scale--fill_no" style={{width: `${this.votesAgainstPercents}%`}}></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<a href="#" className="ballots-i--vote ballots-i--vote_no">Vote</a>
|
<button type="button" onClick={(e) => this.vote(e, this.props.id, 2)} className="ballots-i--vote ballots-i--vote_no">Vote</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="info">
|
<div className="info">
|
||||||
|
|
|
@ -2,9 +2,10 @@ import React from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { observable, action, computed } from "mobx";
|
import { observable, action, computed } from "mobx";
|
||||||
import { inject, observer } from "mobx-react";
|
import { inject, observer } from "mobx-react";
|
||||||
import { toAscii } from "../helpers"
|
import { toAscii } from "../helpers";
|
||||||
|
import swal from 'sweetalert2';
|
||||||
|
|
||||||
@inject("contractsStore", "ballotStore")
|
@inject("commonStore", "contractsStore", "ballotStore", "routing")
|
||||||
@observer
|
@observer
|
||||||
export class BallotProxyCard extends React.Component {
|
export class BallotProxyCard extends React.Component {
|
||||||
@observable startTime;
|
@observable startTime;
|
||||||
|
@ -95,6 +96,24 @@ export class BallotProxyCard extends React.Component {
|
||||||
this.progress = await contractsStore.votingToChangeKeys.votingToChangeKeysInstance.methods.getProgress(_id).call
|
this.progress = await contractsStore.votingToChangeKeys.votingToChangeKeysInstance.methods.getProgress(_id).call
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@action("Vote")
|
||||||
|
vote = async (e, _id, _type) => {
|
||||||
|
const { commonStore, contractsStore } = this.props;
|
||||||
|
commonStore.showLoading();
|
||||||
|
const { push } = this.props.routing;
|
||||||
|
contractsStore.votingToChangeKeys.vote(this.props.id, _type, contractsStore.votingKey)
|
||||||
|
.on("receipt", () => {
|
||||||
|
commonStore.hideLoading();
|
||||||
|
swal("Congratulations!", "You successfully voted", "success").then((result) => {
|
||||||
|
push(`${commonStore.rootPath}`);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.on("error", (e) => {
|
||||||
|
commonStore.hideLoading();
|
||||||
|
swal("Error!", e.message, "error");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.votesForNumber = 0;
|
this.votesForNumber = 0;
|
||||||
|
@ -151,7 +170,7 @@ export class BallotProxyCard extends React.Component {
|
||||||
</div>
|
</div>
|
||||||
<div className="ballots-i-scale">
|
<div className="ballots-i-scale">
|
||||||
<div className="ballots-i-scale-column">
|
<div className="ballots-i-scale-column">
|
||||||
<a href="#" className="ballots-i--vote ballots-i--vote_yes">Vote</a>
|
<button type="button" onClick={(e) => this.vote(e, this.props.id, 1)} className="ballots-i--vote ballots-i--vote_yes">Vote</button>
|
||||||
<div className="vote-scale--container">
|
<div className="vote-scale--container">
|
||||||
<p className="vote-scale--value">Yes</p>
|
<p className="vote-scale--value">Yes</p>
|
||||||
<p className="vote-scale--votes">Votes: {this.votesForNumber}</p>
|
<p className="vote-scale--votes">Votes: {this.votesForNumber}</p>
|
||||||
|
@ -170,7 +189,7 @@ export class BallotProxyCard extends React.Component {
|
||||||
<div className="vote-scale--fill vote-scale--fill_no" style={{width: `${this.votesAgainstPercents}%`}}></div>
|
<div className="vote-scale--fill vote-scale--fill_no" style={{width: `${this.votesAgainstPercents}%`}}></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<a href="#" className="ballots-i--vote ballots-i--vote_no">Vote</a>
|
<button type="button" onClick={(e) => this.vote(e, this.props.id, 2)} className="ballots-i--vote ballots-i--vote_no">Vote</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="info">
|
<div className="info">
|
||||||
|
|
|
@ -182,19 +182,23 @@ export class NewBallot extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { ballotStore } = this.props;
|
const { contractsStore, ballotStore } = this.props;
|
||||||
let validator = ballotStore.isNewValidatorPersonalData ? <Validator />: "";
|
let validator = ballotStore.isNewValidatorPersonalData ? <Validator />: "";
|
||||||
let keysTypes = ballotStore.isBallotForKey ? <KeysTypes />: "";
|
let keysTypes = ballotStore.isBallotForKey ? <KeysTypes />: "";
|
||||||
let metadata
|
let metadata
|
||||||
|
let minThreshold
|
||||||
switch (ballotStore.ballotType) {
|
switch (ballotStore.ballotType) {
|
||||||
case ballotStore.BallotType.keys:
|
case ballotStore.BallotType.keys:
|
||||||
metadata = <BallotKeysMetadata />;
|
metadata = <BallotKeysMetadata />;
|
||||||
|
minThreshold = contractsStore.keysBallotThreshold;
|
||||||
break;
|
break;
|
||||||
case ballotStore.BallotType.minThreshold:
|
case ballotStore.BallotType.minThreshold:
|
||||||
metadata = <BallotMinThresholdMetadata />;
|
metadata = <BallotMinThresholdMetadata />;
|
||||||
|
minThreshold = contractsStore.minThresholdBallotThreshold;
|
||||||
break;
|
break;
|
||||||
case ballotStore.BallotType.proxy:
|
case ballotStore.BallotType.proxy:
|
||||||
metadata = <BallotProxyMetadata />;
|
metadata = <BallotProxyMetadata />;
|
||||||
|
minThreshold = contractsStore.proxyBallotThreshold;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
|
@ -251,7 +255,7 @@ export class NewBallot extends React.Component {
|
||||||
{metadata}
|
{metadata}
|
||||||
<div className="new-form-footer">
|
<div className="new-form-footer">
|
||||||
<div className="info">
|
<div className="info">
|
||||||
Minimum 3 from 12 validators required to pass the proposal
|
Minimum {minThreshold} from {contractsStore.validatorsLength} validators required to pass the proposal
|
||||||
</div>
|
</div>
|
||||||
<button type="button" className="add-ballot" onClick={e => this.onClick(e)}>Add ballot</button>
|
<button type="button" className="add-ballot" onClick={e => this.onClick(e)}>Add ballot</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -11,15 +11,15 @@ export default class VotingToChangeKeys {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
createVotingForKeys(startTime, endTime, affectedKey, affectedKeyType, miningKey, ballotType, sender){
|
createVotingForKeys(startTime, endTime, affectedKey, affectedKeyType, miningKey, ballotType, sender) {
|
||||||
return this.votingToChangeKeysInstance.methods.createVotingForKeys(startTime, endTime, affectedKey, affectedKeyType, miningKey, ballotType).send({from: sender})
|
return this.votingToChangeKeysInstance.methods.createVotingForKeys(startTime, endTime, affectedKey, affectedKeyType, miningKey, ballotType).send({from: sender})
|
||||||
}
|
}
|
||||||
|
|
||||||
vote({id, choice, sender}){
|
vote(id, choice, sender) {
|
||||||
return this.votingToChangeKeysInstance.methods.vote(id, choice).send({from: sender})
|
return this.votingToChangeKeysInstance.methods.vote(id, choice).send({from: sender})
|
||||||
}
|
}
|
||||||
|
|
||||||
finalize({id, sender}){
|
finalize({id, sender}) {
|
||||||
return this.votingToChangeKeysInstance.methods.finalize(id, id).send({from: sender})
|
return this.votingToChangeKeysInstance.methods.finalize(id, id).send({from: sender})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,15 +11,15 @@ export default class VotingToChangeMinThreshold {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
createBallotToChangeThreshold(startTime, endTime, proposedValue, sender){
|
createBallotToChangeThreshold(startTime, endTime, proposedValue, sender) {
|
||||||
return this.votingToChangeMinThresholdInstance.methods.createBallotToChangeThreshold(startTime, endTime, proposedValue).send({from: sender})
|
return this.votingToChangeMinThresholdInstance.methods.createBallotToChangeThreshold(startTime, endTime, proposedValue).send({from: sender})
|
||||||
}
|
}
|
||||||
|
|
||||||
vote({id, choice, sender}){
|
vote(id, choice, sender) {
|
||||||
return this.votingToChangeMinThresholdInstance.methods.vote(id, choice).send({from: sender})
|
return this.votingToChangeMinThresholdInstance.methods.vote(id, choice).send({from: sender})
|
||||||
}
|
}
|
||||||
|
|
||||||
finalize({id, sender}){
|
finalize({id, sender}) {
|
||||||
return this.votingToChangeMinThresholdInstance.methods.finalize(id, id).send({from: sender})
|
return this.votingToChangeMinThresholdInstance.methods.finalize(id, id).send({from: sender})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,11 +15,11 @@ export default class VotingToChangeProxy {
|
||||||
return this.votingToChangeProxyInstance.methods.createBallotToChangeProxyAddress(startTime, endTime, proposedValue, contractType).send({from: sender})
|
return this.votingToChangeProxyInstance.methods.createBallotToChangeProxyAddress(startTime, endTime, proposedValue, contractType).send({from: sender})
|
||||||
}
|
}
|
||||||
|
|
||||||
vote({id, choice, sender}){
|
vote(id, choice, sender) {
|
||||||
return this.votingToChangeProxyInstance.methods.vote(id, choice).send({from: sender})
|
return this.votingToChangeProxyInstance.methods.vote(id, choice).send({from: sender})
|
||||||
}
|
}
|
||||||
|
|
||||||
finalize({id, sender}){
|
finalize({id, sender}) {
|
||||||
return this.votingToChangeProxyInstance.methods.finalize(id, id).send({from: sender})
|
return this.votingToChangeProxyInstance.methods.finalize(id, id).send({from: sender})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ class AppMainRouter extends Component {
|
||||||
await contractsStore.setPoaConsensus(web3Config);
|
await contractsStore.setPoaConsensus(web3Config);
|
||||||
contractsStore.setBallotsStorage(web3Config);
|
contractsStore.setBallotsStorage(web3Config);
|
||||||
contractsStore.getValidatorsLength();
|
contractsStore.getValidatorsLength();
|
||||||
contractsStore.getKeysBallotThreshold();
|
await contractsStore.getKeysBallotThreshold();
|
||||||
contractsStore.getMinThresholdBallotThreshold();
|
contractsStore.getMinThresholdBallotThreshold();
|
||||||
contractsStore.getProxyBallotThreshold();
|
contractsStore.getProxyBallotThreshold();
|
||||||
contractsStore.setVotingToChangeKeys(web3Config);
|
contractsStore.setVotingToChangeKeys(web3Config);
|
||||||
|
|
Loading…
Reference in New Issue