Skip to content

fix: handle injected provider connection issues - #7800

Merged
limitofzero merged 7 commits into
developfrom
fix/injected-provider-and-safe-connection
Jul 3, 2026
Merged

limitofzero merged 7 commits into
developfrom
fix/injected-provider-and-safe-connection

Conversation

@limitofzero

@limitofzero limitofzero commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #7765 (partial — see deferred section).

Fixes three regressions after #7757 landed enableReconnect: hasRecentConnector on the AppKit config in libs/wallet:

  1. Safe iframe — Reown refused to auto-connect via Safe SDK when no cached connector was present, leaving users on the "Connect Wallet" screen while the wallet was actually available.
  2. Widget iframe browser-wallet leak — enableEIP6963: true in widget mode let Reown discover window.ethereum directly, bypassing the WidgetEthereumProvider iframe transport. A browser wallet connected in a standalone widget page bled into embedded contexts (e.g. widget-inside-Safe showed MetaMask instead of Safe).
  3. Widget iframe reconnect handshake — without reconnect enabled in widget mode, the cow-widget connector never handshaked with the parent dApp on reload.

Not fixed here (deferred to a separate PR)

Widget Configurator dApp-mode connect button stays on "Connect Wallet" after a successful connect, refresh fixes it. This regression was introduced by #7604 (Widget Configurator Revamp), lives entirely in apps/widget-configurator/, and needs local browser debugging (subscription timing on <appkit-button /> vs ConnectorController.state). Out of scope for this wallet-config change — will be addressed in a dedicated PR against the configurator.

To Test

  • Need to test connection inside mobile app - it should be connected by injected wallet. (ps for me MM is always stuck after few seconds, so I tested it with Rabby)
  • Need to test safe connection (inside iframe), it should be separate from dApp wallet connection.
  • Regress for dApp - nothing should be broken
  • standalone mode should works as expected

@vercel

vercel Bot commented Jul 2, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
cowfi Ready Ready Preview Jul 3, 2026 4:01pm
explorer-dev Ready Ready Preview Jul 3, 2026 4:01pm
storybook Ready Ready Preview Jul 3, 2026 4:01pm
swap-dev Ready Ready Preview Jul 3, 2026 4:01pm
widget-configurator Ready Ready Preview Jul 3, 2026 4:01pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
cosmos Ignored Ignored Jul 3, 2026 4:01pm
sdk-tools Ignored Ignored Preview Jul 3, 2026 4:01pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The wallet wagmi config now detects widget mode, disables EIP-6963 there, and broadens reconnect eligibility to include Safe, mobile, and widget contexts.

Changes

Widget-aware reconnect gating

Layer / File(s) Summary
Widget detection and AppKit flags
libs/wallet/src/wagmi/config.ts
Imports isInjectedWidget, derives isWidget, sets enableEIP6963 to !isWidget, and expands enableReconnect to include Safe, mobile, and widget contexts.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • cowprotocol/cowswap#7581: Also adjusts wallet connection behavior using widget-mode detection and related connector gating.
  • cowprotocol/cowswap#7766: Changes the same wallet config area and overlaps with reconnect and widget/injected gating logic.

Suggested reviewers: fairlighteth, kernelwhisperer, elena-zh

Poem

I’m a rabbit in the config thicket,
Hopping where the widget sits.
EIP-6963 takes a rest,
Reconnect now knows all the rest.
Soft paws, neat flags, one happy twitch. 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and matches the injected-provider connection fix in the config changes.
Linked Issues check ✅ Passed The config changes align with #7765 by using isInjectedWidget, disabling EIP6963 in widget mode, and broadening reconnect logic accordingly.
Out of Scope Changes check ✅ Passed The changes stay within wallet connection config and do not introduce unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The PR description includes the required Summary and To Test sections and provides useful context, with only the optional Background section omitted.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/injected-provider-and-safe-connection

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 2, 2026 •

Copy link
Copy Markdown

Deploying explorer-dev with  Cloudflare Pages  Cloudflare Pages

Latest commit: a45c93a
Status: ✅  Deploy successful!
Preview URL: https://dceb8c32.explorer-dev-dxz.pages.dev
Branch Preview URL: https://fix-injected-provider-and-sa.explorer-dev-dxz.pages.dev

View logs

@vercel
vercel Bot temporarily deployed to Preview – storybook July 2, 2026 12:48 Inactive
@vercel
vercel Bot temporarily deployed to Preview – widget-configurator July 2, 2026 12:48 Inactive
@vercel
vercel Bot temporarily deployed to Preview – explorer-dev July 2, 2026 12:48 Inactive
@vercel
vercel Bot temporarily deployed to Preview – cowfi July 2, 2026 12:49 Inactive
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 2, 2026 •

