Skip to content

EMBED-89: support multi-namespace for current chains#2419

Open
tanguyenvn wants to merge 11 commits intomasterfrom
feat/EMBED-89-current-chain
Open

EMBED-89: support multi-namespace for current chains#2419
tanguyenvn wants to merge 11 commits intomasterfrom
feat/EMBED-89-current-chain

Conversation

@tanguyenvn
Copy link
Copy Markdown
Contributor

@tanguyenvn tanguyenvn commented Mar 26, 2026

Motivation and Context

Jira Link: EMBED-89

Description

  • allow multi-chain wallet (e.g. Embedded Wallet, WC) to expose Ethereum provider and Solana wallet at the same time -> this requires WS to be able to handle both EVM and Solana RPC requests
  • we maintain currentChainIds which is map of chain namespace and chain id for that namespace
  • switch chain requires namespace beside chain id

How has this been tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project. (run lint)
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My code requires a db migration.

Note

High Risk
High risk because it refactors core chain selection, persisted state, auto-connect/cached connector behavior, and switchChain semantics 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/chainNamespace concept with currentChainIds (namespace → chainId) across the No-Modal and Modal SDKs, plus a new getCurrentChain(namespace) API.

Makes chain switching namespace-aware: switchChain now 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 via getCurrentChain(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 expose solanaChain and support switching Solana clusters, with the Vue demo adding UI to display/switch the active Solana chain.

Also loosens @solana/kit peer dependency to >=6.5.0 and tweaks demo copy (Get Connected Chain).

Written by Cursor Bugbot for commit 734a68a. This will update automatically on new commits. Configure here.

- 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)
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
web3auth-web Ready Ready Preview, Comment Mar 27, 2026 8:00am

Request Review

@tanguyenvn tanguyenvn force-pushed the feat/EMBED-89-current-chain branch from a44818b to b255b0e Compare March 26, 2026 04:07
Base automatically changed from feat/EMBED-89-wallet-connection to master March 26, 2026 07:55
@tanguyenvn tanguyenvn marked this pull request as ready for review March 27, 2026 08:05
@tanguyenvn tanguyenvn requested a review from a team as a code owner March 27, 2026 08:05
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chain ids are unique across namespaces, so this won't be a problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant