From 29a8733d876120912bea05c11d2964d5b837b863 Mon Sep 17 00:00:00 2001 From: nhestrompia Date: Mon, 28 Aug 2023 16:01:20 +0300 Subject: [PATCH] fix(web): court-ongoing-stats --- subgraph/schema.graphql | 2 ++ subgraph/src/KlerosCore.ts | 22 +++++++++++++++++++-- subgraph/src/entities/Court.ts | 2 ++ web/.env.devnet.public | 2 +- web/src/hooks/queries/useCourtDetails.ts | 2 ++ web/src/pages/Courts/CourtDetails/Stats.tsx | 2 +- 6 files changed, 28 insertions(+), 4 deletions(-) diff --git a/subgraph/schema.graphql b/subgraph/schema.graphql index ee53ed2bc..3d5655bc2 100644 --- a/subgraph/schema.graphql +++ b/subgraph/schema.graphql @@ -128,6 +128,8 @@ type Court @entity { supportedDisputeKits: [DisputeKit!]! disputes: [Dispute!]! @derivedFrom(field: "court") numberDisputes: BigInt! + numberClosedDisputes: BigInt! + numberAppealingDisputes: BigInt! stakedJurors: [JurorTokensPerCourt!]! @derivedFrom(field: "court") numberStakedJurors: BigInt! stake: BigInt! diff --git a/subgraph/src/KlerosCore.ts b/subgraph/src/KlerosCore.ts index e2c30e895..ca559e787 100644 --- a/subgraph/src/KlerosCore.ts +++ b/subgraph/src/KlerosCore.ts @@ -84,14 +84,23 @@ export function handleDisputeCreation(event: DisputeCreation): void { } export function handleNewPeriod(event: NewPeriod): void { + const contract = KlerosCore.bind(event.address); const disputeID = event.params._disputeID; const dispute = Dispute.load(disputeID.toString()); + const disputeStorage = contract.disputes(disputeID); + const courtID = disputeStorage.value0.toString(); + const court = Court.load(courtID); if (!dispute) return; + if (!court) return; const newPeriod = getPeriodName(event.params._period); if (dispute.period === "vote") { updateCasesVoting(BigInt.fromI32(-1), event.block.timestamp); + } else if (newPeriod === "evidence") { + court.numberAppealingDisputes = court.numberAppealingDisputes.minus(ONE); } else if (newPeriod === "vote") { updateCasesVoting(ONE, event.block.timestamp); + } else if (newPeriod === "appeal") { + court.numberAppealingDisputes = court.numberAppealingDisputes.plus(ONE); } else if (newPeriod === "execution") { const contract = KlerosCore.bind(event.address); const currentRulingInfo = contract.currentRuling(disputeID); @@ -99,19 +108,28 @@ export function handleNewPeriod(event: NewPeriod): void { dispute.overridden = currentRulingInfo.getOverridden(); dispute.tied = currentRulingInfo.getTied(); dispute.save(); + court.numberAppealingDisputes = court.numberAppealingDisputes.minus(ONE); } dispute.period = newPeriod; dispute.lastPeriodChange = event.block.timestamp; dispute.save(); + court.save(); } export function handleRuling(event: Ruling): void { - const disputeID = event.params._disputeID.toString(); - const dispute = Dispute.load(disputeID); + const contract = KlerosCore.bind(event.address); + const disputeID = event.params._disputeID; + const dispute = Dispute.load(disputeID.toString()); + const disputeStorage = contract.disputes(disputeID); + const courtID = disputeStorage.value0.toString(); + const court = Court.load(courtID); if (!dispute) return; dispute.ruled = true; dispute.save(); updateCasesRuled(ONE, event.block.timestamp); + if (!court) return; + court.numberClosedDisputes = court.numberClosedDisputes.plus(ONE); + court.save(); } export function handleAppealDecision(event: AppealDecision): void { diff --git a/subgraph/src/entities/Court.ts b/subgraph/src/entities/Court.ts index 520f9b2c7..895457846 100644 --- a/subgraph/src/entities/Court.ts +++ b/subgraph/src/entities/Court.ts @@ -14,6 +14,8 @@ export function createCourtFromEvent(event: CourtCreated): void { court.timesPerPeriod = event.params._timesPerPeriod; court.supportedDisputeKits = event.params._supportedDisputeKits.map((value) => value.toString()); court.numberDisputes = ZERO; + court.numberClosedDisputes = ZERO; + court.numberAppealingDisputes = ZERO; court.numberStakedJurors = ZERO; court.stake = ZERO; court.delayedStake = ZERO; diff --git a/web/.env.devnet.public b/web/.env.devnet.public index 498b71954..dbeb18169 100644 --- a/web/.env.devnet.public +++ b/web/.env.devnet.public @@ -1,4 +1,4 @@ # Do not enter sensitive information here. export REACT_APP_DEPLOYMENT=devnet -export REACT_APP_KLEROS_CORE_SUBGRAPH_DEVNET=https://api.thegraph.com/subgraphs/name/alcercu/kleroscoredev +export REACT_APP_KLEROS_CORE_SUBGRAPH_DEVNET=https://api.thegraph.com/subgraphs/name/nhestrompia/kleros-core-v2-devnet export REACT_APP_DISPUTE_TEMPLATE_ARBGOERLI_SUBGRAPH_DEVNET=https://api.thegraph.com/subgraphs/name/alcercu/templateregistrydevnet \ No newline at end of file diff --git a/web/src/hooks/queries/useCourtDetails.ts b/web/src/hooks/queries/useCourtDetails.ts index ad6f1c966..90a820842 100644 --- a/web/src/hooks/queries/useCourtDetails.ts +++ b/web/src/hooks/queries/useCourtDetails.ts @@ -11,6 +11,8 @@ const courtDetailsQuery = graphql(` minStake alpha numberDisputes + numberClosedDisputes + numberAppealingDisputes numberStakedJurors stake paidETH diff --git a/web/src/pages/Courts/CourtDetails/Stats.tsx b/web/src/pages/Courts/CourtDetails/Stats.tsx index ec25c74a7..f26fb1fcc 100644 --- a/web/src/pages/Courts/CourtDetails/Stats.tsx +++ b/web/src/pages/Courts/CourtDetails/Stats.tsx @@ -71,7 +71,7 @@ const stats: IStat[] = [ }, { title: "In Progress", - getText: (data) => data?.numberDisputes, + getText: (data) => data?.numberDisputes - data?.numberClosedDisputes, color: "orange", icon: BalanceIcon, },