Skip to content

fix(connect): bound WalletConnect switch on connect - #605

Merged
matt416 merged 1 commit into
masterfrom
walletconnect-hang
Jun 26, 2026
Merged

fix(connect): bound WalletConnect switch on connect#605
matt416 merged 1 commit into
masterfrom
walletconnect-hang

Conversation

@matt416

@matt416 matt416 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Objective

Fix WalletConnect connect flows that can hang when the connector tries to switch to the configured default chain during connect and the wallet never settles switchChain.

What Changed

  • WalletConnect now establishes the base session on the wallet's current chain before attempting a best-effort switch to the requested/default chain.
  • chainId is stripped before calling wagmi's base WalletConnect connect, so wagmi cannot perform its own unbounded internal switchChain before this wrapper's timeout applies.
  • Automatic switch-on-connect is bounded to 1500ms; if it rejects or times out, connect resolves with the original wallet chain.
  • Default walletConnect config now accepts customStoragePrefix and passes it through to wagmi WalletConnect, so apps can opt into isolated WalletConnect storage when they run another WalletConnect core.
  • The default storage namespace is unchanged unless customStoragePrefix is explicitly provided, so existing WalletConnect sessions are not migrated by default.

Why

Some WalletConnect wallets, notably Safe/smart-contract wallet flows, cannot satisfy app-initiated chain switching and may leave the switch promise pending. Because the switch was part of connect, the app stayed on “Connecting…” indefinitely.

This upstreams the package-level behavior needed by the downstream wallet-kit workaround in 0xPolygon/apps-team-packages#66 and the Portal bug in 0xPolygon/portal#1213.

Links

Verification

  • pnpm install --frozen-lockfile
  • pnpm --filter @0xsequence/hooks build
  • pnpm -C packages/connect build
  • pnpm -C packages/connect typecheck
  • pnpm -C packages/connect test
  • pnpm exec eslint -c eslint.config.mjs packages/connect/src/connectors/walletConnect/walletConnect.ts packages/connect/src/config/defaultConnectors.ts
  • pnpm exec prettier --check packages/connect/src/connectors/walletConnect/walletConnect.ts packages/connect/src/config/defaultConnectors.ts .changeset/walletconnect-connect-timeout.md

Reviewer Focus

  • WalletConnect connect flow: confirm connect no longer depends on a successful switch to the app default chain.
  • Chain behavior compatibility: confirm wallets that switch quickly still return the target chain, while wallets that cannot switch still connect on their current chain.
  • Storage prefix passthrough: confirm default storage behavior remains unchanged unless apps explicitly pass walletConnect.customStoragePrefix.

Manual QA Suggested

  • Safe over WalletConnect on a non-default chain should connect without hanging.
  • Normal WalletConnect wallet on a switchable non-default chain should still switch if it settles within the timeout.
  • App-specific transaction/send flows should still handle wrong-network state after connect if the wallet stays on its current chain.

@matt416
matt416 requested a review from a team as a code owner June 26, 2026 13:49
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 26, 2026

Copy link
Copy Markdown

Deploying web-sdk-react-example with  Cloudflare Pages  Cloudflare Pages

Latest commit: 61ae42d
Status: ✅  Deploy successful!
Preview URL: https://32ad8e55.web-sdk-react-example.pages.dev
Branch Preview URL: https://walletconnect-hang.web-sdk-react-example.pages.dev

View logs

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dca52ff698

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/connect/src/connectors/walletConnect/walletConnect.ts Outdated
@matt416
matt416 merged commit 2112c21 into master Jun 26, 2026
5 checks passed
@matt416
matt416 deleted the walletconnect-hang branch June 26, 2026 14:15
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.

2 participants