Skip to content

Commit 94936ba

Browse files
authored
Merge pull request #1099 from kleros/fix(subgraph)/number-of-votes
Fix(web, subgraph): number of votes on voting history
2 parents 78934e6 + cadc4f9 commit 94936ba

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

subgraph/src/DisputeKitClassic.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,17 @@ export function handleEvidenceEvent(event: EvidenceEvent): void {
4747
}
4848

4949
export function handleJustificationEvent(event: JustificationEvent): void {
50-
const coreDisputeID = event.params._coreDisputeID.toString();
51-
const coreDispute = Dispute.load(coreDisputeID);
50+
const contract = DisputeKitClassic.bind(event.address);
51+
const coreDisputeID = event.params._coreDisputeID;
52+
const coreDispute = Dispute.load(coreDisputeID.toString());
5253
const classicDisputeID = `${DISPUTEKIT_ID}-${coreDisputeID}`;
5354
const classicDispute = ClassicDispute.load(classicDisputeID);
5455
if (!classicDispute || !coreDispute) return;
56+
const choice = event.params._choice;
57+
const coreRoundIndex = coreDispute.currentRoundIndex;
58+
const roundInfo = contract.getRoundInfo(coreDisputeID, coreRoundIndex, choice);
5559
const currentLocalRoundID = classicDispute.id + "-" + classicDispute.currentLocalRoundIndex.toString();
56-
const currentRulingInfo = updateCountsAndGetCurrentRuling(currentLocalRoundID, event.params._choice);
60+
const currentRulingInfo = updateCountsAndGetCurrentRuling(currentLocalRoundID, choice, roundInfo.getChoiceCount());
5761
coreDispute.currentRuling = currentRulingInfo.ruling;
5862
coreDispute.tied = currentRulingInfo.tied;
5963
coreDispute.save();

subgraph/src/entities/ClassicRound.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ class CurrentRulingInfo {
2525
tied: boolean;
2626
}
2727

28-
export function updateCountsAndGetCurrentRuling(id: string, choice: BigInt): CurrentRulingInfo {
28+
export function updateCountsAndGetCurrentRuling(id: string, choice: BigInt, choiceCount: BigInt): CurrentRulingInfo {
2929
const round = ClassicRound.load(id);
3030
if (!round) return { ruling: ZERO, tied: false };
3131
const choiceNum = choice.toI32();
32-
const updatedCount = round.counts[choiceNum].plus(ONE);
32+
const delta = choiceCount.minus(round.counts[choiceNum]);
3333
let newCounts: BigInt[] = [];
3434
for (let i = 0; i < round.counts.length; i++) {
3535
if (BigInt.fromI32(i).equals(choice)) {
36-
newCounts.push(round.counts[i].plus(ONE));
36+
newCounts.push(choiceCount);
3737
} else {
3838
newCounts.push(round.counts[i]);
3939
}
@@ -43,14 +43,14 @@ export function updateCountsAndGetCurrentRuling(id: string, choice: BigInt): Cur
4343
if (choice.equals(round.winningChoice)) {
4444
if (round.tied) round.tied = false;
4545
} else {
46-
if (updatedCount.equals(currentWinningCount)) {
46+
if (choiceCount.equals(currentWinningCount)) {
4747
if (!round.tied) round.tied = true;
48-
} else if (updatedCount.gt(currentWinningCount)) {
48+
} else if (choiceCount.gt(currentWinningCount)) {
4949
round.winningChoice = choice;
5050
round.tied = false;
5151
}
5252
}
53-
round.totalVoted = round.totalVoted.plus(ONE);
53+
round.totalVoted = round.totalVoted.plus(delta);
5454
round.save();
5555
return { ruling: round.winningChoice, tied: round.tied };
5656
}

web/src/hooks/queries/useVotingHistory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const votingHistoryQuery = graphql(`
3636
export const useVotingHistory = (disputeID?: string) => {
3737
const isEnabled = disputeID !== undefined;
3838

39-
return useQuery({
39+
return useQuery<VotingHistoryQuery>({
4040
queryKey: ["refetchOnBlock", `VotingHistory${disputeID}`],
4141
enabled: isEnabled,
4242
queryFn: async () => await graphqlQueryFnHelper(votingHistoryQuery, { disputeID }),

web/src/pages/Cases/CaseDetails/Voting/VotingHistory.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ const VotingHistory: React.FC<{ arbitrable?: `0x${string}` }> = ({ arbitrable })
112112
<p>
113113
{localRounds.at(currentTab)?.totalVoted === rounds.at(currentTab)?.nbVotes
114114
? "All jurors voted"
115-
: localRounds.at(currentTab)?.totalVoted + " jurors voted out of " + rounds.at(currentTab)?.nbVotes}
115+
: localRounds.at(currentTab)?.totalVoted.toString() +
116+
` vote${localRounds.at(currentTab)?.totalVoted.toString() === "1" ? "" : "s"} casted out of ` +
117+
rounds.at(currentTab)?.nbVotes}
116118
</p>
117119
</StyledBox>
118120
<StyledAccordion

0 commit comments

Comments
 (0)