Skip to content

Commit 3dc11c0

Browse files
committed
Dashboard: Contract pages cleanup (#6991)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR primarily focuses on refactoring the contract-related code to consistently use `clientContract` and `serverContract` variables instead of `contract`. This improves clarity and ensures that the correct contract instance is used in various components. ### Detailed summary - Replaced instances of `info.contract` with `info.clientContract` or `info.serverContract` across multiple files. - Updated conditions checking for localhost to use `info.isLocalhostChain`. - Modified return statements in several components to use the appropriate contract variable. - Adjusted metadata fetching and handling to align with the new contract structure. - Removed `ContractAnalyticsPageClient` usage in favor of direct `ContractAnalyticsPage` with `clientContract`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 49479d4 commit 3dc11c0

File tree

27 files changed

+196
-206
lines changed

27 files changed

+196
-206
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { notFound, redirect } from "next/navigation";
2-
import { localhost } from "thirdweb/chains";
32
import { getRawAccount } from "../../../../../../account/settings/getAccount";
43
import { getContractPageParamsInfo } from "../../_utils/getContractFromParams";
54
import { getContractPageMetadata } from "../../_utils/getContractPageMetadata";
@@ -20,25 +19,25 @@ export default async function Page(props: {
2019
notFound();
2120
}
2221

23-
if (info.chainMetadata.chainId === localhost.id) {
22+
if (info.isLocalhostChain) {
2423
return (
2524
<ContractDirectListingsPageClient
26-
contract={info.contract}
25+
contract={info.clientContract}
2726
isLoggedIn={!!account}
2827
/>
2928
);
3029
}
3130

3231
const { isDirectListingSupported, isInsightSupported } =
33-
await getContractPageMetadata(info.contract);
32+
await getContractPageMetadata(info.serverContract);
3433

3534
if (!isDirectListingSupported) {
3635
redirect(`/${params.chain_id}/${params.contractAddress}`);
3736
}
3837

3938
return (
4039
<ContractDirectListingsPage
41-
contract={info.contract}
40+
contract={info.clientContract}
4241
isLoggedIn={!!account}
4342
isInsightSupported={isInsightSupported}
4443
/>

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { notFound, redirect } from "next/navigation";
2-
import { localhost } from "thirdweb/chains";
32
import { getRawAccount } from "../../../../../../account/settings/getAccount";
43
import { getContractPageParamsInfo } from "../../_utils/getContractFromParams";
54
import { getContractPageMetadata } from "../../_utils/getContractPageMetadata";
@@ -21,25 +20,25 @@ export default async function Page(props: {
2120

2221
const twAccount = await getRawAccount();
2322

24-
if (info.chainMetadata.chainId === localhost.id) {
23+
if (info.isLocalhostChain) {
2524
return (
2625
<ContractEnglishAuctionsPageClient
27-
contract={info.contract}
26+
contract={info.clientContract}
2827
isLoggedIn={!!twAccount}
2928
/>
3029
);
3130
}
3231

3332
const { isEnglishAuctionSupported, isInsightSupported } =
34-
await getContractPageMetadata(info.contract);
33+
await getContractPageMetadata(info.serverContract);
3534

3635
if (!isEnglishAuctionSupported) {
3736
redirect(`/${params.chain_id}/${params.contractAddress}`);
3837
}
3938

4039
return (
4140
<ContractEnglishAuctionsPage
42-
contract={info.contract}
41+
contract={info.clientContract}
4342
isLoggedIn={!!twAccount}
4443
isInsightSupported={isInsightSupported}
4544
/>

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/_utils/getContractFromParams.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { serverThirdwebClient } from "@/constants/thirdweb-client.server";
12
import { mapV4ChainToV5Chain } from "contexts/map-chains";
23
import { getAddress, getContract, isAddress } from "thirdweb";
4+
import { localhost } from "thirdweb/chains";
35
import { fetchChainWithLocalOverrides } from "../../../../../../../utils/fetchChainWithLocalOverrides";
46
import { getUserThirdwebClient } from "../../../../../api/lib/getAuthToken";
57

@@ -17,7 +19,14 @@ export async function getContractPageParamsInfo(params: {
1719

1820
// attempt to get the auth token
1921

20-
const contract = getContract({
22+
const serverContract = getContract({
23+
address: contractAddress,
24+
// eslint-disable-next-line no-restricted-syntax
25+
chain: mapV4ChainToV5Chain(chainMetadata),
26+
client: serverThirdwebClient,
27+
});
28+
29+
const clientContract = getContract({
2130
address: contractAddress,
2231
// eslint-disable-next-line no-restricted-syntax
2332
chain: mapV4ChainToV5Chain(chainMetadata),
@@ -27,7 +36,9 @@ export async function getContractPageParamsInfo(params: {
2736

2837
return {
2938
chainMetadata,
30-
contract,
39+
serverContract,
40+
clientContract,
41+
isLocalhostChain: chainMetadata.chainId === localhost.id,
3142
};
3243
}
3344

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/account-permissions/page.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { notFound, redirect } from "next/navigation";
2-
import { localhost } from "thirdweb/chains";
32
import { getContractPageParamsInfo } from "../_utils/getContractFromParams";
43
import { getContractPageMetadata } from "../_utils/getContractPageMetadata";
54
import { AccountSignersClient } from "./AccountSigners.client";
@@ -18,18 +17,18 @@ export default async function Page(props: {
1817
notFound();
1918
}
2019

21-
const { contract, chainMetadata } = info;
20+
const { clientContract, serverContract, isLocalhostChain } = info;
2221

23-
if (chainMetadata.chainId === localhost.id) {
24-
return <AccountSignersClient contract={contract} />;
22+
if (isLocalhostChain) {
23+
return <AccountSignersClient contract={clientContract} />;
2524
}
2625

2726
const { isAccountPermissionsSupported } =
28-
await getContractPageMetadata(contract);
27+
await getContractPageMetadata(serverContract);
2928

3029
if (!isAccountPermissionsSupported) {
3130
redirect(`/${params.chain_id}/${params.contractAddress}`);
3231
}
3332

34-
return <AccountSigners contract={contract} />;
33+
return <AccountSigners contract={clientContract} />;
3534
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { notFound, redirect } from "next/navigation";
2-
import { localhost } from "thirdweb/chains";
32
import { getRawAccount } from "../../../../../account/settings/getAccount";
43
import { getContractPageParamsInfo } from "../_utils/getContractFromParams";
54
import { getContractPageMetadata } from "../_utils/getContractPageMetadata";
@@ -19,30 +18,31 @@ export default async function Page(props: {
1918
notFound();
2019
}
2120

22-
const { contract, chainMetadata } = info;
21+
const { clientContract, serverContract, chainMetadata, isLocalhostChain } =
22+
info;
2323

2424
const account = await getRawAccount();
2525

26-
if (contract.chain.id === localhost.id) {
26+
if (isLocalhostChain) {
2727
return (
2828
<AccountPageClient
29-
contract={contract}
29+
contract={clientContract}
3030
chainMetadata={chainMetadata}
3131
isLoggedIn={!!account}
3232
/>
3333
);
3434
}
3535

3636
const { isAccount, isInsightSupported } =
37-
await getContractPageMetadata(contract);
37+
await getContractPageMetadata(serverContract);
3838

3939
if (!isAccount) {
4040
redirect(`/${params.chain_id}/${params.contractAddress}`);
4141
}
4242

4343
return (
4444
<AccountPage
45-
contract={contract}
45+
contract={clientContract}
4646
chainMetadata={chainMetadata}
4747
isLoggedIn={!!account}
4848
isInsightSupported={isInsightSupported}

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { notFound, redirect } from "next/navigation";
2-
import { localhost } from "thirdweb/chains";
32
import { getRawAccount } from "../../../../../account/settings/getAccount";
43
import { getContractPageParamsInfo } from "../_utils/getContractFromParams";
54
import { getContractPageMetadata } from "../_utils/getContractPageMetadata";
@@ -19,19 +18,24 @@ export default async function Page(props: {
1918
notFound();
2019
}
2120

22-
const { contract, chainMetadata } = info;
21+
const { clientContract, serverContract, isLocalhostChain } = info;
2322

24-
const account = await getRawAccount();
23+
const [account, { isAccountFactory }] = await Promise.all([
24+
getRawAccount(),
25+
isLocalhostChain
26+
? { isAccountFactory: undefined }
27+
: getContractPageMetadata(serverContract),
28+
]);
2529

26-
if (chainMetadata.chainId === localhost.id) {
27-
return <AccountsPageClient contract={contract} isLoggedIn={!!account} />;
30+
if (isLocalhostChain) {
31+
return (
32+
<AccountsPageClient contract={clientContract} isLoggedIn={!!account} />
33+
);
2834
}
2935

30-
const { isAccountFactory } = await getContractPageMetadata(contract);
31-
3236
if (!isAccountFactory) {
3337
redirect(`/${params.chain_id}/${params.contractAddress}`);
3438
}
3539

36-
return <AccountsPage contract={contract} isLoggedIn={!!account} />;
40+
return <AccountsPage contract={clientContract} isLoggedIn={!!account} />;
3741
}

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/analytics/ContractAnalyticsPage.client.tsx

Lines changed: 0 additions & 35 deletions
This file was deleted.

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

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { notFound, redirect } from "next/navigation";
2-
import { localhost } from "thirdweb/chains";
32
import { type ThirdwebContract, resolveContractAbi } from "thirdweb/contract";
43
import { type Abi, toEventSelector, toFunctionSelector } from "thirdweb/utils";
54
import { getContractPageParamsInfo } from "../_utils/getContractFromParams";
65
import { getContractPageMetadata } from "../_utils/getContractPageMetadata";
76
import { ContractAnalyticsPage } from "./ContractAnalyticsPage";
8-
import { ContractAnalyticsPageClient } from "./ContractAnalyticsPage.client";
97

108
export default async function Page(props: {
119
params: Promise<{
@@ -20,29 +18,21 @@ export default async function Page(props: {
2018
notFound();
2119
}
2220

23-
const { eventSelectorToName, writeFnSelectorToName } = await getSelectors(
24-
info.contract,
25-
);
26-
27-
if (info.chainMetadata.chainId === localhost.id) {
28-
return (
29-
<ContractAnalyticsPageClient
30-
contract={info.contract}
31-
writeFnSelectorToNameRecord={writeFnSelectorToName}
32-
eventSelectorToNameRecord={eventSelectorToName}
33-
/>
34-
);
35-
}
36-
37-
const { isInsightSupported } = await getContractPageMetadata(info.contract);
21+
const [
22+
{ eventSelectorToName, writeFnSelectorToName },
23+
{ isInsightSupported },
24+
] = await Promise.all([
25+
getSelectors(info.serverContract),
26+
getContractPageMetadata(info.serverContract),
27+
]);
3828

3929
if (!isInsightSupported) {
4030
redirect(`/${params.chain_id}/${params.contractAddress}`);
4131
}
4232

4333
return (
4434
<ContractAnalyticsPage
45-
contract={info.contract}
35+
contract={info.clientContract}
4636
writeFnSelectorToNameRecord={writeFnSelectorToName}
4737
eventSelectorToNameRecord={eventSelectorToName}
4838
/>

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/claim-conditions/page.tsx

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { notFound, redirect } from "next/navigation";
2-
import { localhost } from "thirdweb/chains";
32
import { getRawAccount } from "../../../../../account/settings/getAccount";
43
import { ClaimConditions } from "../_components/claim-conditions/claim-conditions";
54
import { getContractPageParamsInfo } from "../_utils/getContractFromParams";
@@ -18,27 +17,39 @@ export default async function Page(props: {
1817
if (!info) {
1918
notFound();
2019
}
21-
const { contract, chainMetadata } = info;
20+
const { clientContract, serverContract, isLocalhostChain } = info;
2221

23-
const account = await getRawAccount();
22+
const [
23+
account,
24+
{
25+
isERC20ClaimConditionsSupported,
26+
isERC721ClaimConditionsSupported,
27+
supportedERCs,
28+
},
29+
] = await Promise.all([
30+
getRawAccount(),
31+
isLocalhostChain
32+
? {
33+
isERC20ClaimConditionsSupported: undefined,
34+
isERC721ClaimConditionsSupported: undefined,
35+
supportedERCs: undefined,
36+
}
37+
: getContractPageMetadata(serverContract),
38+
]);
2439

25-
if (chainMetadata.chainId === localhost.id) {
26-
return <ClaimConditionsClient contract={contract} isLoggedIn={!!account} />;
40+
if (isLocalhostChain) {
41+
return (
42+
<ClaimConditionsClient contract={clientContract} isLoggedIn={!!account} />
43+
);
2744
}
2845

29-
const {
30-
isERC20ClaimConditionsSupported,
31-
isERC721ClaimConditionsSupported,
32-
supportedERCs,
33-
} = await getContractPageMetadata(contract);
34-
3546
if (!isERC20ClaimConditionsSupported && !isERC721ClaimConditionsSupported) {
3647
redirect(`/${params.chain_id}/${params.contractAddress}`);
3748
}
3849

3950
return (
4051
<ClaimConditions
41-
contract={contract}
52+
contract={clientContract}
4253
isERC20={supportedERCs.isERC20}
4354
isLoggedIn={!!account}
4455
isMultiphase={true}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { notFound } from "next/navigation";
2-
import { localhost } from "thirdweb/chains";
32
import { resolveContractAbi } from "thirdweb/contract";
43
import { getContractPageParamsInfo } from "../_utils/getContractFromParams";
54
import { ContractCodePage } from "./contract-code-page";
@@ -18,23 +17,24 @@ export default async function Page(props: {
1817
notFound();
1918
}
2019

21-
const { contract, chainMetadata } = info;
20+
const { clientContract, serverContract, chainMetadata, isLocalhostChain } =
21+
info;
2222

23-
if (contract.chain.id === localhost.id) {
23+
if (isLocalhostChain) {
2424
return (
2525
<ContractCodePageClient
26-
contract={contract}
26+
contract={clientContract}
2727
chainMetadata={chainMetadata}
2828
/>
2929
);
3030
}
3131

32-
const abi = await resolveContractAbi(contract).catch(() => undefined);
32+
const abi = await resolveContractAbi(serverContract).catch(() => undefined);
3333

3434
return (
3535
<ContractCodePage
3636
abi={abi}
37-
contract={contract}
37+
contract={clientContract}
3838
chainMetadata={chainMetadata}
3939
/>
4040
);

0 commit comments

Comments
 (0)