(Fix) Refresh ballot card after voting or finalization

This commit is contained in:
Vadim Arasev 2018-07-02 13:46:53 +03:00
parent a9cb25a89b
commit 685d43285e
5 changed files with 20 additions and 29 deletions

View File

@ -180,10 +180,23 @@ export class BallotCard extends React.Component {
swal("Warning!", messages.INVALID_VOTE_MSG, "warning");
return;
}
this.getContract(contractsStore, votingType).vote(id, choice, contractsStore.votingKey)
.on("receipt", (tx) => {
const contract = this.getContract(contractsStore, votingType);
contract.vote(id, choice, contractsStore.votingKey)
.on("receipt", async (tx) => {
commonStore.hideLoading();
if (tx.status === true || tx.status === '0x1') {
const ballotInfo = await contract.getBallotInfo(id, contractsStore.votingKey);
this.totalVoters = ballotInfo.totalVoters;
this.progress = ballotInfo.progress;
this.isFinalized = ballotInfo.isFinalized;
if (ballotInfo.hasOwnProperty('canBeFinalizedNow')) {
this.canBeFinalized = ballotInfo.canBeFinalizedNow;
} else {
await canBeFinalizedNow();
}
this.hasAlreadyVoted = true;
swal("Congratulations!", messages.VOTED_SUCCESS_MSG, "success").then((result) => {
push(`${commonStore.rootPath}`);
});
@ -233,6 +246,8 @@ export class BallotCard extends React.Component {
.on("receipt", (tx) => {
commonStore.hideLoading();
if (tx.status === true || tx.status === '0x1') {
this.isFinalized = true;
this.canBeFinalized = false;
swal("Congratulations!", messages.FINALIZED_SUCCESS_MSG, "success").then((result) => {
push(`${commonStore.rootPath}`);
});

View File

@ -52,18 +52,11 @@ export default class VotingToChangeKeys {
return this.votingToChangeKeysInstance.methods.nextBallotId().call();
}
votingState(_id) {
if (this.doesMethodExist('votingState')) {
return this.votingToChangeKeysInstance.methods.votingState(_id).call();
}
return null;
}
getBallotInfo(_id, _votingKey) {
if (this.doesMethodExist('getBallotInfo')) {
return this.votingToChangeKeysInstance.methods.getBallotInfo(_id).call();
}
return null;
return this.votingToChangeKeysInstance.methods.votingState(_id).call();
}
hasAlreadyVoted(_id, votingKey) {

View File

@ -47,18 +47,11 @@ export default class VotingToChangeMinThreshold {
return this.votingToChangeMinThresholdInstance.methods.nextBallotId().call();
}
votingState(_id) {
if (this.doesMethodExist('votingState')) {
return this.votingToChangeMinThresholdInstance.methods.votingState(_id).call();
}
return null;
}
getBallotInfo(_id, _votingKey) {
if (this.doesMethodExist('getBallotInfo')) {
return this.votingToChangeMinThresholdInstance.methods.getBallotInfo(_id, _votingKey).call();
}
return null;
return this.votingToChangeMinThresholdInstance.methods.votingState(_id).call();
}
hasAlreadyVoted(_id, votingKey) {

View File

@ -47,18 +47,11 @@ export default class VotingToChangeProxy {
return this.votingToChangeProxyInstance.methods.nextBallotId().call();
}
votingState(_id) {
if (this.doesMethodExist('votingState')) {
return this.votingToChangeProxyInstance.methods.votingState(_id).call();
}
return null;
}
getBallotInfo(_id, _votingKey) {
if (this.doesMethodExist('getBallotInfo')) {
return this.votingToChangeProxyInstance.methods.getBallotInfo(_id, _votingKey).call();
}
return null;
return this.votingToChangeProxyInstance.methods.votingState(_id).call();
}
hasAlreadyVoted(_id, votingKey) {

View File

@ -259,9 +259,6 @@ class ContractsStore {
let votingState;
try {
votingState = await this[contractType].getBallotInfo(id, this.votingKey);
if (!votingState) {
votingState = await this[contractType].votingState(id);
}
votingState = this.fillCardVotingState(votingState, contractType);
} catch(e) {
console.log(e.message);