diff --git a/src/components/BallotKeysCard.jsx b/src/components/BallotKeysCard.jsx index 858b5ba..c250fc7 100644 --- a/src/components/BallotKeysCard.jsx +++ b/src/components/BallotKeysCard.jsx @@ -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 {
- Vote +

Yes

Votes: {this.votesForNumber}

@@ -249,7 +268,7 @@ export class BallotKeysCard extends React.Component {
- Vote +
diff --git a/src/components/BallotMinThresholdCard.jsx b/src/components/BallotMinThresholdCard.jsx index d817d37..6d89284 100644 --- a/src/components/BallotMinThresholdCard.jsx +++ b/src/components/BallotMinThresholdCard.jsx @@ -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 {
- Vote +

Yes

Votes: {this.votesForNumber}

@@ -154,7 +173,7 @@ export class BallotMinThresholdCard extends React.Component {
- Vote +
diff --git a/src/components/BallotProxyCard.jsx b/src/components/BallotProxyCard.jsx index bd712b0..c133b99 100644 --- a/src/components/BallotProxyCard.jsx +++ b/src/components/BallotProxyCard.jsx @@ -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 {
- Vote +

Yes

Votes: {this.votesForNumber}

@@ -170,7 +189,7 @@ export class BallotProxyCard extends React.Component {
- Vote +
diff --git a/src/components/NewBallot.jsx b/src/components/NewBallot.jsx index f89b1f4..b18c9fe 100644 --- a/src/components/NewBallot.jsx +++ b/src/components/NewBallot.jsx @@ -182,19 +182,23 @@ export class NewBallot extends React.Component { } render() { - const { ballotStore } = this.props; + const { contractsStore, ballotStore } = this.props; let validator = ballotStore.isNewValidatorPersonalData ? : ""; let keysTypes = ballotStore.isBallotForKey ? : ""; let metadata + let minThreshold switch (ballotStore.ballotType) { case ballotStore.BallotType.keys: metadata = ; + minThreshold = contractsStore.keysBallotThreshold; break; case ballotStore.BallotType.minThreshold: metadata = ; + minThreshold = contractsStore.minThresholdBallotThreshold; break; case ballotStore.BallotType.proxy: metadata = ; + minThreshold = contractsStore.proxyBallotThreshold; break; } return ( @@ -251,7 +255,7 @@ export class NewBallot extends React.Component { {metadata}
- Minimum 3 from 12 validators required to pass the proposal + Minimum {minThreshold} from {contractsStore.validatorsLength} validators required to pass the proposal
diff --git a/src/contracts/VotingToChangeKeys.contract.js b/src/contracts/VotingToChangeKeys.contract.js index 97de45f..2ae757c 100644 --- a/src/contracts/VotingToChangeKeys.contract.js +++ b/src/contracts/VotingToChangeKeys.contract.js @@ -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}) } - vote({id, choice, sender}){ + vote(id, choice, 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}) } } diff --git a/src/contracts/VotingToChangeMinThreshold.contract.js b/src/contracts/VotingToChangeMinThreshold.contract.js index 35341d4..872d1d8 100644 --- a/src/contracts/VotingToChangeMinThreshold.contract.js +++ b/src/contracts/VotingToChangeMinThreshold.contract.js @@ -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}) } - vote({id, choice, sender}){ + vote(id, choice, 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}) } } diff --git a/src/contracts/VotingToChangeProxy.contract.js b/src/contracts/VotingToChangeProxy.contract.js index 4ef0907..c1f6ca5 100644 --- a/src/contracts/VotingToChangeProxy.contract.js +++ b/src/contracts/VotingToChangeProxy.contract.js @@ -15,11 +15,11 @@ 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}) } - finalize({id, sender}){ + finalize({id, sender}) { return this.votingToChangeProxyInstance.methods.finalize(id, id).send({from: sender}) } } diff --git a/src/index.js b/src/index.js index 9fb7d88..19c5e9e 100644 --- a/src/index.js +++ b/src/index.js @@ -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);