Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Claim Rewards Fixes #846

Merged
merged 2 commits into from
Feb 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 77 additions & 2 deletions packages/core/src/contracts/tcr/civilTCR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,67 @@ export class CivilTCR extends BaseWrapper<CivilTCRContract> {
};
}

public async getUserAppealChallengeData(appealChallengeID: BigNumber, user: EthAddress): Promise<UserChallengeData> {
let didUserCommit;
let didUserReveal;
let didUserCollect;
let didUserRescue = false;
let didCollectAmount;
let isVoterWinner;
let salt;
let numTokens;
let choice;
const [, , resolved] = await this.instance.challenges.callAsync(appealChallengeID);
const pollData = await this.voting.getPoll(appealChallengeID);
let canUserReveal;
let canUserRescue;
let canUserCollect;
if (user) {
didUserCommit = await this.voting.didCommitVote(user, appealChallengeID);
if (didUserCommit) {
didUserReveal = await this.voting.didRevealVote(user, appealChallengeID);
if (resolved) {
if (didUserReveal) {
const reveal = await this.voting.getRevealedVoteEvent(appealChallengeID, user);
salt = reveal!.args.salt;
numTokens = reveal!.args.numTokens;
choice = reveal!.args.choice;
didUserCollect = await this.instance.tokenClaims.callAsync(appealChallengeID, user);
isVoterWinner = await this.voting.isVoterWinner(appealChallengeID, user);
canUserCollect = isVoterWinner && !didUserCollect;
} else {
didUserRescue =
!(await this.voting.canRescueTokens(user, appealChallengeID)) &&
!(await isInCommitStage(pollData)) &&
!(await isInRevealStage(pollData));
}
} else {
canUserReveal = !didUserReveal && (await isInRevealStage(pollData));
}
canUserRescue = !didUserRescue && !(await isInCommitStage(pollData)) && !(await isInRevealStage(pollData));
}
}

if (didUserCollect) {
didCollectAmount = await this.getRewardClaimed(appealChallengeID, user);
}

return {
didUserCommit,
didUserReveal,
canUserReveal,
didUserCollect,
canUserCollect,
didUserRescue,
canUserRescue,
didCollectAmount,
isVoterWinner,
salt,
numTokens,
choice,
};
}

public async getUserChallengeData(challengeID: BigNumber, user: EthAddress): Promise<UserChallengeData> {
let didUserCommit;
let didUserReveal;
Expand All @@ -551,7 +612,9 @@ export class CivilTCR extends BaseWrapper<CivilTCRContract> {
let salt;
let numTokens;
let choice;
const [, , resolved] = await this.instance.challenges.callAsync(challengeID);
const challenge = new Challenge(this.ethApi, this.instance, challengeID);
const challengeData = await challenge.getChallengeData();
const resolved = challengeData.resolved;
const pollData = await this.voting.getPoll(challengeID);
let canUserReveal;
let canUserRescue;
Expand All @@ -567,7 +630,19 @@ export class CivilTCR extends BaseWrapper<CivilTCRContract> {
numTokens = reveal!.args.numTokens;
choice = reveal!.args.choice;
didUserCollect = await this.instance.tokenClaims.callAsync(challengeID, user);
isVoterWinner = await this.voting.isVoterWinner(challengeID, user);
if (challengeData.appeal && challengeData.appeal.appealGranted) {
if (
challengeData.appeal.appealChallenge &&
challengeData.appeal.appealChallenge.resolved &&
(await this.voting.isPollPassed(challengeData.appeal.appealChallengeID))
) {
isVoterWinner = await this.voting.isVoterWinner(challengeID, user);
} else {
isVoterWinner = !(await this.voting.isVoterWinner(challengeID, user));
}
} else {
isVoterWinner = await this.voting.isVoterWinner(challengeID, user);
}
canUserCollect = isVoterWinner && !didUserCollect;
} else {
didUserRescue =
Expand Down
2 changes: 1 addition & 1 deletion packages/dapp/src/components/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class Main extends React.Component<DispatchProp<any> & RouteComponentProps<any>>
<Route path="/mgmt/:newsroomAddress" component={NewsroomManagement} />
<Route path="/mgmt-v1/:newsroomAddress" component={NewsroomManagementV1} />
<Route path="/parameterizer" component={Parameterizer} />
<Route path="/createNewsroom" component={CreateNewsroom} />
<Route path="/create-newsroom" component={CreateNewsroom} />
<Route path="/signupNewsroom" component={SignUpNewsroom} />
<Route path="/government" component={Government} />
<Route path="/dashboard/:activeDashboardTab" component={Dashboard} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ const mapToStateToProps = (
let challengeStatement: any = "";
let appealStatement: any = "";
let appealChallengeStatement: any = "";
if (challenge) {
if (challenge && challenge.challenge) {
challengeStatement = content.get(challenge.challenge.challengeStatementURI!);

if (challenge.challenge.appeal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const transactionLabels = {
const multiStepTransactionLabels = {
[TransactionTypes.APPROVE_CHALLENGE_APPEAL]: "1 of 3",
[TransactionTypes.PUBLISH_CONTENT]: "2 of 3",
[TransactionTypes.CHALLENGE_APPEAL]: "2 of 3",
[TransactionTypes.CHALLENGE_APPEAL]: "3 of 3",
};

const denialSuffix = ", you need to confirm the transaction in your MetaMask wallet.";
Expand Down
2 changes: 1 addition & 1 deletion packages/dapp/src/helpers/listingEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export async function initializeChallengeSubscriptions(dispatch: Dispatch<any>,

// if the challenge ID corresponds to an appeal challenge, get any user data for it
if (!pollID.equals(challengeId)) {
const appealChallengeUserData = await tcr.getUserChallengeData(pollID, user);
const appealChallengeUserData = await tcr.getUserAppealChallengeData(pollID, user);
dispatch(addUserAppealChallengeData(pollID.toString(), user, appealChallengeUserData));
dispatch(linkAppealChallengeToChallenge(pollID.toString(), challengeId.toString()));
}
Expand Down