From 302ef1e5a590486815d7a5aa73b853fb5ca68c12 Mon Sep 17 00:00:00 2001 From: marino <102478601+kemuru@users.noreply.github.com> Date: Wed, 25 Oct 2023 12:07:08 +0200 Subject: [PATCH] feat(web, subgraph): add timestamp field to disputekitdispute, update query, get latest kit --- subgraph/schema.graphql | 2 ++ subgraph/src/entities/ClassicDispute.ts | 1 + web/src/hooks/queries/useClassicAppealQuery.ts | 13 ++++++++++--- web/src/hooks/useClassicAppealContext.tsx | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/subgraph/schema.graphql b/subgraph/schema.graphql index ad646bee1..851cfc015 100644 --- a/subgraph/schema.graphql +++ b/subgraph/schema.graphql @@ -19,6 +19,7 @@ interface DisputeKitDispute { coreDispute: Dispute! localRounds: [DisputeKitRound!]! @derivedFrom(field: "localDispute") currentLocalRoundIndex: BigInt! + timestamp: BigInt! } interface DisputeKitRound { @@ -236,6 +237,7 @@ type ClassicDispute implements DisputeKitDispute @entity { coreDispute: Dispute! localRounds: [DisputeKitRound!]! @derivedFrom(field: "localDispute") currentLocalRoundIndex: BigInt! + timestamp: BigInt! numberOfChoices: BigInt! extraData: Bytes! diff --git a/subgraph/src/entities/ClassicDispute.ts b/subgraph/src/entities/ClassicDispute.ts index 9d49c7210..bc0604517 100644 --- a/subgraph/src/entities/ClassicDispute.ts +++ b/subgraph/src/entities/ClassicDispute.ts @@ -9,5 +9,6 @@ export function createClassicDisputeFromEvent(event: DisputeCreation): void { classicDispute.currentLocalRoundIndex = ZERO; classicDispute.numberOfChoices = event.params._numberOfChoices; classicDispute.extraData = event.params._extraData; + classicDispute.timestamp = event.block.timestamp; classicDispute.save(); } diff --git a/web/src/hooks/queries/useClassicAppealQuery.ts b/web/src/hooks/queries/useClassicAppealQuery.ts index bcdce6ebb..ff4eb4968 100644 --- a/web/src/hooks/queries/useClassicAppealQuery.ts +++ b/web/src/hooks/queries/useClassicAppealQuery.ts @@ -5,7 +5,7 @@ import { graphqlQueryFnHelper } from "utils/graphqlQueryFnHelper"; export type { ClassicAppealQuery }; const classicAppealQuery = graphql(` - query ClassicAppeal($disputeID: ID!) { + query ClassicAppeal($disputeID: ID!, $orderBy: DisputeKitDispute_orderBy, $orderDirection: OrderDirection) { dispute(id: $disputeID) { period court { @@ -16,7 +16,7 @@ const classicAppealQuery = graphql(` id } lastPeriodChange - disputeKitDispute { + disputeKitDispute(orderBy: $orderBy, orderDirection: $orderDirection) { id currentLocalRoundIndex localRounds { @@ -37,6 +37,13 @@ export const useClassicAppealQuery = (id?: string | number) => { return useQuery({ queryKey: ["refetchOnBlock", `classicAppealQuery${id}`], enabled: isEnabled, - queryFn: async () => await graphqlQueryFnHelper(classicAppealQuery, { disputeID: id?.toString() }), + queryFn: async () => + isEnabled + ? await graphqlQueryFnHelper(classicAppealQuery, { + disputeID: id?.toString(), + orderBy: "timestamp", + orderDirection: "asc", + }) + : undefined, }); }; diff --git a/web/src/hooks/useClassicAppealContext.tsx b/web/src/hooks/useClassicAppealContext.tsx index c751d4446..706b8577e 100644 --- a/web/src/hooks/useClassicAppealContext.tsx +++ b/web/src/hooks/useClassicAppealContext.tsx @@ -102,7 +102,7 @@ const getCurrentLocalRound = (dispute?: ClassicAppealQuery["dispute"]) => { if (!dispute) return undefined; const period = dispute.period; - const currentLocalRoundIndex = dispute.disputeKitDispute[0]?.currentLocalRoundIndex; + const currentLocalRoundIndex = dispute.disputeKitDispute.at(-1)?.currentLocalRoundIndex; const adjustedRoundIndex = ["appeal", "execution"].includes(period) ? currentLocalRoundIndex : currentLocalRoundIndex - 1;