From 0e6e40ed84caa7a90925173927e27ab633e4ad9a Mon Sep 17 00:00:00 2001 From: Chirag Date: Thu, 28 Nov 2024 11:29:59 +0530 Subject: [PATCH] Added GET_RECENT_ATTESTATION_GLOBAL enum, updated RecentAttestations component to handle global attestations, and made minor changes to SchemaLoadingSkeleton and Schema components. --- explorer/src/interfaces/swr/enum.ts | 1 + .../components/RecentAttestations/index.tsx | 20 +++++++++++-------- .../SchemaLoadingSkeleton/index.tsx | 14 ++++++------- explorer/src/pages/Schema/index.tsx | 10 ++++++++-- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/explorer/src/interfaces/swr/enum.ts b/explorer/src/interfaces/swr/enum.ts index d3d8d96f..abf8bc93 100644 --- a/explorer/src/interfaces/swr/enum.ts +++ b/explorer/src/interfaces/swr/enum.ts @@ -14,4 +14,5 @@ export enum SWRKeys { GET_PORTAL_BY_ID = "getPortalByID", GET_PORTAL_MODULE_LIST = "getPortalModuleList", GET_PORTAL_LIST = "getPortalList", + GET_RECENT_ATTESTATION_GLOBAL = "GET_RECENT_ATTESTATION_GLOBAL", } diff --git a/explorer/src/pages/Schema/components/RecentAttestations/index.tsx b/explorer/src/pages/Schema/components/RecentAttestations/index.tsx index 11b02ef3..d4325724 100644 --- a/explorer/src/pages/Schema/components/RecentAttestations/index.tsx +++ b/explorer/src/pages/Schema/components/RecentAttestations/index.tsx @@ -9,19 +9,23 @@ import { SWRKeys } from "@/interfaces/swr/enum"; import { useNetworkContext } from "@/providers/network-provider/context"; import { APP_ROUTES } from "@/routes/constants"; -export const RecentAttestations: React.FC<{ schemaId: string }> = ({ schemaId }) => { +export const RecentAttestations: React.FC<{ schemaId?: string }> = ({ schemaId }) => { const { sdk, network: { chain, network }, } = useNetworkContext(); - const { data: attestations, isLoading } = useSWR( - `${SWRKeys.GET_RECENT_ATTESTATION}/${schemaId}/${chain.id}`, - () => sdk.attestation.findBy(5, 0, { schema: schemaId }, "attestedDate", "desc"), - { - shouldRetryOnError: false, - }, - ); + const fetchKey = schemaId + ? `${SWRKeys.GET_RECENT_ATTESTATION}/${schemaId}/${chain.id}` + : `${SWRKeys.GET_RECENT_ATTESTATION_GLOBAL}/${chain.id}`; + + const fetchFunction = schemaId + ? () => sdk.attestation.findBy(5, 0, { schema: schemaId }, "attestedDate", "desc") + : () => sdk.attestation.findBy(5, 0, {}, "attestedDate", "desc"); + + const { data: attestations, isLoading } = useSWR(fetchKey, fetchFunction, { + shouldRetryOnError: false, + }); const columnsSkeletonRef = useRef(columnsSkeleton(columns({ sortByDate: false }), attestationColumnsOption)); const data = isLoading diff --git a/explorer/src/pages/Schema/components/SchemaLoadingSkeleton/index.tsx b/explorer/src/pages/Schema/components/SchemaLoadingSkeleton/index.tsx index 7d10e068..fc617122 100644 --- a/explorer/src/pages/Schema/components/SchemaLoadingSkeleton/index.tsx +++ b/explorer/src/pages/Schema/components/SchemaLoadingSkeleton/index.tsx @@ -4,24 +4,24 @@ export const SchemaLoadingSkeleton = () => { return (
- +
- - +
- +
diff --git a/explorer/src/pages/Schema/index.tsx b/explorer/src/pages/Schema/index.tsx index 48ddea64..454d2527 100644 --- a/explorer/src/pages/Schema/index.tsx +++ b/explorer/src/pages/Schema/index.tsx @@ -11,7 +11,7 @@ import { useNetworkContext } from "@/providers/network-provider/context"; import { RecentAttestations } from "./components/RecentAttestations"; import { SchemaLoadingSkeleton } from "./components/SchemaLoadingSkeleton"; -export const Schema = () => { +export const Schema: React.FC = () => { const { id } = useParams(); const { sdk, @@ -25,7 +25,9 @@ export const Schema = () => { } = useSWR( `${SWRKeys.GET_SCHEMA_BY_ID}/${id}/${chain.id}`, async () => { - if (id && regexEthAddress.byNumberOfChar[64].test(id)) return sdk.schema.findOneById(id); + if (id && regexEthAddress.byNumberOfChar[64].test(id)) { + return sdk.schema.findOneById(id); + } }, { shouldRetryOnError: false, @@ -34,8 +36,11 @@ export const Schema = () => { ); if (isLoading || isValidating) return ; + if (!schema) return ; + const isContextURL = urlRegex.test(schema.context); + return (
@@ -55,6 +60,7 @@ export const Schema = () => { {schema.context}