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 all 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
32 changes: 32 additions & 0 deletions explorer/src/constants/columns/portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Chain } from "viem";
import { TdHandler } from "@/components/DataTable/components/TdHandler";
import { HelperIndicator } from "@/components/HelperIndicator";
import { Link } from "@/components/Link";
import { EMPTY_STRING, ZERO, ZERO_ADDRESS } from "@/constants";
import { ColumnsOptions } from "@/interfaces/components";
import { toPortalById } from "@/routes/constants";
import { getBlockExplorerLink } from "@/utils";
import { cropString } from "@/utils/stringUtils";
Expand Down Expand Up @@ -55,3 +57,33 @@ export const columns = ({ chain }: { chain: Chain }): ColumnDef<Portal>[] => [
},
},
];

export const portalColumnsOption: ColumnsOptions = {
0: {
minWidth: 150,
maxWidth: 200,
isRandomWidth: true,
},
1: {
minWidth: 200,
maxWidth: 400,
isRandomWidth: true,
},
2: {
width: 150,
},
};

export const skeletonPortals = (count: number) =>
Array(count)
.fill(null)
.map(() => ({
id: ZERO_ADDRESS,
name: EMPTY_STRING,
description: EMPTY_STRING,
ownerAddress: ZERO_ADDRESS,
ownerName: EMPTY_STRING,
modules: [],
isRevocable: false,
attestationCounter: ZERO,
}));
2 changes: 2 additions & 0 deletions explorer/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Address } from "viem";
import { arbitrum, arbitrumSepolia, base, baseSepolia, bsc, bscTestnet, linea } from "wagmi/chains";

import { lineaSepolia } from "@/config";
Expand All @@ -10,6 +11,7 @@ export const DASH = "-";
export const ZERO_STRING = "0";
export const TEN = 10;
export const ZERO = 0;
export const ZERO_ADDRESS: Address = "0x0000000000000000000000000000000000000000";
export const ITEMS_PER_PAGE_DEFAULT = 10;
export const ITEMS_SEARCHED_DEFAULT = 100;
export const CURRENT_PAGE_DEFAULT = 1;
Expand Down
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
12 changes: 6 additions & 6 deletions explorer/src/pages/Issuer/components/Portals/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ export const Portals: React.FC<IPortalProps> = ({ address }) => {
</tr>
</thead>
<tbody className="divide-y">
{portals.map(({ id, name, description, attestationCounter }) => (
<tr key={id}>
{portals.map((portal) => (
<tr key={portal.id}>
<td className="px-6 py-4 whitespace-nowrap text-xs font-medium">
<Button
name={name}
name={portal.name}
handler={() =>
navigate(toPortalById(id).replace(CHAIN_ID_ROUTE, network), {
navigate(toPortalById(portal.id).replace(CHAIN_ID_ROUTE, network), {
state: { from: location.pathname },
})
}
buttonType={EButtonType.TRANSPARENT}
iconRight={<ArrowRight />}
/>
</td>
<td className="px-6 py-4 whitespace-nowrap text-xs">{description}</td>
<td className="px-6 py-4 whitespace-nowrap text-xs font-medium">{attestationCounter}</td>
<td className="px-6 py-4 whitespace-nowrap text-xs">{portal.description}</td>
<td className="px-6 py-4 whitespace-nowrap text-xs font-medium">{portal.attestationCounter}</td>
</tr>
))}
</tbody>
Expand Down
39 changes: 39 additions & 0 deletions explorer/src/pages/Module/components/ModulePortals/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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 () => sdk.portal.findBy(undefined, undefined, { modules_contains: [moduleId] }),
{
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