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:
commit
11be1a8944
|
@ -9,7 +9,7 @@ import { BallotMinThresholdMetadata } from './BallotMinThresholdMetadata';
|
||||||
import { BallotProxyMetadata } from './BallotProxyMetadata';
|
import { BallotProxyMetadata } from './BallotProxyMetadata';
|
||||||
import { messages } from "../messages";
|
import { messages } from "../messages";
|
||||||
import { constants } from "../constants";
|
import { constants } from "../constants";
|
||||||
@inject("commonStore", "ballotStore", "validatorStore", "contractsStore", "routing")
|
@inject("commonStore", "ballotStore", "validatorStore", "contractsStore", "routing", "ballotsStore")
|
||||||
@observer
|
@observer
|
||||||
export class NewBallot extends React.Component {
|
export class NewBallot extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
@ -182,7 +182,7 @@ export class NewBallot extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
onClick = async () => {
|
onClick = async () => {
|
||||||
const { commonStore, contractsStore, ballotStore } = this.props;
|
const { commonStore, contractsStore, ballotStore, ballotsStore } = this.props;
|
||||||
const { push } = this.props.routing;
|
const { push } = this.props.routing;
|
||||||
commonStore.showLoading();
|
commonStore.showLoading();
|
||||||
const isValidVotingKey = contractsStore.isValidVotingKey;
|
const isValidVotingKey = contractsStore.isValidVotingKey;
|
||||||
|
@ -208,15 +208,19 @@ export class NewBallot extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
let methodToCreateBallot;
|
let methodToCreateBallot;
|
||||||
|
let contractType;
|
||||||
switch (ballotStore.ballotType) {
|
switch (ballotStore.ballotType) {
|
||||||
case ballotStore.BallotType.keys:
|
case ballotStore.BallotType.keys:
|
||||||
methodToCreateBallot = this.createBallotForKeys;
|
methodToCreateBallot = this.createBallotForKeys;
|
||||||
|
contractType = "votingToChangeKeys";
|
||||||
break;
|
break;
|
||||||
case ballotStore.BallotType.minThreshold:
|
case ballotStore.BallotType.minThreshold:
|
||||||
methodToCreateBallot = this.createBallotForMinThreshold;
|
methodToCreateBallot = this.createBallotForMinThreshold;
|
||||||
|
contractType = "votingToChangeMinThreshold";
|
||||||
break;
|
break;
|
||||||
case ballotStore.BallotType.proxy:
|
case ballotStore.BallotType.proxy:
|
||||||
methodToCreateBallot = this.createBallotForProxy;
|
methodToCreateBallot = this.createBallotForProxy;
|
||||||
|
contractType = "votingToChangeProxy";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -224,11 +228,16 @@ export class NewBallot extends React.Component {
|
||||||
|
|
||||||
const startTime = moment.utc().add(constants.startTimeOffsetInMinutes, 'minutes').unix();
|
const startTime = moment.utc().add(constants.startTimeOffsetInMinutes, 'minutes').unix();
|
||||||
methodToCreateBallot(startTime)
|
methodToCreateBallot(startTime)
|
||||||
.on("receipt", (tx) => {
|
.on("receipt", async (tx) => {
|
||||||
commonStore.hideLoading();
|
commonStore.hideLoading();
|
||||||
if (tx.status === true || tx.status === '0x1') {
|
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) => {
|
swal("Congratulations!", messages.BALLOT_CREATED_SUCCESS_MSG, "success").then((result) => {
|
||||||
push(`${commonStore.rootPath}`);
|
push(`${commonStore.rootPath}`);
|
||||||
|
window.scrollTo(0, 0);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
swal("Warning!", messages.BALLOT_CREATE_FAILED_TX, "warning");
|
swal("Warning!", messages.BALLOT_CREATE_FAILED_TX, "warning");
|
||||||
|
|
|
@ -254,47 +254,51 @@ class ContractsStore {
|
||||||
return votingState;
|
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) => {
|
getCards = async (nextBallotId, contractType) => {
|
||||||
for (let id = nextBallotId - 1; id >= 0; id--) {
|
for (let id = nextBallotId - 1; id >= 0; id--) {
|
||||||
let votingState;
|
ballotsStore.ballotCards.push(await this.getCard(id, contractType));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue