Skip to content

Commit

Permalink
fix(web): court-ongoing-stats
Browse files Browse the repository at this point in the history
  • Loading branch information
nhestrompia committed Aug 28, 2023
1 parent f6c2582 commit 8c7905e
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
2 changes: 2 additions & 0 deletions subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
22 changes: 20 additions & 2 deletions subgraph/src/KlerosCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,34 +84,52 @@ 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);
dispute.currentRuling = currentRulingInfo.getRuling();
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 {
Expand Down
2 changes: 2 additions & 0 deletions subgraph/src/entities/Court.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export function createCourtFromEvent(event: CourtCreated): void {
court.timesPerPeriod = event.params._timesPerPeriod;
court.supportedDisputeKits = event.params._supportedDisputeKits.map<string>((value) => value.toString());
court.numberDisputes = ZERO;
court.numberClosedDisputes = ZERO;
court.numberAppealingDisputes = ZERO;
court.numberStakedJurors = ZERO;
court.stake = ZERO;
court.delayedStake = ZERO;
Expand Down
2 changes: 1 addition & 1 deletion web/.env.devnet.public
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions web/src/hooks/queries/useCourtDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const courtDetailsQuery = graphql(`
minStake
alpha
numberDisputes
numberClosedDisputes
numberAppealingDisputes
numberStakedJurors
stake
paidETH
Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/Courts/CourtDetails/Stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const stats: IStat[] = [
},
{
title: "In Progress",
getText: (data) => data?.numberDisputes,
getText: (data) => data?.numberDisputes - data?.numberClosedDisputes,
color: "orange",
icon: BalanceIcon,
},
Expand Down

0 comments on commit 8c7905e

Please sign in to comment.