Skip to content

[TOOL-4336] Dashboard: Fix contracts on custom chains not shown in contracts table #6916

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

Merged
merged 1 commit into from
May 1, 2025
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
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { getThirdwebClient } from "@/constants/thirdweb.server";
import { mapV4ChainToV5Chain } from "contexts/map-chains";
import { cookies } from "next/headers";
import { TW_LOCAL_CHAIN_STORE } from "stores/storageKeys";
import { getAddress, getContract, isAddress } from "thirdweb";
import type { ChainMetadata } from "thirdweb/chains";
import { fetchChain } from "utils/fetchChain";
import { LAST_USED_TEAM_ID } from "../../../../../../../constants/cookies";
import { fetchChainWithLocalOverrides } from "../../../../../../../utils/fetchChainWithLocalOverrides";
import { getAuthToken } from "../../../../../api/lib/getAuthToken";

export async function getContractPageParamsInfo(params: {
Expand All @@ -14,29 +12,7 @@ export async function getContractPageParamsInfo(params: {
}) {
const contractAddress = getCheckSummedAddress(params.contractAddress);
const chainSlugOrId = params.chain_id;
let chainMetadata = await fetchChain(chainSlugOrId).catch(() => null);

const cookieStore = await cookies();
const localChainStoreValue = cookieStore.get(TW_LOCAL_CHAIN_STORE)?.value;

if (localChainStoreValue) {
try {
const chains = JSON.parse(decodeURIComponent(localChainStoreValue));
if (typeof chains === "object" && Array.isArray(chains)) {
const chainOverrides = chains as ChainMetadata[];
const chain = chainOverrides.find(
(c) =>
c.slug === chainSlugOrId ||
c.chainId === Number.parseInt(chainSlugOrId),
);
if (chain) {
chainMetadata = chain;
}
}
} catch {
// noop
}
}
const chainMetadata = await fetchChainWithLocalOverrides(chainSlugOrId);

if (!chainMetadata) {
return undefined;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fetchChain } from "utils/fetchChain";
import { fetchChainWithLocalOverrides } from "../../../../../utils/fetchChainWithLocalOverrides";
import {
type ProjectContract,
getProjectContracts,
Expand All @@ -19,7 +19,9 @@ export async function getSortedDeployedContracts(params: {
const chainIds = Array.from(new Set(contracts.map((c) => c.chainId)));
const chains = (
await Promise.allSettled(
chainIds.map((chainId) => fetchChain(chainId.toString())),
chainIds.map((chainId) =>
fetchChainWithLocalOverrides(chainId.toString()),
),
)
)
.filter((c) => c.status === "fulfilled")
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/src/app/nebula-app/(app)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
getNebulaAuthTokenWalletAddress,
} from "../_utils/authToken";
import { ChatPageContent } from "./components/ChatPageContent";
import { getChains } from "./utils/getChainIds";
import { getChainsForNebula } from "./utils/getChainIds";

export default async function Page(props: {
searchParams: Promise<{
Expand All @@ -15,7 +15,7 @@ export default async function Page(props: {
const searchParams = await props.searchParams;

const [chains, authToken, accountAddress] = await Promise.all([
getChains(searchParams.chain),
getChainsForNebula(searchParams.chain),
getNebulaAuthToken(),
getNebulaAuthTokenWalletAddress(),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { unstable_cache } from "next/cache";
import type { ChainMetadata } from "thirdweb/chains";
import { fetchChain } from "utils/fetchChain";

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

return chains;
},
["nebula_getChains"],
["getChainsForNebula"],
{
revalidate: 60 * 60 * 24, // 24 hours
},
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/src/app/nebula-app/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getChains } from "../(app)/utils/getChainIds";
import { getChainsForNebula } from "../(app)/utils/getChainIds";
import { getNebulaAuthToken } from "../_utils/authToken";
import { NebulaLoggedOutStatePage } from "./NebulaLoginPage";

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

return (
<NebulaLoggedOutStatePage
Expand Down
33 changes: 33 additions & 0 deletions apps/dashboard/src/utils/fetchChainWithLocalOverrides.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import "server-only";

import { cookies } from "next/headers";
import type { ChainMetadata } from "thirdweb/chains";
import { TW_LOCAL_CHAIN_STORE } from "../stores/storageKeys";
import { fetchChain } from "./fetchChain";

export async function fetchChainWithLocalOverrides(
chainIdOrSlug: string | number,
): Promise<ChainMetadata | null> {
const cookieStore = await cookies();
const localChainStoreValue = cookieStore.get(TW_LOCAL_CHAIN_STORE)?.value;

if (localChainStoreValue) {
try {
const chains = JSON.parse(decodeURIComponent(localChainStoreValue));
if (typeof chains === "object" && Array.isArray(chains)) {
const chainOverrides = chains as ChainMetadata[];
const savedChain = chainOverrides.find(
(c) =>
c.slug === chainIdOrSlug || c.chainId.toString() === chainIdOrSlug,
);
if (savedChain) {
return savedChain;
}
}
} catch {
// noop
}
}

return fetchChain(chainIdOrSlug);
}
Loading