>
>(
connectChallengePhase,
connectChallengeResults,
connectParameters,
)(AppealChallengeRevealVoteCardComponent);
class AppealChallengeRevealVote extends React.Component<
AppealChallengeDetailProps & InjectedTransactionStatusModalProps,
ChallengeVoteState & AppealRevealCardKeyState
> {
public static contextType = CivilHelperContext;
public context: CivilHelper;
constructor(props: AppealChallengeDetailProps & InjectedTransactionStatusModalProps) {
super(props);
this.state = {
voteOption: this.getVoteOption(),
salt: fetchSalt(this.props.appealChallengeID, this.props.user),
isReviewVoteModalOpen: false,
numTokens: undefined,
key: new Date().valueOf(),
};
}
public componentWillMount(): void {
const transactionSuccessContent = this.getTransactionSuccessContent();
this.props.setTransactions(this.getTransactions());
this.props.setTransactionStatusModalConfig({
transactionSuccessContent,
});
this.props.setHandleTransactionSuccessButtonClick(this.handleRevealVoteSuccessClose);
}
public render(): JSX.Element | null {
const { appealChallenge } = this.props;
const userHasRevealedVote =
this.props.userAppealChallengeData && !!this.props.userAppealChallengeData.didUserReveal;
const userHasCommittedVote =
this.props.userAppealChallengeData && !!this.props.userAppealChallengeData.didUserCommit;
const endTime = appealChallenge.poll.revealEndDate.toNumber();
const phaseLength = this.props.parameters.get(Parameters.challengeAppealRevealLen);
const secondaryPhaseLength = this.props.parameters.get(Parameters.challengeAppealCommitLen);
const transactions = this.getTransactions();
return (
<>
>
);
}
private getTransactionSuccessContent = (): TransactionStatusModalContentMap => {
const endTime = getLocalDateTimeStrings(this.props.appealChallenge.poll.revealEndDate.toNumber());
return {
[TransactionTypes.REVEAL_VOTE]: [
<>
Thanks for confirming your vote.
>,
<>
We are still waiting for all voters to confirm their votes. Please check back after{" "}
{endTime[0]} {endTime[1]}
{" "}
to see voting results. Thank you for your patience!
>,
],
};
};
private handleRevealVoteSuccessClose = (): void => {
this.props.updateTransactionStatusModalsState({ isTransactionSuccessModalOpen: false });
this.setState({ isReviewVoteModalOpen: false, key: new Date().valueOf() });
};
private getTransactions = (): any => {
return [
{
transaction: async () => {
this.props.updateTransactionStatusModalsState({
isWaitingTransactionModalOpen: true,
isTransactionProgressModalOpen: false,
isTransactionSuccessModalOpen: false,
transactionType: TransactionTypes.REVEAL_VOTE,
});
return this.revealVoteOnChallenge();
},
handleTransactionHash: (txHash: TxHash) => {
this.props.updateTransactionStatusModalsState({
isWaitingTransactionModalOpen: false,
isTransactionProgressModalOpen: true,
});
},
postTransaction: () => {
this.props.updateTransactionStatusModalsState({
isWaitingTransactionModalOpen: false,
isTransactionProgressModalOpen: false,
isTransactionSuccessModalOpen: true,
});
},
handleTransactionError: this.props.handleTransactionError,
},
];
};
private getVoteOption(): string | undefined {
const fetchedVote = fetchVote(this.props.appealChallengeID, this.props.user);
let voteOption;
if (fetchedVote) {
voteOption = fetchedVote.toString();
}
return voteOption;
}
private revealVoteOnChallenge = async (): Promise> => {
const pollID = this.props.appealChallengeID;
const voteOption: BigNumber = new BigNumber(this.state.voteOption as string);
const salt: BigNumber = new BigNumber(this.state.salt as string);
return this.context.revealVote(pollID, voteOption, salt);
};
private updateRevealVoteState = (data: any, callback?: () => void): void => {
if (callback) {
this.setState({ ...data }, callback);
} else {
this.setState({ ...data });
}
};
}
export default compose>(
hasTransactionStatusModals(transactionStatusModalConfig),
)(AppealChallengeRevealVote);