(Fix) Refresh ballot card after voting or finalization

This commit is contained in:
Vadim Arasev 2018-07-02 15:47:09 +03:00
parent 9f89940b0f
commit db743f3e5a
5 changed files with 24 additions and 15 deletions

View File

@ -11,7 +11,7 @@ const USDateTimeFormat = "MM/DD/YYYY h:mm:ss A";
const zeroTimeTo = "00:00";
@inject("commonStore", "contractsStore", "routing")
@inject("commonStore", "contractsStore", "routing", "ballotsStore")
@observer
export class BallotCard extends React.Component {
@observable startTime;
@ -167,7 +167,7 @@ export class BallotCard extends React.Component {
swal("Warning!", messages.ballotIsNotActiveMsg(this.timeTo.displayValue), "warning");
return;
}
const { commonStore, contractsStore, id, votingType } = this.props;
const { commonStore, contractsStore, id, votingType, ballotsStore } = this.props;
const { push } = this.props.routing;
if (!contractsStore.isValidVotingKey) {
swal("Warning!", messages.invalidVotingKeyMsg(contractsStore.votingKey), "warning");
@ -187,16 +187,22 @@ export class BallotCard extends React.Component {
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;
this.totalVoters = Number(ballotInfo.totalVoters);
this.progress = Number(ballotInfo.progress);
this.isFinalized = Boolean(ballotInfo.isFinalized);
if (ballotInfo.hasOwnProperty('canBeFinalizedNow')) {
this.canBeFinalized = ballotInfo.canBeFinalizedNow;
this.canBeFinalized = Boolean(ballotInfo.canBeFinalizedNow);
} else {
await this.canBeFinalizedNow();
}
this.hasAlreadyVoted = true;
ballotsStore.ballotCards[this.props.pos].props.votingState.totalVoters = this.totalVoters;
ballotsStore.ballotCards[this.props.pos].props.votingState.progress = this.progress;
ballotsStore.ballotCards[this.props.pos].props.votingState.isFinalized = this.isFinalized;
ballotsStore.ballotCards[this.props.pos].props.votingState.canBeFinalized = this.canBeFinalized;
ballotsStore.ballotCards[this.props.pos].props.votingState.hasAlreadyVoted = this.hasAlreadyVoted;
swal("Congratulations!", messages.VOTED_SUCCESS_MSG, "success").then((result) => {
push(`${commonStore.rootPath}`);
});
@ -220,7 +226,7 @@ export class BallotCard extends React.Component {
swal("Warning!", messages.ballotIsNotActiveMsg(this.timeTo.displayValue), "warning");
return;
}
const { commonStore, contractsStore, id, votingType } = this.props;
const { commonStore, contractsStore, id, votingType, ballotsStore } = this.props;
const { push } = this.props.routing;
if (!contractsStore.isValidVotingKey) {
swal("Warning!", messages.invalidVotingKeyMsg(contractsStore.votingKey), "warning");
@ -246,9 +252,9 @@ export class BallotCard extends React.Component {
.on("receipt", (tx) => {
commonStore.hideLoading();
if (tx.status === true || tx.status === '0x1') {
this.isFinalized = true;
ballotsStore.ballotCards[this.props.pos].props.votingState.isFinalized = true;
if (this.canBeFinalized !== null) {
this.canBeFinalized = false;
ballotsStore.ballotCards[this.props.pos].props.votingState.canBeFinalized = false;
}
swal("Congratulations!", messages.FINALIZED_SUCCESS_MSG, "success").then((result) => {
push(`${commonStore.rootPath}`);

View File

@ -6,7 +6,7 @@ import { BallotCard } from "./BallotCard";
@observer
export class BallotKeysCard extends React.Component {
render () {
let { id, votingState } = this.props;
let { id, votingState, pos } = this.props;
let affectedKeyClassName;
let affectedKey = <p>{votingState.affectedKey}</p>;
@ -33,7 +33,7 @@ export class BallotKeysCard extends React.Component {
}
return (
<BallotCard votingType="votingToChangeKeys" votingState={votingState} id={id}>
<BallotCard votingType="votingToChangeKeys" votingState={votingState} id={id} pos={pos}>
<div className="ballots-about-i ballots-about-i_action">
<div className="ballots-about-td">
<p className="ballots-about-i--title">Action</p>

View File

@ -6,9 +6,9 @@ import { BallotCard } from "./BallotCard";
@observer
export class BallotMinThresholdCard extends React.Component {
render () {
let { id, votingState } = this.props;
let { id, votingState, pos } = this.props;
return (
<BallotCard votingType="votingToChangeMinThreshold" votingState={votingState} id={id}>
<BallotCard votingType="votingToChangeMinThreshold" votingState={votingState} id={id} pos={pos}>
<div className="ballots-about-i ballots-about-i_proposed-min-threshold">
<div className="ballots-about-td">
<p className="ballots-about-i--title">Proposed min threshold</p>

View File

@ -6,9 +6,9 @@ import { BallotCard } from "./BallotCard";
@observer
export class BallotProxyCard extends React.Component {
render () {
const { id, votingState } = this.props;
const { id, votingState, pos } = this.props;
return (
<BallotCard votingType="votingToChangeProxy" votingState={votingState} id={id}>
<BallotCard votingType="votingToChangeProxy" votingState={votingState} id={id} pos={pos}>
<div className="ballots-about-i ballots-about-i_contract-type">
<div className="ballots-about-td">
<p className="ballots-about-i--title">Contract type</p>

View File

@ -271,6 +271,7 @@ class ContractsStore {
id={id}
type={ballotStore.BallotType.keys}
key={ballotsStore.ballotCards.length}
pos={ballotsStore.ballotCards.length}
votingState={votingState}/>
break;
case "votingToChangeMinThreshold":
@ -278,6 +279,7 @@ class ContractsStore {
id={id}
type={ballotStore.BallotType.minThreshold}
key={ballotsStore.ballotCards.length}
pos={ballotsStore.ballotCards.length}
votingState={votingState}/>
break;
case "votingToChangeProxy":
@ -285,6 +287,7 @@ class ContractsStore {
id={id}
type={ballotStore.BallotType.proxy}
key={ballotsStore.ballotCards.length}
pos={ballotsStore.ballotCards.length}
votingState={votingState}/>
break;
default: