EMBED-89: support multi-namespace for current chains#2419
EMBED-89: support multi-namespace for current chains#2419tanguyenvn wants to merge 11 commits intomasterfrom
Conversation
- IWeb3AuthState: currentChainId → currentChainIds: Partial<Record<ChainNamespaceType, string>>
- IWeb3AuthCore: add currentChainIds getter, getCurrentChain(namespace), update switchChain({ chainId, namespace })
- IBaseWeb3AuthHookContext: replace chainId/chainNamespace with currentChainIds
- noModal.ts: full per-namespace state, setChainForNamespace, getCurrentChain
- React/Vue contexts: replace chainId/chainNamespace state with currentChainIds
- useChain(namespace): returns CustomChainConfig | undefined for that namespace
- useSwitchChain: switchChain({ chainId, namespace }) — namespace required
- useWeb3Auth: expose currentChainIds, drop chainId/chainNamespace from Omit
- useSolanaWallet: use useChain(SOLANA) instead of currentChain.rpcTarget
- wagmi providers: getCurrentChain(EIP155) instead of currentChain
- BaseConnector: checkSwitchChainRequirements and abstract switchChain accept { chainId, namespace }
- AuthConnector: remove multi-namespace guard, route by explicit namespace param
- WalletConnectV2: remove multi-namespace guard, accept namespace param
- MetaMask/Coinbase/InjectedEVM: accept namespace param; internal init callsites pass chainConfig.chainNamespace
- WalletStandard (Solana): change from throw to no-op (chain switch is local state-only at SDK level)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
a44818b to
b255b0e
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
| const { chainId, namespace } = params; | ||
| const { chainId: currentChainId } = this.provider; | ||
| if (currentChainId === newChainId) return; | ||
| if (currentChainId === chainId) return; |
There was a problem hiding this comment.
Cross-namespace chainId collision silently skips chain switch
High Severity
The switchChain method compares this.provider.chainId (the WS Embed provider's current chain) with the target chainId regardless of namespace. Previously, a guard threw an error when multiple chain namespaces were configured, so this comparison was always within the same namespace. Now that guard is removed to enable multi-namespace switching, but the comparison remains namespace-unaware. If an EVM chain and a Solana chain share the same hex chainId (e.g., both mainnet-beta chains using 0x1), the switch is silently skipped because currentChainId === chainId evaluates to true even though the chains belong to different namespaces.
There was a problem hiding this comment.
chain ids are unique across namespaces, so this won't be a problem


Motivation and Context
Jira Link: EMBED-89
Description
How has this been tested?
Screenshots (if appropriate):
Types of changes
Checklist:
Note
High Risk
High risk because it refactors core chain selection, persisted state, auto-connect/cached connector behavior, and
switchChainsemantics across connectors and both React/Vue hook layers, which can affect connection/rehydration flows for EVM and Solana.Overview
Adds multi-namespace “current chain” tracking by replacing the single
currentChainId/chainNamespaceconcept withcurrentChainIds(namespace → chainId) across the No-Modal and Modal SDKs, plus a newgetCurrentChain(namespace)API.Makes chain switching namespace-aware:
switchChainnow requires{ chainId, namespace }, updates per-namespace chain state, and updates React/Vue hooks (useChain,useSwitchChain,useWeb3Auth) and wagmi providers to derive the default EVM chain viagetCurrentChain(CHAIN_NAMESPACES.EIP155).Fixes connector caching/initialization collisions across namespaces by persisting
cachedConnectorNamespace/connectedConnectorNamespace, matching cached connectors by both name+namespace, and adjusting connector init/auto-connect logic; Solana wallet hooks now exposesolanaChainand support switching Solana clusters, with the Vue demo adding UI to display/switch the active Solana chain.Also loosens
@solana/kitpeer dependency to>=6.5.0and tweaks demo copy (Get Connected Chain).Written by Cursor Bugbot for commit 734a68a. This will update automatically on new commits. Configure here.