(Fix) Show a new ballot card right after the ballot is created
This commit is contained in:
parent
db7c97c38a
commit
005f852ec3
|
@ -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");
|
||||
|
|
|
@ -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 = <BallotKeysCard
|
||||
id={id}
|
||||
type={ballotStore.BallotType.keys}
|
||||
key={ballotsStore.ballotCards.length}
|
||||
pos={ballotsStore.ballotCards.length}
|
||||
votingState={votingState}/>
|
||||
break;
|
||||
case "votingToChangeMinThreshold":
|
||||
card = <BallotMinThresholdCard
|
||||
id={id}
|
||||
type={ballotStore.BallotType.minThreshold}
|
||||
key={ballotsStore.ballotCards.length}
|
||||
pos={ballotsStore.ballotCards.length}
|
||||
votingState={votingState}/>
|
||||
break;
|
||||
case "votingToChangeProxy":
|
||||
card = <BallotProxyCard
|
||||
id={id}
|
||||
type={ballotStore.BallotType.proxy}
|
||||
key={ballotsStore.ballotCards.length}
|
||||
pos={ballotsStore.ballotCards.length}
|
||||
votingState={votingState}/>
|
||||
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 = <BallotKeysCard
|
||||
id={id}
|
||||
type={ballotStore.BallotType.keys}
|
||||
key={ballotsStore.ballotCards.length}
|
||||
pos={ballotsStore.ballotCards.length}
|
||||
votingState={votingState}/>
|
||||
break;
|
||||
case "votingToChangeMinThreshold":
|
||||
card = <BallotMinThresholdCard
|
||||
id={id}
|
||||
type={ballotStore.BallotType.minThreshold}
|
||||
key={ballotsStore.ballotCards.length}
|
||||
pos={ballotsStore.ballotCards.length}
|
||||
votingState={votingState}/>
|
||||
break;
|
||||
case "votingToChangeProxy":
|
||||
card = <BallotProxyCard
|
||||
id={id}
|
||||
type={ballotStore.BallotType.proxy}
|
||||
key={ballotsStore.ballotCards.length}
|
||||
pos={ballotsStore.ballotCards.length}
|
||||
votingState={votingState}/>
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
ballotsStore.ballotCards.push(card);
|
||||
ballotsStore.ballotCards.push(await this.getCard(id, contractType));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue