Skip to content

Commit 0b510f8

Browse files
committed
Handle contract page crash if contract is not deployed (#5132)
## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on improving error handling in the `ContractOverviewPage` and validating contract existence in the `layout.tsx`. It introduces an `ErrorBoundary` around the `PublishedBy` component and checks if a contract is deployed before rendering the layout. ### Detailed summary - Wrapped the `PublishedBy` component in an `ErrorBoundary` in `ContractOverviewPage.tsx`. - Added a check for contract deployment using `isContractDeployed` in `layout.tsx`. - Implemented a `notFound()` call if the contract is not deployed, with a TODO for future improvements. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 5351d4e commit 0b510f8

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/layout.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { SidebarLayout } from "@/components/blocks/SidebarLayout";
33
import { ContractMetadata } from "components/custom-contract/contract-header/contract-metadata";
44
import { DeprecatedAlert } from "components/shared/DeprecatedAlert";
55
import type { Metadata } from "next";
6+
import { notFound } from "next/navigation";
67
import { getContractMetadata } from "thirdweb/extensions/common";
8+
import { isContractDeployed } from "thirdweb/utils";
79
import { resolveFunctionSelectors } from "../../../../../lib/selectors";
810
import { shortenIfAddress } from "../../../../../utils/usedapp-external";
911
import { ConfigureCustomChain } from "./ConfigureCustomChain";
@@ -26,6 +28,13 @@ export default async function Layout(props: {
2628
return <ConfigureCustomChain chainSlug={props.params.chain_id} />;
2729
}
2830

31+
// check if the contract exists
32+
const isValidContract = await isContractDeployed(info.contract);
33+
if (!isValidContract) {
34+
// TODO - replace 404 with a better page to upsale deploy or other thirdweb products
35+
notFound();
36+
}
37+
2938
const { contract, chainMetadata } = info;
3039
const contractPageMetadata = await getContractPageMetadata(contract);
3140
const sidebarLinks = getContractPageSidebarLinks({

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/overview/ContractOverviewPage.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { PublishedBy } from "components/contract-components/shared/published-by";
2+
import { ErrorBoundary } from "react-error-boundary";
23
import type { ThirdwebContract } from "thirdweb";
34
import { AnalyticsOverview } from "./components/Analytics";
45
import { BuildYourApp } from "./components/BuildYourApp";
@@ -99,7 +100,9 @@ export const ContractOverviewPage: React.FC<ContractOverviewPageProps> = ({
99100
/>
100101
</div>
101102
<div className="shrink-0 lg:w-[300px]">
102-
<PublishedBy contract={contract} />
103+
<ErrorBoundary fallback={null}>
104+
<PublishedBy contract={contract} />
105+
</ErrorBoundary>
103106
</div>
104107
</div>
105108
);

0 commit comments

Comments
 (0)