Merge pull request #151 from varasev/fix-147

(Fix) Show a new ballot card right after the ballot is created
This commit is contained in:
Victor Baranov 2018-07-12 12:52:40 +03:00 committed by GitHub
commit 11be1a8944
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 42 deletions

View File

@ -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");

View File

@ -254,8 +254,7 @@ class ContractsStore {
return votingState;
}
getCards = async (nextBallotId, contractType) => {
for (let id = nextBallotId - 1; id >= 0; id--) {
getCard = async (id, contractType) => {
let votingState;
try {
votingState = await this[contractType].getBallotInfo(id, this.votingKey);
@ -294,7 +293,12 @@ class ContractsStore {
break;
}
ballotsStore.ballotCards.push(card);
return card;
}
getCards = async (nextBallotId, contractType) => {
for (let id = nextBallotId - 1; id >= 0; id--) {
ballotsStore.ballotCards.push(await this.getCard(id, contractType));
}
}