Skip to content

Commit 983a009

Browse files
committed
Render contract pages on client side for localhost chain
1 parent a365dd8 commit 983a009

File tree

58 files changed

+1217
-167
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1217
-167
lines changed

apps/dashboard/src/@3rdweb-sdk/react/hooks/useDashboardContractMetadata.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function useDashboardContractMetadata(contract: ThirdwebContract) {
1818
});
1919
}
2020

21-
type DashboardContractMetadata = {
21+
export type DashboardContractMetadata = {
2222
name: string;
2323
symbol: string;
2424
image: string;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"use client";
2+
3+
import type { ThirdwebContract } from "thirdweb";
4+
import { ErrorPage, LoadingPage } from "../../_components/page-skeletons";
5+
import { RedirectToContractOverview } from "../../_components/redirect-contract-overview.client";
6+
import { useContractPageMetadata } from "../../_hooks/useContractPageMetadata";
7+
import { ContractDirectListingsPage } from "./ContractDirectListingsPage";
8+
9+
export function ContractDirectListingsPageClient(props: {
10+
contract: ThirdwebContract;
11+
}) {
12+
const metadataQuery = useContractPageMetadata(props.contract);
13+
14+
if (metadataQuery.isPending) {
15+
return <LoadingPage />;
16+
}
17+
18+
if (metadataQuery.isError) {
19+
return <ErrorPage />;
20+
}
21+
22+
if (!metadataQuery.data.isDirectListingSupported) {
23+
return <RedirectToContractOverview contract={props.contract} />;
24+
}
25+
26+
return <ContractDirectListingsPage contract={props.contract} />;
27+
}

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/(marketplace)/direct-listings/page.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { notFound, redirect } from "next/navigation";
2+
import { localhost } from "thirdweb/chains";
23
import { getContractPageParamsInfo } from "../../_utils/getContractFromParams";
34
import { getContractPageMetadata } from "../../_utils/getContractPageMetadata";
45
import { ContractDirectListingsPage } from "./ContractDirectListingsPage";
6+
import { ContractDirectListingsPageClient } from "./ContractDirectListingsPage.client";
57

68
export default async function Page(props: {
79
params: {
@@ -15,6 +17,10 @@ export default async function Page(props: {
1517
notFound();
1618
}
1719

20+
if (info.chainMetadata.chainId === localhost.id) {
21+
return <ContractDirectListingsPageClient contract={info.contract} />;
22+
}
23+
1824
const { isDirectListingSupported } = await getContractPageMetadata(
1925
info.contract,
2026
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"use client";
2+
3+
import type { ThirdwebContract } from "thirdweb";
4+
import { ErrorPage, LoadingPage } from "../../_components/page-skeletons";
5+
import { RedirectToContractOverview } from "../../_components/redirect-contract-overview.client";
6+
import { useContractPageMetadata } from "../../_hooks/useContractPageMetadata";
7+
import { ContractEnglishAuctionsPage } from "./ContractEnglishAuctionsPage";
8+
9+
export function ContractEnglishAuctionsPageClient(props: {
10+
contract: ThirdwebContract;
11+
}) {
12+
const metadataQuery = useContractPageMetadata(props.contract);
13+
14+
if (metadataQuery.isPending) {
15+
return <LoadingPage />;
16+
}
17+
18+
if (metadataQuery.isError) {
19+
return <ErrorPage />;
20+
}
21+
22+
if (!metadataQuery.data.isEnglishAuctionSupported) {
23+
return <RedirectToContractOverview contract={props.contract} />;
24+
}
25+
26+
return <ContractEnglishAuctionsPage contract={props.contract} />;
27+
}

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/(marketplace)/english-auctions/page.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { notFound, redirect } from "next/navigation";
2+
import { localhost } from "thirdweb/chains";
23
import { getContractPageParamsInfo } from "../../_utils/getContractFromParams";
34
import { getContractPageMetadata } from "../../_utils/getContractPageMetadata";
45
import { ContractEnglishAuctionsPage } from "./ContractEnglishAuctionsPage";
6+
import { ContractEnglishAuctionsPageClient } from "./ContractEnglishAuctionsPage.client";
57

68
export default async function Page(props: {
79
params: {
@@ -15,6 +17,10 @@ export default async function Page(props: {
1517
notFound();
1618
}
1719

20+
if (info.chainMetadata.chainId === localhost.id) {
21+
return <ContractEnglishAuctionsPageClient contract={info.contract} />;
22+
}
23+
1824
const { isEnglishAuctionSupported } = await getContractPageMetadata(
1925
info.contract,
2026
);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Spinner } from "@/components/ui/Spinner/Spinner";
2+
3+
export function LoadingPage() {
4+
return (
5+
<div className="flex min-h-[300px] grow items-center justify-center">
6+
<Spinner className="size-10" />
7+
</div>
8+
);
9+
}
10+
11+
export function ErrorPage() {
12+
return (
13+
<div className="flex min-h-[300px] grow items-center justify-center">
14+
<p className="text-destructive-text">Failed to load contract</p>
15+
</div>
16+
);
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"use client";
2+
3+
import { useDashboardRouter } from "@/lib/DashboardRouter";
4+
import { useEffect, useRef } from "react";
5+
import type { ThirdwebContract } from "thirdweb";
6+
import { LoadingPage } from "./page-skeletons";
7+
8+
export function RedirectToContractOverview(props: {
9+
contract: ThirdwebContract;
10+
}) {
11+
const router = useDashboardRouter();
12+
const redirected = useRef(false);
13+
14+
// eslint-disable-next-line no-restricted-syntax
15+
useEffect(() => {
16+
if (redirected.current) {
17+
return;
18+
}
19+
redirected.current = true;
20+
router.replace(`/${props.contract.chain.id}/${props.contract.address}`);
21+
}, [router, props.contract]);
22+
23+
return <LoadingPage />;
24+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"use client";
2+
3+
import { useQuery } from "@tanstack/react-query";
4+
import type { ThirdwebContract } from "thirdweb";
5+
import { getContractPageMetadataSetup } from "../_utils/getContractPageMetadata";
6+
7+
export function useContractPageMetadata(contract: ThirdwebContract) {
8+
return useQuery({
9+
queryKey: ["getContractPageMetadataSetup", contract],
10+
queryFn: () => {
11+
return getContractPageMetadataSetup(contract, () =>
12+
Promise.resolve(false),
13+
);
14+
},
15+
retry: false,
16+
refetchOnWindowFocus: false,
17+
});
18+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { useQuery } from "@tanstack/react-query";
2+
import { type ThirdwebContract, resolveContractAbi } from "thirdweb/contract";
3+
4+
export function useResolveContractABI(contract: ThirdwebContract) {
5+
return useQuery({
6+
queryKey: ["resolveContractAbi", contract],
7+
queryFn: () => {
8+
return resolveContractAbi(contract);
9+
},
10+
retry: false,
11+
refetchOnWindowFocus: false,
12+
});
13+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
44
import { Button } from "@/components/ui/button";
55
import { CheckIcon, CircleAlertIcon, RotateCcwIcon } from "lucide-react";
66
import { useState } from "react";
7-
import { ConfigureNetworks } from "../../../../../components/configure-networks/ConfigureNetworks";
8-
import { addChainOverrides } from "../../../../../stores/chainStores";
7+
import { addChainOverrides } from "stores/chainStores";
8+
import { ConfigureNetworks } from "../../../../../../components/configure-networks/ConfigureNetworks";
99

1010
export function ConfigureCustomChain(props: {
1111
chainSlug: string;

0 commit comments

Comments
 (0)