From ef284ae4c7f176d079acd977855fda7d959411d4 Mon Sep 17 00:00:00 2001 From: Chirag <157453139+Chirag-S-Kotian@users.noreply.github.com> Date: Fri, 29 Nov 2024 22:59:42 +0530 Subject: [PATCH] feat(explorer): As a user, I want the Portal page to display latest Attestations (#837) --- explorer/src/interfaces/swr/enum.ts | 4 +++- explorer/src/pages/Portal/index.tsx | 2 ++ .../components/RecentAttestations/index.tsx | 24 ++++++++++++------- .../SchemaLoadingSkeleton/index.tsx | 14 +++++------ explorer/src/pages/Schema/index.tsx | 10 ++++++-- 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/explorer/src/interfaces/swr/enum.ts b/explorer/src/interfaces/swr/enum.ts index d3d8d96f..f717d253 100644 --- a/explorer/src/interfaces/swr/enum.ts +++ b/explorer/src/interfaces/swr/enum.ts @@ -6,7 +6,9 @@ export enum SWRKeys { GET_RELATED_ATTESTATION = "getRelatedAttestations", GET_ATTESTATION_LIST = "getAttestationList", GET_ATTESTATION_COUNT = "getAttestationCount", - GET_RECENT_ATTESTATION = "getRecentAttestations", + GET_RECENT_ATTESTATION_SCHEMA = "getRecentAttestationsSchema", + GET_RECENT_ATTESTATION_PORTAL = "getRecentAttestationsPortal", + GET_RECENT_ATTESTATION_GLOBAL = "getRecentAttestations", GET_MODULE_LIST = "getModuleList", GET_MODULE_COUNT = "getModuleCount", SEARCH = "search", diff --git a/explorer/src/pages/Portal/index.tsx b/explorer/src/pages/Portal/index.tsx index c19b0a4b..e8f20d35 100644 --- a/explorer/src/pages/Portal/index.tsx +++ b/explorer/src/pages/Portal/index.tsx @@ -15,6 +15,7 @@ import { useNetworkContext } from "@/providers/network-provider/context"; import { PortalLoadingSkeleton } from "./components/PortalLoadingSkeleton"; import { PortalModules } from "./components/PortalModules"; +import { RecentAttestations } from "../Schema/components/RecentAttestations"; export const Portal = () => { const { id } = useParams(); @@ -92,6 +93,7 @@ export const Portal = () => { ))} + ); diff --git a/explorer/src/pages/Schema/components/RecentAttestations/index.tsx b/explorer/src/pages/Schema/components/RecentAttestations/index.tsx index 11b02ef3..28067f4f 100644 --- a/explorer/src/pages/Schema/components/RecentAttestations/index.tsx +++ b/explorer/src/pages/Schema/components/RecentAttestations/index.tsx @@ -9,19 +9,27 @@ 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; portalId?: string }> = ({ schemaId, portalId }) => { 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_SCHEMA}/${schemaId}/${chain.id}` + : portalId + ? `${SWRKeys.GET_RECENT_ATTESTATION_PORTAL}/${portalId}/${chain.id}` + : `${SWRKeys.GET_RECENT_ATTESTATION_GLOBAL}/${chain.id}`; + + const fetchFunction = schemaId + ? () => sdk.attestation.findBy(5, 0, { schema: schemaId }, "attestedDate", "desc") + : portalId + ? () => sdk.attestation.findBy(5, 0, { portal: portalId }, "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}