Skip to content

fix: switch chainnamespace/network#2472

Open
lwin-kyaw wants to merge 10 commits into
masterfrom
fix/switch-chain
Open

fix: switch chainnamespace/network#2472
lwin-kyaw wants to merge 10 commits into
masterfrom
fix/switch-chain

Conversation

@lwin-kyaw
Copy link
Copy Markdown
Contributor

@lwin-kyaw lwin-kyaw commented May 7, 2026

Jira Link

Description

  • Fix the Vue Solana provider so it only initializes a Solana client when the active embedded-wallet chain is Solana.
  • Sync the vue-app-new demo with Web3Auth’s multichain chain state for both "Get Connected Chain ID" and the demo switch-chain action.
  • Add safer cleanup/loading behavior around Vue chain transitions.

Problem

  • The Vue Solana provider eagerly tried to connect a Solana client whenever a Solana wallet was present, even if the embedded provider was still on an EVM chain.
  • The vue-app-new demo relied on wagmi’s EVM chain state for chain display/switching, which could drift from Web3Auth after chain changes triggered from the wallet-services UI.

Changes

  • Guard Solana client initialization behind the active Web3Auth chain namespace in the Vue Solana provider.
  • Re-run the Vue Solana provider setup on chain changes and dispose stale clients safely.
  • Update the demo to use Web3Auth useChain() for connected-chain display.
  • Update the demo to use Web3Auth useSwitchChain() for the embedded wallet switch flow.
  • Add loading state to the demo switch-chain button.

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.

Note

Medium Risk
Touches core AUTH connector chain switching and adds new provider/account readiness state that gates React/Vue wagmi/solana bindings, so regressions could affect connection lifecycle and chain/account availability across namespaces.

Overview
Fixes multichain switching by teaching the AUTH connector to sync embedded provider state (accounts/chain/unlocked) via GET_PROVIDER_STATE, expose isProviderStateSyncing/isAccountReady, and react to chainChanged/accountsChanged with proper cleanup/disconnect.

Updates React/Vue hook contexts and wagmi/Solana providers to gate binding until accounts are ready, avoid stale bindings during namespace changes, and dispose/recreate Solana clients only when the active chain is Solana (with race-safe reconnect handling).

Updates the vue-app-new dashboard to switch chain namespaces via web3Auth.switchChain (with loading state) and only show EVM/Solana service panels based on chainNamespace. Also bumps @web3auth/ws-embed and related deps/lockfiles.

Reviewed by Cursor Bugbot for commit fb385d4. Bugbot is set up for automated code reviews on this repo. Configure here.

@lwin-kyaw lwin-kyaw requested review from a team as code owners May 7, 2026 13:06
@vercel
Copy link
Copy Markdown

vercel Bot commented May 7, 2026

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

Project Deployment Actions Updated (UTC)
web3auth-web Ready Ready Preview, Comment May 21, 2026 2:22pm

Request Review

Comment thread demo/vue-app-new/src/components/AppDashboard.vue Outdated
arch1995
arch1995 previously approved these changes May 7, 2026
Comment thread demo/vue-app-new/src/components/AppDashboard.vue Outdated
Comment thread demo/vue-app-new/src/components/AppDashboard.vue Outdated
Comment thread packages/no-modal/src/connectors/auth-connector/authConnector.ts
Comment thread demo/vue-app-new/src/components/AppDashboard.vue Outdated
Comment thread packages/no-modal/src/react/wagmi/provider.ts
Comment thread packages/no-modal/src/vue/solana/provider.ts
Comment thread packages/no-modal/src/react/wagmi/provider.ts
Comment thread packages/no-modal/src/noModal.ts
}

get isAccountReady(): boolean {
if (this.status !== CONNECTOR_STATUS.CONNECTED && this.status !== CONNECTOR_STATUS.AUTHORIZED) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

use !connected_statuses.includes

log.debug("initializing auth connector");
await authInstancePromise;

if (this.wsEmbedInstancePromise) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this will slow down the app by a lot.
there's a reason we made this async

Comment thread packages/no-modal/src/connectors/auth-connector/authConnector.ts Outdated
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 2 potential issues.

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.

Reviewed by Cursor Bugbot for commit fb385d4. Configure here.


this.bindWsEmbedProviderEvents();
if (this.providerStateSyncPromise) {
return this.providerStateSyncPromise;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Race condition drops chain changes during sync

Medium Severity

The syncProviderState deduplication returns the existing in-flight promise when called while a sync is already running. If handleWsEmbedChainChanged fires during an active sync (e.g., rapid chain A→B→C), the second call is silently absorbed into the first promise. When that promise resolves (potentially with chain B's state), providerStateSyncPromise is cleared in finally, but no fresh sync is scheduled for the latest chain C state. The provider state can end up stale until another event triggers a new sync.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit fb385d4. Configure here.

if (this.wsEmbedInstance?.provider) {
return this.wsEmbedInstance.provider as IProvider;
if (this.getWsEmbedProvider()) {
return this.getWsEmbedProvider();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Provider getter calls getWsEmbedProvider() twice unnecessarily

Low Severity

The provider getter calls getWsEmbedProvider() twice — once for the truthiness check and once for the return value. While the method has no side effects today, this pattern is fragile: if the underlying wsEmbedInstance reference changes between the two calls (e.g., nulled by an event between evaluations), the getter could theoretically return null despite passing the initial check. Storing the result in a local variable avoids both the redundancy and the potential inconsistency.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit fb385d4. Configure here.

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.

3 participants