From 1240d72e297e7282b3503a83147cc38dbb772fcf Mon Sep 17 00:00:00 2001 From: Vadim Arasev Date: Mon, 9 Jul 2018 18:29:55 +0300 Subject: [PATCH] (Fix) Show a new ballot card right after the ballot is created --- src/components/NewBallot.jsx | 15 +++++-- src/stores/ContractsStore.js | 82 +++++++++++++++++++----------------- 2 files changed, 55 insertions(+), 42 deletions(-) diff --git a/src/components/NewBallot.jsx b/src/components/NewBallot.jsx index eb9e68a..8cd7e00 100644 --- a/src/components/NewBallot.jsx +++ b/src/components/NewBallot.jsx @@ -9,7 +9,7 @@ import { BallotMinThresholdMetadata } from './BallotMinThresholdMetadata'; import { BallotProxyMetadata } from './BallotProxyMetadata'; import { messages } from "../messages"; import { constants } from "../constants"; -@inject("commonStore", "ballotStore", "validatorStore", "contractsStore", "routing") +@inject("commonStore", "ballotStore", "validatorStore", "contractsStore", "routing", "ballotsStore") @observer export class NewBallot extends React.Component { constructor(props) { @@ -182,7 +182,7 @@ export class NewBallot extends React.Component { } onClick = async () => { - const { commonStore, contractsStore, ballotStore } = this.props; + const { commonStore, contractsStore, ballotStore, ballotsStore } = this.props; const { push } = this.props.routing; commonStore.showLoading(); const isValidVotingKey = contractsStore.isValidVotingKey; @@ -208,15 +208,19 @@ export class NewBallot extends React.Component { } let methodToCreateBallot; + let contractType; switch (ballotStore.ballotType) { case ballotStore.BallotType.keys: methodToCreateBallot = this.createBallotForKeys; + contractType = "votingToChangeKeys"; break; case ballotStore.BallotType.minThreshold: methodToCreateBallot = this.createBallotForMinThreshold; + contractType = "votingToChangeMinThreshold"; break; case ballotStore.BallotType.proxy: methodToCreateBallot = this.createBallotForProxy; + contractType = "votingToChangeProxy"; break; default: break; @@ -224,11 +228,16 @@ export class NewBallot extends React.Component { const startTime = moment.utc().add(constants.startTimeOffsetInMinutes, 'minutes').unix(); methodToCreateBallot(startTime) - .on("receipt", (tx) => { + .on("receipt", async (tx) => { commonStore.hideLoading(); if (tx.status === true || tx.status === '0x1') { + const newId = Number(tx.events.BallotCreated.returnValues.id); + const card = await contractsStore.getCard(newId, contractType); + ballotsStore.ballotCards.push(card); + swal("Congratulations!", messages.BALLOT_CREATED_SUCCESS_MSG, "success").then((result) => { push(`${commonStore.rootPath}`); + window.scrollTo(0, 0); }); } else { swal("Warning!", messages.BALLOT_CREATE_FAILED_TX, "warning"); diff --git a/src/stores/ContractsStore.js b/src/stores/ContractsStore.js index 6ff3990..2b8c589 100644 --- a/src/stores/ContractsStore.js +++ b/src/stores/ContractsStore.js @@ -254,47 +254,51 @@ class ContractsStore { return votingState; } + getCard = async (id, contractType) => { + let votingState; + try { + votingState = await this[contractType].getBallotInfo(id, this.votingKey); + votingState = this.fillCardVotingState(votingState, contractType); + } catch(e) { + console.log(e.message); + } + + let card; + switch(contractType) { + case "votingToChangeKeys": + card = + break; + case "votingToChangeMinThreshold": + card = + break; + case "votingToChangeProxy": + card = + break; + default: + break; + } + + return card; + } + getCards = async (nextBallotId, contractType) => { for (let id = nextBallotId - 1; id >= 0; id--) { - let votingState; - try { - votingState = await this[contractType].getBallotInfo(id, this.votingKey); - votingState = this.fillCardVotingState(votingState, contractType); - } catch(e) { - console.log(e.message); - } - - let card; - switch(contractType) { - case "votingToChangeKeys": - card = - break; - case "votingToChangeMinThreshold": - card = - break; - case "votingToChangeProxy": - card = - break; - default: - break; - } - - ballotsStore.ballotCards.push(card); + ballotsStore.ballotCards.push(await this.getCard(id, contractType)); } }