From 371009bee12bd8a9f0cfb3a9ed251790a63ffb2b Mon Sep 17 00:00:00 2001 From: Ludovic Levalleux Date: Mon, 14 Sep 2026 09:09:28 +0100 Subject: [PATCH 1/2] feat: restrict the network selector to Ethereum/Base and their testnets getEnvConfigs() returns every chain the SDK supports for an environment, and the whole dapp derives its chain list from it: the network selector, the "connect to" tooltip in the wallet status, isSupportedChain() and the subgraph chain list. Filter it once in lib/config so the selector offers only Ethereum and Base on production, and Sepolia and Base Sepolia on testing/staging. Local keeps its single Hardhat chain. Co-Authored-By: Claude Opus 5 (1M context) --- src/lib/config.ts | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/lib/config.ts b/src/lib/config.ts index 452ba9829..9ee06ac70 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -100,21 +100,38 @@ function getMetaTxApiKey(envConfig: ProtocolConfig) { return apiKey; } -export const envConfigsFilteredByEnv: ProtocolConfig[] = getEnvConfigs(envName); +// Chains the dapp exposes, per environment. getEnvConfigs() returns every chain +// the SDK supports for the environment (Polygon, Optimism and Arbitrum +// included); the dapp deliberately offers a subset in the network selector. +// Chain ids are hardcoded rather than imported from lib/constants/chains to +// avoid a circular import (that module reads envChainIds from here). +const supportedChainIdsPerEnv: Record = { + local: [31337], // Local Hardhat + testing: [11155111, 84532], // Sepolia, Base Sepolia + staging: [11155111, 84532], // Sepolia, Base Sepolia + production: [1, 8453] // Ethereum, Base +}; + +const supportedChainIds = supportedChainIdsPerEnv[envName]; + +export const envConfigsFilteredByEnv: ProtocolConfig[] = getEnvConfigs( + envName +).filter((envConf) => supportedChainIds.includes(envConf.chainId)); if (!envConfigsFilteredByEnv.length) { // Fail fast with context: everything below assumes at least one config, and // without this the app would crash later on an undefined defaultEnvConfig. - throw new Error(`No protocol config is available for envName ${envName}`); + throw new Error( + `No protocol config is available for envName ${envName} and chain ids ${supportedChainIds.join( + ", " + )}` + ); } export const envChainIds = envConfigsFilteredByEnv.map( (envConf) => envConf.chainId ); -// Chain the dapp starts on, per environment. getEnvConfigs() lists the Polygon -// config first, so without this the app would default to Polygon (Amoy on -// testing/staging). Chain ids are hardcoded rather than imported from -// lib/constants/chains to avoid a circular import (that module reads -// envChainIds from here). +// Chain the dapp starts on, per environment. Pinned explicitly rather than +// relying on whichever config getEnvConfigs() happens to return first. const defaultChainIdPerEnv: Record = { local: 31337, // Local Hardhat testing: 84532, // Base Sepolia From 9668a65f0a46a1070a8ea7fe57fa178d098cc3cc Mon Sep 17 00:00:00 2001 From: Ludovic Levalleux Date: Mon, 14 Sep 2026 09:18:33 +0100 Subject: [PATCH 2/2] fix(config): validate REACT_APP_ENV_NAME before looking up its chain ids MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit envName is an unchecked `as EnvironmentType` cast of an env var, so an unexpected value made supportedChainIdsPerEnv[envName] undefined. In practice getEnvConfigs() is evaluated before the .filter() callback and throws first, so the app did fail fast — but on the SDK's internal ordering rather than on anything this module guarantees. Check the lookup explicitly and throw a message that names the accepted values. Addresses PR #1185 review comment r4003308542. Co-Authored-By: Claude Opus 5 (1M context) --- src/lib/config.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lib/config.ts b/src/lib/config.ts index 9ee06ac70..185ad25b8 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -112,7 +112,19 @@ const supportedChainIdsPerEnv: Record = { production: [1, 8453] // Ethereum, Base }; -const supportedChainIds = supportedChainIdsPerEnv[envName]; +// envName is an unchecked cast of an env var, so at runtime it can be any +// string: look the chain ids up defensively and fail with a message that names +// the accepted values, rather than letting an unrelated error surface further +// down. +const supportedChainIds: number[] | undefined = + supportedChainIdsPerEnv[envName]; +if (!supportedChainIds) { + throw new Error( + `REACT_APP_ENV_NAME is "${envName}", expected one of ${Object.keys( + supportedChainIdsPerEnv + ).join(", ")}` + ); +} export const envConfigsFilteredByEnv: ProtocolConfig[] = getEnvConfigs( envName