Copy link
Copy Markdown

Deploying swap-dev with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7adae9c
Status: ✅  Deploy successful!
Preview URL: https://d6d17505.swap-dev-5u6.pages.dev
Branch Preview URL: https://fix-injected-provider-and-sa.swap-dev-5u6.pages.dev

View logs

@vercel
vercel Bot temporarily deployed to Preview – swap-dev July 2, 2026 12:51 Inactive

@fairlighteth fairlighteth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ AI Review (Codex GPT-5, worked 5m): partial reconnect cherry-pick can re-open wallet regressions

Finding: [BLOCKING] Keep reconnect scoped until the Safe/widget isolation pieces are included

  • Location: libs/wallet/src/wagmi/config.ts:90 and libs/wallet/src/wagmi/config.ts:120
  • This one is important: this turns AppKit reconnect on for every Safe/mobile load and starts the injected mobile connector even without recentConnectorId.
  • Receipt: PR #7757 deliberately narrowed mobile reconnect to recent connectors, and the #7785 review found a similar broad reconnect change broke MetaMask in-app browser and Safe/widget isolation. The follow-up comment also calls out blanket reconnect as the wrong lever.
  • The full #7790 branch this PR cites adds the missing context-isolation pieces (enableEIP6963: !isWidget and Safe/AppKit @appkit/* storage namespacing) and keeps the direct mobile injected connect behind hasRecentConnector. This PR cherry-picks only the reconnect part, so the known bleed/reconnect failure mode is still in play.

QA evidence needed

  • Please add ER-vs-AR for MetaMask mobile first visit, reload, disconnect/reconnect, and Safe/widget isolation where a standalone widget has a browser wallet connected but the widget inside Safe must show the Safe account.

Suggested fix

  • Either include the rest of the #7790 isolation changes and keep the direct mobile connectWalletById('injected') path guarded by hasRecentConnector, or keep enableReconnect scoped until the Safe/mobile flows above are proven on a preview.
Review scope and related context
  • No existing PR #7800 review thread covers this; CodeRabbit only flagged missing PR-body test detail.
  • This is separate from a generic QA request because the same reconnect lever already has a recent regression receipt in #7785.
  • I checked the live PR diff, the linked issue #7765, and the full #7790 source branch before drafting this.
🤖 Prompt for AI agents
Verify this finding against current PR #7800 before editing.

Context:
- Current PR changes libs/wallet/src/wagmi/config.ts only.
- It sets enableReconnect to isSafeApp || isMobile || hasRecentConnector.
- It removes hasRecentConnector from the direct mobile injected connect.
- Prior PR #7785 reported similar broad reconnect behavior broke MetaMask mobile and Safe/widget isolation.
- Full PR #7790 includes additional isolation changes and does not remove the direct mobile recent-connector guard.

Expected fix:
- Keep the change minimal.
- Either pull in the missing Safe/widget isolation pieces from #7790 and keep mobile direct connect guarded, or narrow reconnect back to the proven path.
- Add/record targeted ER-vs-AR for MetaMask mobile and Safe/widget isolation.

Generated using the pr-review skill from the CoW Protocol skills repo.

@vercel
vercel Bot temporarily deployed to Preview – storybook July 2, 2026 13:10 Inactive
@vercel
vercel Bot temporarily deployed to Preview – widget-configurator July 2, 2026 13:10 Inactive
@vercel
vercel Bot temporarily deployed to Preview – cowfi July 2, 2026 13:10 Inactive
@vercel
vercel Bot temporarily deployed to Preview – explorer-dev July 2, 2026 13:14 Inactive
@vercel
vercel Bot temporarily deployed to Preview – swap-dev July 2, 2026 13:15 Inactive
@limitofzero limitofzero changed the title fix: handle isMobile fix: handle injected provider connection issues Jul 2, 2026
@vercel
vercel Bot temporarily deployed to Preview – storybook July 2, 2026 18:27 Inactive
@vercel
vercel Bot temporarily deployed to Preview – widget-configurator July 2, 2026 18:28 Inactive
@vercel
vercel Bot temporarily deployed to Preview – explorer-dev July 2, 2026 18:28 Inactive
@vercel
vercel Bot temporarily deployed to Preview – cowfi July 2, 2026 18:28 Inactive
@vercel
vercel Bot temporarily deployed to Preview – swap-dev July 2, 2026 18:30 Inactive
@limitofzero
limitofzero requested a review from a team July 2, 2026 18:59
@limitofzero

