Skip to content

Commit 4d4446a

Browse files
committed
chore(api-reference) Add override Chain logic
1 parent a702f4c commit 4d4446a

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

apps/api-reference/src/components/EvmProvider/chain-overrides.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { defineChain } from "viem";
21
import type { Chain } from "viem";
2+
import { defineChain } from "viem";
33

44
/**
55
* Chain overrides for chains that are not available in viem's built-in chain list.
@@ -10,10 +10,10 @@ import type { Chain } from "viem";
1010
* 2. Add a new defineChain entry with the following required fields:
1111
* - id: chainId. id in EvmChains.json is the name
1212
* - name: Chain display name
13-
* - nativeCurrency: { name, symbol, decimals }
14-
* - rpcUrls: { default: { http: ['...'] } }
13+
* - nativeCurrency: \{ name, symbol, decimals \}
14+
* - rpcUrls: \{ default: \{ http: ['...'] \} \}
1515
* - testnet: true/false (optional, defaults to false for mainnet)
16-
* - blockExplorers: { default: { name, url } } (optional)
16+
* - blockExplorers: \{ default: \{ name, url \} \} (optional)
1717
*/
1818
export const chainOverrides: readonly Chain[] = [
1919
// Example chain override (remove or replace with actual chains):
@@ -75,4 +75,3 @@ export const chainOverrides: readonly Chain[] = [
7575
},
7676
}),
7777
];
78-

apps/api-reference/src/components/EvmProvider/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@ import type { ReactNode } from "react";
1111
import * as chains from "viem/chains";
1212
import { WagmiProvider, createConfig, http, useChainId } from "wagmi";
1313

14+
import { chainOverrides } from "./chain-overrides";
1415
import { metadata } from "../../metadata";
1516

1617
const CHAINS = allEvmChainIds
17-
.map((id) => Object.values(chains).find((chain) => chain.id === id))
18+
.map((id) => {
19+
// First, check if we have an override for this chain
20+
const overrideChain = chainOverrides.find((chain) => chain.id === id);
21+
if (overrideChain) return overrideChain;
22+
23+
// Fall back to viem's built-in chains
24+
return Object.values(chains).find((chain) => chain.id === id);
25+
})
1826
.filter((chain) => chain !== undefined) as unknown as readonly [
1927
chains.Chain,
2028
...chains.Chain[],

0 commit comments

Comments
 (0)