Skip to content

Commit

Permalink
Added portal columns options, skeleton portals, and module portal lis…
Browse files Browse the repository at this point in the history
…t feature
  • Loading branch information
Chirag-S-Kotian committed Dec 2, 2024
1 parent 0dcb079 commit 5a4cf08
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 1 deletion.
26 changes: 26 additions & 0 deletions explorer/src/constants/columns/portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,29 @@ export const columns = ({ chain }: { chain: Chain }): ColumnDef<Portal>[] => [
},
},
];

export const portalColumnsOption = {
name: {
width: "25%",
},
description: {
width: "50%",
},
owner: {
width: "25%",
},
};

export const skeletonPortals = (count: number) =>
Array(count)
.fill(null)
.map((_, index) => ({
id: `0x${index.toString(16).padStart(40, "0")}` as `0x${string}`,
name: "",
description: "",
ownerAddress: "0x0000000000000000000000000000000000000000" as `0x${string}`,
ownerName: "",
modules: [] as `0x${string}`[],
isRevocable: false,
attestationCounter: 0,
}));
1 change: 1 addition & 0 deletions explorer/src/interfaces/swr/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum SWRKeys {
GET_RECENT_ATTESTATION_GLOBAL = "getRecentAttestations",
GET_MODULE_LIST = "getModuleList",
GET_MODULE_COUNT = "getModuleCount",
GET_MODULE_PORTAL_LIST = "getModulePortalList",
SEARCH = "search",
GET_PORTALS_BY_ISSUER = "getPortalsByIssuer",
GET_PORTAL_BY_ID = "getPortalByID",
Expand Down
7 changes: 6 additions & 1 deletion explorer/src/pages/Issuer/components/Portals/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ export const Portals: React.FC<IPortalProps> = ({ address }) => {
const location = useLocation();

const { data: portals } = useSWR(`${SWRKeys.GET_PORTALS_BY_ISSUER}/${address}`, () =>
sdk.portal.findBy(undefined, undefined, { ownerAddress: address }),
sdk.portal.findBy(undefined, undefined, { ownerAddress: address }).then((portalList) =>
portalList.map((portal) => ({
...portal,
id: portal.id as `0x${string}`,
})),
),
);

if (!portals) return null;
Expand Down
46 changes: 46 additions & 0 deletions explorer/src/pages/Module/components/ModulePortals/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { t } from "i18next";
import { useRef } from "react";
import useSWR from "swr";
import { Address } from "viem";

import { DataTable } from "@/components/DataTable";
import { columns, portalColumnsOption, skeletonPortals } from "@/constants/columns/portal";
import { columnsSkeleton } from "@/constants/columns/skeleton";
import { SWRKeys } from "@/interfaces/swr/enum";
import { useNetworkContext } from "@/providers/network-provider/context";
import { APP_ROUTES } from "@/routes/constants";
import { isNotNullOrUndefined } from "@/utils";

export const ModulePortals: React.FC<{ moduleId: Address }> = ({ moduleId }) => {
const {
sdk,
network: { chain },
} = useNetworkContext();

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) => ({
...portal,
id: portal.id as `0x${string}`,
}));
},
{
shouldRetryOnError: false,
},
);

const columnsSkeletonRef = useRef(columnsSkeleton(columns({ chain }), portalColumnsOption));
const data = isLoading
? { columns: columnsSkeletonRef.current, list: skeletonPortals(5) }
: { columns: columns({ chain }), list: portals?.filter(isNotNullOrUndefined) || [] };

return (
<div className="flex flex-col gap-6 w-full px-5 md:px-10">
<p className="text-xl not-italic font-semibold text-text-primary dark:text-whiteDefault">{t("portal.title")}</p>
<DataTable columns={data.columns} data={data.list} link={APP_ROUTES.PORTAL_BY_ID} />
</div>
);
};
2 changes: 2 additions & 0 deletions explorer/src/pages/Module/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useNetworkContext } from "@/providers/network-provider/context";
import { getBlockExplorerLink } from "@/utils";

import { ModuleLoadingSkeleton } from "./components/ModuleLoadingSkeleton";
import { ModulePortals } from "./components/ModulePortals";

export const Module = () => {
const { id } = useParams();
Expand Down Expand Up @@ -60,6 +61,7 @@ export const Module = () => {
<ArrowUpRight height="auto" width="1rem" />
</a>
</div>
<ModulePortals moduleId={module.moduleAddress} />
</section>
);
};

0 comments on commit 5a4cf08

Please sign in to comment.