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 { observable, action, computed } from "mobx";
|
||||
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
|
||||
export class BallotKeysCard extends React.Component {
|
||||
@observable startTime;
|
||||
|
@ -163,6 +164,24 @@ export class BallotKeysCard extends React.Component {
|
|||
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) {
|
||||
super(props);
|
||||
this.votesForNumber = 0;
|
||||
|
@ -230,7 +249,7 @@ export class BallotKeysCard extends React.Component {
|
|||
</div>
|
||||
<div className="ballots-i-scale">
|
||||
<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">
|
||||
<p className="vote-scale--value">Yes</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>
|
||||
</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 className="info">
|
||||
|
|
|
@ -2,9 +2,10 @@ import React from 'react';
|
|||
import moment from 'moment';
|
||||
import { observable, action } from "mobx";
|
||||
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
|
||||
export class BallotMinThresholdCard extends React.Component {
|
||||
@observable startTime;
|
||||
|
@ -86,6 +87,24 @@ export class BallotMinThresholdCard extends React.Component {
|
|||
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) {
|
||||
super(props);
|
||||
this.votesForNumber = 0;
|
||||
|
@ -135,7 +154,7 @@ export class BallotMinThresholdCard extends React.Component {
|
|||
</div>
|
||||
<div className="ballots-i-scale">
|
||||
<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">
|
||||
<p className="vote-scale--value">Yes</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>
|
||||
</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 className="info">
|
||||
|
|
|
@ -2,9 +2,10 @@ import React from 'react';
|
|||
import moment from 'moment';
|
||||
import { observable, action, computed } from "mobx";
|
||||
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
|
||||
export class BallotProxyCard extends React.Component {
|
||||
@observable startTime;
|
||||
|
@ -95,6 +96,24 @@ export class BallotProxyCard extends React.Component {
|
|||
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) {
|
||||
super(props);
|
||||
this.votesForNumber = 0;
|
||||
|
@ -151,7 +170,7 @@ export class BallotProxyCard extends React.Component {
|
|||
</div>
|
||||
<div className="ballots-i-scale">
|
||||
<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">
|
||||
<p className="vote-scale--value">Yes</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>
|
||||
</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 className="info">
|
||||
|
|
|
@ -182,19 +182,23 @@ export class NewBallot extends React.Component {
|
|||
}
|
||||
|
||||
render() {
|
||||
const { ballotStore } = this.props;
|
||||
const { contractsStore, ballotStore } = this.props;
|
||||
let validator = ballotStore.isNewValidatorPersonalData ? <Validator />: "";
|
||||
let keysTypes = ballotStore.isBallotForKey ? <KeysTypes />: "";
|
||||
let metadata
|
||||
let minThreshold
|
||||
switch (ballotStore.ballotType) {
|
||||
case ballotStore.BallotType.keys:
|
||||
metadata = <BallotKeysMetadata />;
|
||||
minThreshold = contractsStore.keysBallotThreshold;
|
||||
break;
|
||||
case ballotStore.BallotType.minThreshold:
|
||||
metadata = <BallotMinThresholdMetadata />;
|
||||
minThreshold = contractsStore.minThresholdBallotThreshold;
|
||||
break;
|
||||
case ballotStore.BallotType.proxy:
|
||||
metadata = <BallotProxyMetadata />;
|
||||
minThreshold = contractsStore.proxyBallotThreshold;
|
||||
break;
|
||||
}
|
||||
return (
|
||||
|
@ -251,7 +255,7 @@ export class NewBallot extends React.Component {
|
|||
{metadata}
|
||||
<div className="new-form-footer">
|
||||
<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>
|
||||
<button type="button" className="add-ballot" onClick={e => this.onClick(e)}>Add ballot</button>
|
||||
</div>
|
||||
|
|
|
@ -15,7 +15,7 @@ export default class VotingToChangeKeys {
|
|||
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})
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ export default class VotingToChangeMinThreshold {
|
|||
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})
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ export default class VotingToChangeProxy {
|
|||
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})
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ class AppMainRouter extends Component {
|
|||
await contractsStore.setPoaConsensus(web3Config);
|
||||
contractsStore.setBallotsStorage(web3Config);
|
||||
contractsStore.getValidatorsLength();
|
||||
contractsStore.getKeysBallotThreshold();
|
||||
await contractsStore.getKeysBallotThreshold();
|
||||
contractsStore.getMinThresholdBallotThreshold();
|
||||
contractsStore.getProxyBallotThreshold();
|
||||
contractsStore.setVotingToChangeKeys(web3Config);
|
||||
|
|
Loading…
Reference in New Issue