Skip to content

Commit 004f377

Browse files
committed
[TOOL-4336] Dashboard: Fix contracts on custom chains not shown in contracts table (#6916)
<!-- ## 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 focuses on refactoring the chain fetching functionality within the application. It renames and updates the `getChains` function to `getChainsForNebula`, introduces a new utility `fetchChainWithLocalOverrides`, and modifies various components to utilize these changes. ### Detailed summary - Renamed `getChains` to `getChainsForNebula` in `getChainIds.ts`. - Updated references to `getChains` in `page.tsx` and `login/page.tsx` to use `getChainsForNebula`. - Introduced `fetchChainWithLocalOverrides` in `fetchChainWithLocalOverrides.ts`. - Replaced `fetchChain` with `fetchChainWithLocalOverrides` in `getSortedDeployedContracts.tsx` and `getContractFromParams.ts`. - Removed redundant local chain fetching logic from `getContractFromParams.ts`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent e197639 commit 004f377

File tree

6 files changed

+45
-34
lines changed

6 files changed

+45
-34
lines changed

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

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { getThirdwebClient } from "@/constants/thirdweb.server";
22
import { mapV4ChainToV5Chain } from "contexts/map-chains";
33
import { cookies } from "next/headers";
4-
import { TW_LOCAL_CHAIN_STORE } from "stores/storageKeys";
54
import { getAddress, getContract, isAddress } from "thirdweb";
6-
import type { ChainMetadata } from "thirdweb/chains";
7-
import { fetchChain } from "utils/fetchChain";
85
import { LAST_USED_TEAM_ID } from "../../../../../../../constants/cookies";
6+
import { fetchChainWithLocalOverrides } from "../../../../../../../utils/fetchChainWithLocalOverrides";
97
import { getAuthToken } from "../../../../../api/lib/getAuthToken";
108

119
export async function getContractPageParamsInfo(params: {
@@ -14,29 +12,7 @@ export async function getContractPageParamsInfo(params: {
1412
}) {
1513
const contractAddress = getCheckSummedAddress(params.contractAddress);
1614
const chainSlugOrId = params.chain_id;
17-
let chainMetadata = await fetchChain(chainSlugOrId).catch(() => null);
18-
19-
const cookieStore = await cookies();
20-
const localChainStoreValue = cookieStore.get(TW_LOCAL_CHAIN_STORE)?.value;
21-
22-
if (localChainStoreValue) {
23-
try {
24-
const chains = JSON.parse(decodeURIComponent(localChainStoreValue));
25-
if (typeof chains === "object" && Array.isArray(chains)) {
26-
const chainOverrides = chains as ChainMetadata[];
27-
const chain = chainOverrides.find(
28-
(c) =>
29-
c.slug === chainSlugOrId ||
30-
c.chainId === Number.parseInt(chainSlugOrId),
31-
);
32-
if (chain) {
33-
chainMetadata = chain;
34-
}
35-
}
36-
} catch {
37-
// noop
38-
}
39-
}
15+
const chainMetadata = await fetchChainWithLocalOverrides(chainSlugOrId);
4016

4117
if (!chainMetadata) {
4218
return undefined;

apps/dashboard/src/app/(app)/account/contracts/_components/getSortedDeployedContracts.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fetchChain } from "utils/fetchChain";
1+
import { fetchChainWithLocalOverrides } from "../../../../../utils/fetchChainWithLocalOverrides";
22
import {
33
type ProjectContract,
44
getProjectContracts,
@@ -19,7 +19,9 @@ export async function getSortedDeployedContracts(params: {
1919
const chainIds = Array.from(new Set(contracts.map((c) => c.chainId)));
2020
const chains = (
2121
await Promise.allSettled(
22-
chainIds.map((chainId) => fetchChain(chainId.toString())),
22+
chainIds.map((chainId) =>
23+
fetchChainWithLocalOverrides(chainId.toString()),
24+
),
2325
)
2426
)
2527
.filter((c) => c.status === "fulfilled")

apps/dashboard/src/app/nebula-app/(app)/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
getNebulaAuthTokenWalletAddress,
55
} from "../_utils/authToken";
66
import { ChatPageContent } from "./components/ChatPageContent";
7-
import { getChains } from "./utils/getChainIds";
7+
import { getChainsForNebula } from "./utils/getChainIds";
88

99
export default async function Page(props: {
1010
searchParams: Promise<{
@@ -15,7 +15,7 @@ export default async function Page(props: {
1515
const searchParams = await props.searchParams;
1616

1717
const [chains, authToken, accountAddress] = await Promise.all([
18-
getChains(searchParams.chain),
18+
getChainsForNebula(searchParams.chain),
1919
getNebulaAuthToken(),
2020
getNebulaAuthTokenWalletAddress(),
2121
]);

apps/dashboard/src/app/nebula-app/(app)/utils/getChainIds.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { unstable_cache } from "next/cache";
22
import type { ChainMetadata } from "thirdweb/chains";
33
import { fetchChain } from "utils/fetchChain";
44

5-
export const getChains = unstable_cache(
5+
export const getChainsForNebula = unstable_cache(
66
async (chainNamesOrIds: string[] | string | undefined) => {
77
if (!chainNamesOrIds) {
88
return [];
@@ -25,7 +25,7 @@ export const getChains = unstable_cache(
2525

2626
return chains;
2727
},
28-
["nebula_getChains"],
28+
["getChainsForNebula"],
2929
{
3030
revalidate: 60 * 60 * 24, // 24 hours
3131
},

apps/dashboard/src/app/nebula-app/login/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getChains } from "../(app)/utils/getChainIds";
1+
import { getChainsForNebula } from "../(app)/utils/getChainIds";
22
import { getNebulaAuthToken } from "../_utils/authToken";
33
import { NebulaLoggedOutStatePage } from "./NebulaLoginPage";
44

@@ -10,7 +10,7 @@ export default async function NebulaLogin(props: {
1010
}) {
1111
const searchParams = await props.searchParams;
1212
const authToken = await getNebulaAuthToken();
13-
const chains = await getChains(searchParams.chain);
13+
const chains = await getChainsForNebula(searchParams.chain);
1414

1515
return (
1616
<NebulaLoggedOutStatePage
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import "server-only";
2+
3+
import { cookies } from "next/headers";
4+
import type { ChainMetadata } from "thirdweb/chains";
5+
import { TW_LOCAL_CHAIN_STORE } from "../stores/storageKeys";
6+
import { fetchChain } from "./fetchChain";
7+
8+
export async function fetchChainWithLocalOverrides(
9+
chainIdOrSlug: string | number,
10+
): Promise<ChainMetadata | null> {
11+
const cookieStore = await cookies();
12+
const localChainStoreValue = cookieStore.get(TW_LOCAL_CHAIN_STORE)?.value;
13+
14+
if (localChainStoreValue) {
15+
try {
16+
const chains = JSON.parse(decodeURIComponent(localChainStoreValue));
17+
if (typeof chains === "object" && Array.isArray(chains)) {
18+
const chainOverrides = chains as ChainMetadata[];
19+
const savedChain = chainOverrides.find(
20+
(c) =>
21+
c.slug === chainIdOrSlug || c.chainId.toString() === chainIdOrSlug,
22+
);
23+
if (savedChain) {
24+
return savedChain;
25+
}
26+
}
27+
} catch {
28+
// noop
29+
}
30+
}
31+
32+
return fetchChain(chainIdOrSlug);
33+
}

0 commit comments

Comments
 (0)