Skip to content

Commit 08c1d2b

Browse files
committed
refactor: use AVALANCHE_CHAIN_IDS constant for chain ID checks
Replace hardcoded chain ID comparisons with AVALANCHE_CHAIN_ID_VALUES array derived from the AVALANCHE_CHAIN_IDS constant. This makes it easier to add new chains without modifying multiple conditions.
1 parent e98a5b6 commit 08c1d2b

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

client/src/clients/createAvalancheClient.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
RpcSchema,
99
Transport,
1010
} from "viem";
11+
import { AVALANCHE_CHAIN_IDS } from "../methods/consts.js";
1112
import { AvalanchePublicRpcSchema } from "../methods/public/avalanchePublicRpcSchema.js";
1213
import { createAdminApiClient } from "./createAdminApiClient.js";
1314
import { createCChainClient } from "./createCChainClient.js";
@@ -23,6 +24,8 @@ import {
2324
AvalancheClientConfig,
2425
} from "./types/createAvalancheClient.js";
2526
import { createAvalancheTransportClient } from "./utils.js";
27+
28+
const AVALANCHE_CHAIN_ID_VALUES = Object.values(AVALANCHE_CHAIN_IDS) as number[];
2629
/**
2730
* Creates an Avalanche Client with a given transport configured for a Chain.
2831
*
@@ -120,7 +123,7 @@ export function createAvalancheClient<
120123
});
121124
const extendedClient = client.extend(avalanchePublicActions) as any;
122125

123-
if (chainConfig?.id !== 43_112 && chainConfig?.id !== 43_113 && chainConfig?.id !== 43_114) {
126+
if (!chainConfig?.id || !AVALANCHE_CHAIN_ID_VALUES.includes(chainConfig.id)) {
124127
return {
125128
...extendedClient,
126129
};

client/src/clients/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import {
99
} from "viem";
1010
import { commonHeaders } from "./common.js";
1111
import { AvalancheTransportConfig, ClientType } from "./types/types.js";
12+
import { AVALANCHE_CHAIN_IDS } from "../methods/consts.js";
13+
14+
const AVALANCHE_CHAIN_ID_VALUES = Object.values(AVALANCHE_CHAIN_IDS) as number[];
1215

1316
export function createAvalancheTransportClient<
1417
transport extends Transport,
@@ -94,7 +97,7 @@ function getClientURL(
9497
clientType: ClientType = "public",
9598
transportType: "http" | "webSocket" = "http"
9699
): string | undefined {
97-
if (chain?.id !== 43_112 && chain?.id !== 43_113 && chain?.id !== 43_114) {
100+
if (!chain?.id || !AVALANCHE_CHAIN_ID_VALUES.includes(chain.id)) {
98101
return url ?? chain?.rpcUrls.default[transportType]?.[0];
99102
}
100103

0 commit comments

Comments
 (0)