From a67eede97adccf871b8361877e128369ace7920f Mon Sep 17 00:00:00 2001 From: Chirag Date: Tue, 3 Dec 2024 11:01:57 +0530 Subject: [PATCH] Refactor portal constants and ModulePortals component to use EMPTY_0X_STRING, EMPTY_STRING, and ZERO constants; optimize portal filtering in ModulePortals --- explorer/src/constants/columns/portal.tsx | 11 ++++++----- .../pages/Module/components/ModulePortals/index.tsx | 5 ++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/explorer/src/constants/columns/portal.tsx b/explorer/src/constants/columns/portal.tsx index 7231b875..5f0e8d69 100644 --- a/explorer/src/constants/columns/portal.tsx +++ b/explorer/src/constants/columns/portal.tsx @@ -6,6 +6,7 @@ import { Chain } from "viem"; import { TdHandler } from "@/components/DataTable/components/TdHandler"; import { HelperIndicator } from "@/components/HelperIndicator"; import { Link } from "@/components/Link"; +import { EMPTY_0X_STRING, EMPTY_STRING, ZERO } from "@/constants"; import { toPortalById } from "@/routes/constants"; import { getBlockExplorerLink } from "@/utils"; import { cropString } from "@/utils/stringUtils"; @@ -73,11 +74,11 @@ export const skeletonPortals = (count: number) => .fill(null) .map((_, index) => ({ id: `0x${index.toString(16).padStart(40, "0")}` as `0x${string}`, - name: "", - description: "", - ownerAddress: "0x0000000000000000000000000000000000000000" as `0x${string}`, - ownerName: "", + name: EMPTY_STRING, + description: EMPTY_STRING, + ownerAddress: `${EMPTY_0X_STRING}${"0".repeat(40)}` as `0x${string}`, + ownerName: EMPTY_STRING, modules: [] as `0x${string}`[], isRevocable: false, - attestationCounter: 0, + attestationCounter: ZERO, })); diff --git a/explorer/src/pages/Module/components/ModulePortals/index.tsx b/explorer/src/pages/Module/components/ModulePortals/index.tsx index da8cff96..7aa5f0ad 100644 --- a/explorer/src/pages/Module/components/ModulePortals/index.tsx +++ b/explorer/src/pages/Module/components/ModulePortals/index.tsx @@ -20,9 +20,8 @@ export const ModulePortals: React.FC<{ moduleId: Address }> = ({ moduleId }) => const { data: portals, isLoading } = useSWR( `${SWRKeys.GET_MODULE_PORTAL_LIST}/${moduleId}/${chain.id}`, async () => { - const allPortals = await sdk.portal.findBy(100, 0); - const portalList = allPortals.filter((portal) => portal.modules.includes(moduleId)); - return portalList.slice(0, 5).map((portal) => ({ + const portalList = await sdk.portal.findBy(5, 0, { modules_contains: [moduleId] }, "attestationCounter", "desc"); + return portalList.map((portal) => ({ ...portal, id: portal.id as `0x${string}`, }));