Skip to content

Commit 8c7905e

Browse files
committed
fix(web): court-ongoing-stats
1 parent f6c2582 commit 8c7905e

File tree

6 files changed

+28
-4
lines changed

6 files changed

+28
-4
lines changed

subgraph/schema.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ type Court @entity {
128128
supportedDisputeKits: [DisputeKit!]!
129129
disputes: [Dispute!]! @derivedFrom(field: "court")
130130
numberDisputes: BigInt!
131+
numberClosedDisputes: BigInt!
132+
numberAppealingDisputes: BigInt!
131133
stakedJurors: [JurorTokensPerCourt!]! @derivedFrom(field: "court")
132134
numberStakedJurors: BigInt!
133135
stake: BigInt!

subgraph/src/KlerosCore.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,34 +84,52 @@ export function handleDisputeCreation(event: DisputeCreation): void {
8484
}
8585

8686
export function handleNewPeriod(event: NewPeriod): void {
87+
const contract = KlerosCore.bind(event.address);
8788
const disputeID = event.params._disputeID;
8889
const dispute = Dispute.load(disputeID.toString());
90+
const disputeStorage = contract.disputes(disputeID);
91+
const courtID = disputeStorage.value0.toString();
92+
const court = Court.load(courtID);
8993
if (!dispute) return;
94+
if (!court) return;
9095
const newPeriod = getPeriodName(event.params._period);
9196
if (dispute.period === "vote") {
9297
updateCasesVoting(BigInt.fromI32(-1), event.block.timestamp);
98+
} else if (newPeriod === "evidence") {
99+
court.numberAppealingDisputes = court.numberAppealingDisputes.minus(ONE);
93100
} else if (newPeriod === "vote") {
94101
updateCasesVoting(ONE, event.block.timestamp);
102+
} else if (newPeriod === "appeal") {
103+
court.numberAppealingDisputes = court.numberAppealingDisputes.plus(ONE);
95104
} else if (newPeriod === "execution") {
96105
const contract = KlerosCore.bind(event.address);
97106
const currentRulingInfo = contract.currentRuling(disputeID);
98107
dispute.currentRuling = currentRulingInfo.getRuling();
99108
dispute.overridden = currentRulingInfo.getOverridden();
100109
dispute.tied = currentRulingInfo.getTied();
101110
dispute.save();
111+
court.numberAppealingDisputes = court.numberAppealingDisputes.minus(ONE);
102112
}
103113
dispute.period = newPeriod;
104114
dispute.lastPeriodChange = event.block.timestamp;
105115
dispute.save();
116+
court.save();
106117
}
107118

108119
export function handleRuling(event: Ruling): void {
109-
const disputeID = event.params._disputeID.toString();
110-
const dispute = Dispute.load(disputeID);
120+
const contract = KlerosCore.bind(event.address);
121+
const disputeID = event.params._disputeID;
122+
const dispute = Dispute.load(disputeID.toString());
123+
const disputeStorage = contract.disputes(disputeID);
124+
const courtID = disputeStorage.value0.toString();
125+
const court = Court.load(courtID);
111126
if (!dispute) return;
112127
dispute.ruled = true;
113128
dispute.save();
114129
updateCasesRuled(ONE, event.block.timestamp);
130+
if (!court) return;
131+
court.numberClosedDisputes = court.numberClosedDisputes.plus(ONE);
132+
court.save();
115133
}
116134

117135
export function handleAppealDecision(event: AppealDecision): void {

subgraph/src/entities/Court.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export function createCourtFromEvent(event: CourtCreated): void {
1414
court.timesPerPeriod = event.params._timesPerPeriod;
1515
court.supportedDisputeKits = event.params._supportedDisputeKits.map<string>((value) => value.toString());
1616
court.numberDisputes = ZERO;
17+
court.numberClosedDisputes = ZERO;
18+
court.numberAppealingDisputes = ZERO;
1719
court.numberStakedJurors = ZERO;
1820
court.stake = ZERO;
1921
court.delayedStake = ZERO;

web/.env.devnet.public

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Do not enter sensitive information here.
22
export REACT_APP_DEPLOYMENT=devnet
3-
export REACT_APP_KLEROS_CORE_SUBGRAPH_DEVNET=https://api.thegraph.com/subgraphs/name/alcercu/kleroscoredev
3+
export REACT_APP_KLEROS_CORE_SUBGRAPH_DEVNET=https://api.thegraph.com/subgraphs/name/nhestrompia/kleros-core-v2-devnet
44
export REACT_APP_DISPUTE_TEMPLATE_ARBGOERLI_SUBGRAPH_DEVNET=https://api.thegraph.com/subgraphs/name/alcercu/templateregistrydevnet

web/src/hooks/queries/useCourtDetails.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const courtDetailsQuery = graphql(`
1111
minStake
1212
alpha
1313
numberDisputes
14+
numberClosedDisputes
15+
numberAppealingDisputes
1416
numberStakedJurors
1517
stake
1618
paidETH

web/src/pages/Courts/CourtDetails/Stats.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const stats: IStat[] = [
7171
},
7272
{
7373
title: "In Progress",
74-
getText: (data) => data?.numberDisputes,
74+
getText: (data) => data?.numberDisputes - data?.numberClosedDisputes,
7575
color: "orange",
7676
icon: BalanceIcon,
7777
},

0 commit comments

Comments
 (0)