Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(explorer): As a user, I want the Module page to display Portals leveraging it #851

Merged
merged 5 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions explorer/src/constants/columns/portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -55,3 +56,29 @@ export const columns = ({ chain }: { chain: Chain }): ColumnDef<Portal>[] => [
},
},
];

export const portalColumnsOption = {
name: {
width: "25%",
},
description: {
width: "50%",
},
owner: {
width: "25%",
},
};
Chirag-S-Kotian marked this conversation as resolved.
Show resolved Hide resolved

export const skeletonPortals = (count: number) =>
Array(count)
.fill(null)
.map((_, index) => ({
id: `0x${index.toString(16).padStart(40, "0")}` as `0x${string}`,
Chirag-S-Kotian marked this conversation as resolved.
Show resolved Hide resolved
name: EMPTY_STRING,
description: EMPTY_STRING,
ownerAddress: `${EMPTY_0X_STRING}${"0".repeat(40)}` as `0x${string}`,
Chirag-S-Kotian marked this conversation as resolved.
Show resolved Hide resolved
ownerName: EMPTY_STRING,
modules: [] as `0x${string}`[],
Chirag-S-Kotian marked this conversation as resolved.
Show resolved Hide resolved
isRevocable: false,
attestationCounter: ZERO,
}));
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}`,
})),
),
Chirag-S-Kotian marked this conversation as resolved.
Show resolved Hide resolved
);

if (!portals) return null;
Expand Down
45 changes: 45 additions & 0 deletions explorer/src/pages/Module/components/ModulePortals/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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 portalList = await sdk.portal.findBy(5, 0, { modules_contains: [moduleId] }, "attestationCounter", "desc");
return portalList.map((portal) => ({
...portal,
id: portal.id as `0x${string}`,
}));
Chirag-S-Kotian marked this conversation as resolved.
Show resolved Hide resolved
},
{
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>
);
};
Loading