Copy link
Copy Markdown
Contributor Author

@fairlighteth thank you, addressed your remarks

@vercel
vercel Bot temporarily deployed to Preview – storybook July 2, 2026 19:00 Inactive
@vercel
vercel Bot temporarily deployed to Preview – widget-configurator July 2, 2026 19:01 Inactive
@vercel
vercel Bot temporarily deployed to Preview – cowfi July 2, 2026 19:01 Inactive
@vercel
vercel Bot temporarily deployed to Preview – explorer-dev July 2, 2026 19:02 Inactive
@vercel
vercel Bot temporarily deployed to Preview – swap-dev July 2, 2026 19:02 Inactive

@fairlighteth fairlighteth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ AI Review (Codex GPT-5, worked 4m): code follow-up addressed, QA still needed

Rechecked

  • Author response: @limitofzero said the prior remarks were addressed.
  • Code path: libs/wallet/src/wagmi/config.ts:93 now disables EIP-6963 in widget mode, and libs/wallet/src/wagmi/config.ts:125 restores the hasRecentConnector guard around direct mobile injected connect.
  • Related context: this now matches the wallet-config part of #7790; wagmiStorage already has separate swap/widget/Safe keys.

Result: Code-side blocker is fixed. The earlier partial-cherry-pick concern no longer applies to libs/wallet/src/wagmi/config.ts.

Follow-up: [QUESTION] Add the missing wallet/Safe/widget ER-vs-AR before approval

  • The manual QA part from the previous review is still not covered in the PR body: the checklist is still unchecked, and the mobile note says MetaMask was not actually covered.
  • Please add observed ER-vs-AR for MetaMask mobile first visit/reload/disconnect-reconnect, Safe iframe auto-connect, widget standalone-vs-embedded isolation, and regular desktop regression.
  • Automated checks do not replace that matrix here; lint/typecheck/unit tests pass, while Cypress is currently failing on quote/swap e2e paths and does not exercise these wallet contexts.
Review scope and related context
  • I am not reopening the previous code blocker: the current diff includes the two missing pieces called out there.
  • The #7790 AppKit @appkit/* storage patch was in apps/widget-configurator; this PR now explicitly defers the configurator dApp-mode issue, so I did not treat that as a blocker for this wallet-config follow-up.
🤖 Prompt for AI agents
Verify PR #7800 against the previous review only.

Prior issue:
- The PR broadened reconnect while missing widget EIP-6963 isolation.
- It had also removed the hasRecentConnector guard from direct mobile injected connect.

Current code to check:
- libs/wallet/src/wagmi/config.ts: enableEIP6963 must be !isWidget.
- direct mobile connectWalletById('injected') must remain guarded by hasRecentConnector.

Do not reopen the code blocker if those remain true. Ask separately for manual ER-vs-AR covering MetaMask mobile, Safe iframe, widget isolation, and desktop regression.

Generated using the pr-review skill from the CoW Protocol skills repo.

@elena-zh elena-zh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes look good to me besides the not fixed issue with configurator, as you mentioned. But it is OK to address it in another PR

Image

@limitofzero
limitofzero enabled auto-merge (squash) July 3, 2026 15:56
@vercel
vercel Bot temporarily deployed to Preview – storybook July 3, 2026 15:57 Inactive
@vercel
vercel Bot temporarily deployed to Preview – widget-configurator July 3, 2026 15:57 Inactive
@vercel
vercel Bot temporarily deployed to Preview – cowfi July 3, 2026 15:58 Inactive
@vercel
vercel Bot temporarily deployed to Preview – explorer-dev July 3, 2026 15:58 Inactive
@vercel
vercel Bot temporarily deployed to Preview – swap-dev July 3, 2026 16:01 Inactive
@limitofzero
limitofzero merged commit 618ffc1 into develop Jul 3, 2026
19 of 20 checks passed
@limitofzero
limitofzero deleted the fix/injected-provider-and-safe-connection branch July 3, 2026 16:03
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 3, 2026

This branch was previously deployed

5 inactive deployments
Preview – swap-dev — a45c93ac Deployed Jul 3, 2026 by vercel[bot]
Preview – explorer-dev — a45c93ac Deployed Jul 3, 2026 by vercel[bot]
Preview – cowfi — a45c93ac Deployed Jul 3, 2026 by vercel[bot]
Preview – widget-configurator — a45c93ac Deployed Jul 3, 2026 by vercel[bot]
Preview – storybook — a45c93ac Deployed Jul 3, 2026 by vercel[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Widget/standalone and app's connections are not separated

4 participants