Skip to content

Commit e91581a

Browse files
committed
Update chain stack type check (#4901)
## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview This PR introduces a new property `stackType` across various components and utilities, enhancing the handling of blockchain network configurations and metadata. ### Detailed summary - Added `stackType` property in `types.ts` for chains. - Updated `utils.ts` to include `stackType` from data. - Included `stackType` in `embed-setup.tsx` and `ConfigureNetworkForm.tsx`. - Modified the `isZkSyncChain` function to use `getChainMetadata` for `stackType` validation. - Removed the obsolete `getChainStack` function. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 985c4b0 commit e91581a

File tree

5 files changed

+14
-23
lines changed

5 files changed

+14
-23
lines changed

apps/dashboard/src/components/configure-networks/ConfigureNetworkForm.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export type NetworkConfigFormData = {
2828
type: "testnet" | "mainnet";
2929
icon: string;
3030
slug: string;
31+
stackType?: string;
3132
};
3233

3334
// lowercase it, replace all spaces with hyphens, and then strip all non-alphanumeric characters
@@ -71,6 +72,7 @@ export const ConfigureNetworkForm: React.FC<NetworkConfigFormProps> = ({
7172
type: editingChain?.testnet ? "testnet" : "mainnet",
7273
icon: editingChain?.icon?.url || "",
7374
slug: prefillSlug || editingChain?.slug || "",
75+
stackType: "",
7476
},
7577
mode: "onChange",
7678
});
@@ -146,6 +148,7 @@ export const ConfigureNetworkForm: React.FC<NetworkConfigFormProps> = ({
146148
format: "",
147149
},
148150
testnet: data.type === "testnet",
151+
stackType: data.stackType || "",
149152
};
150153
} else {
151154
configuredNetwork = {
@@ -170,6 +173,7 @@ export const ConfigureNetworkForm: React.FC<NetworkConfigFormProps> = ({
170173
format: "",
171174
}
172175
: undefined,
176+
stackType: data.stackType || "",
173177
};
174178
}
175179

apps/dashboard/src/contract-ui/tabs/embed/components/embed-setup.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ export const EmbedSetup: React.FC<EmbedSetupProps> = ({
243243
shortName: "unknown",
244244
slug: "unknown",
245245
testnet: false,
246+
stackType: "",
246247
};
247248

248249
const { register, watch } = useForm<{

packages/thirdweb/src/chains/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export type ChainMetadata = {
8282
type: string;
8383
bridges?: Readonly<Array<{ url: string }>>;
8484
};
85+
stackType: string;
8586
};
8687

8788
/**

packages/thirdweb/src/chains/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,5 +365,6 @@ function createChainMetadata(
365365
url: e.url,
366366
standard: "EIP3091",
367367
})) || data?.explorers,
368+
stackType: data?.stackType || "",
368369
};
369370
}
Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Chain } from "../../../chains/types.js";
2-
import { withCache } from "../../promise/withCache.js";
2+
import { getChainMetadata } from "../../../chains/utils.js";
33

44
export async function isZkSyncChain(chain: Chain) {
55
if (chain.id === 1337 || chain.id === 31337) {
@@ -12,36 +12,20 @@ export async function isZkSyncChain(chain: Chain) {
1212
chain.id === 300 ||
1313
chain.id === 302 ||
1414
chain.id === 11124 ||
15-
chain.id === 282 || // cronos zkevm testnet
16-
chain.id === 388 // cronos zkevm mainnet
15+
chain.id === 282 ||
16+
chain.id === 388 ||
17+
chain.id === 4654 ||
18+
chain.id === 333271
1719
) {
1820
return true;
1921
}
2022

2123
// fallback to checking the stack on rpc
2224
try {
23-
const stack = await getChainStack(chain.id);
24-
return stack === "zksync-stack";
25+
const chainMetadata = await getChainMetadata(chain);
26+
return chainMetadata.stackType === "zksync_stack";
2527
} catch {
2628
// If the network check fails, assume it's not a ZkSync chain
2729
return false;
2830
}
2931
}
30-
31-
async function getChainStack(chainId: number): Promise<string> {
32-
return withCache(
33-
async () => {
34-
const res = await fetch(`https://${chainId}.rpc.thirdweb.com/stack`);
35-
36-
if (!res.ok) {
37-
res.body?.cancel();
38-
throw new Error(`Error fetching stack for ${chainId}`);
39-
}
40-
41-
const data = await res.json();
42-
43-
return data.stack;
44-
},
45-
{ cacheKey: `stack:${chainId}`, cacheTime: 24 * 60 * 60 * 1000 },
46-
);
47-
}

0 commit comments

Comments
 (0)