Skip to content

fix(wallet): reconnect in embedded contexts so widget/Safe don't show 'Connect Wallet' - #7785

Closed
tenderdeve wants to merge 1 commit into
cowprotocol:developfrom
tenderdeve:fix/7777-widget-safe-reconnect
Closed

tenderdeve wants to merge 1 commit into
cowprotocol:developfrom
tenderdeve:fix/7777-widget-safe-reconnect

Conversation

@tenderdeve

@tenderdeve tenderdeve commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #7777

@elena-zh confirmed this regressed in #7757, which changed enableReconnect: true → enableReconnect: hasRecentConnector.

Embedded contexts — a Safe App iframe, or the injected widget in dapp mode — (re)establish the connection through the host on every load and don't persist a recentConnectorId. So reconnect is now disabled for them: the account stays empty and the trade form renders a (disabled) "Connect Wallet" while the wallet is actually connected.

Fix: also enable reconnect when in a Safe App iframe or injected widget, keeping the hasRecentConnector gate for the standalone/mobile path #7757 was guarding.

Repro (from the issue): open a Safe App pointing at the widget — https://app.safe.global/apps/open?safe=<your_safe>&appUrl=https%3A%2F%2Fdev.widget.cow.fi.

@fairlighteth since this touches the enableReconnect gate you added in #7757 — this keeps your mobile-injected guard intact and only restores reconnect for the Safe-app / injected-widget contexts. Does that look right to you?

Summary by CodeRabbit

  • New Features
    • Improved automatic reconnect behavior for the wallet experience.
    • Reconnect now works in more cases, including Safe App and injected widget/dapp environments, not just previously used connections.

… "Connect Wallet"

cowprotocol#7757 changed `enableReconnect: true` to `enableReconnect: hasRecentConnector`.
Embedded contexts — a Safe App iframe, or the injected widget in dapp mode —
(re)establish the connection through the host on every load and don't persist a
`recentConnectorId`, so reconnect was disabled for them. The account stays empty
and the trade form renders a (disabled) "Connect Wallet" while the wallet is
actually connected.

Also enable reconnect when in a Safe App iframe or injected widget, keeping the
`hasRecentConnector` gate for the standalone/mobile path cowprotocol#7757 was guarding.
@vercel

vercel Bot commented Jul 1, 2026

Copy link
Copy Markdown

@tenderdeve is attempting to deploy a commit to the cow-dev Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 870f2a4b-b2b3-476c-86c6-8f9630ec19de

📥 Commits

Reviewing files that changed from the base of the PR and between d5abb10 and 6a50e2c.

📒 Files selected for processing (1)
  • libs/wallet/src/wagmi/config.ts

Walkthrough

In libs/wallet/src/wagmi/config.ts, a new shouldReconnect flag is introduced by importing isInjectedWidget and combining it with existing hasRecentConnector and isSafeApp conditions. The createAppKit enableReconnect option now uses shouldReconnect instead of only hasRecentConnector.

Changes

Reconnect condition update

Layer / File(s) Summary
Combine reconnect conditions and wire into AppKit config
libs/wallet/src/wagmi/config.ts
Imports isInjectedWidget, adds a shouldReconnect flag combining hasRecentConnector, isSafeApp, and isInjectedWidget, and updates enableReconnect to use it.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

Suggested reviewers: fairlighteth, limitofzero, kernelwhisperer, elena-zh

Poem

A hop, a skip, a wallet's plea,
Reconnect now for Safe and widget-ee!
One flag to bind them, small and neat,
No dropped connections 'neath rabbit feet. 🐰🔗

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: reconnecting embedded wallet contexts.
Description check ✅ Passed It explains the regression, fix, issue reference, and context well, though it doesn't use the template's exact section headings.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@elena-zh
elena-zh requested a review from limitofzero July 1, 2026 11:28
@elena-zh elena-zh added the trigger-preview Add to a fork PR to trigger CF-pages preview. See https://github.com/cowprotocol/cowswap/pull/7615 label Jul 1, 2026
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Cloudflare Pages preview mirror

Preview branch URL: https://github.com/cowprotocol/cowswap/tree/cf-preview/pr-7785
Mirror PR: #7786
Cloudflare Pages preview links will be posted on the mirror PR by the Cloudflare Pages GitHub integration once builds complete.

Source fork branch: tenderdeve/cowswap:fix/7777-widget-safe-reconnect
Approval target SHA: 6a50e2cd402b
Last mirrored SHA: 6a50e2cd402b
Last comment update: @elena-zh at 2026-07-01T11:29:26.856Z

  • Sync Cloudflare preview to approval target commit

@github-actions github-actions Bot removed the trigger-preview Add to a fork PR to trigger CF-pages preview. See https://github.com/cowprotocol/cowswap/pull/7615 label Jul 1, 2026
@vercel
vercel Bot temporarily deployed to Preview – storybook July 1, 2026 11:30 Inactive
@vercel
vercel Bot temporarily deployed to Preview – widget-configurator July 1, 2026 11:30 Inactive
@vercel
vercel Bot temporarily deployed to Preview – cowfi July 1, 2026 11:31 Inactive

@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.

Hey @tenderdeve , thank you for the attempt to address this issue.

However, it does not work as expected:

  1. It is impossible to connect the app inside MM integrated browser now (it was fixed in #7757
Image
  1. the widget connection inside Safe is not isolated: when I open just widget, and connect to a wallet there, the connection is reset inside Safe, and it shows MM connection instead of Safe one.
Image

@limitofzero limitofzero mentioned this pull request Jul 1, 2026
12 tasks
@tenderdeve

Copy link
Copy Markdown
Contributor Author

Thanks @elena-zh — you're right, and both regressions come from the same root cause in my approach. Forcing enableReconnect: hasRecentConnector || isSafeApp || isInjectedWidget() turns generic reconnect on for every embedded context, which:

  1. re-breaks the MM in-app browser flow fix(wallet): guard mobile injected provider #7757 deliberately guarded (reconnect kicking in before the injected connector is ready), and
  2. defeats the per-context isolation — the connection should be driven by each context's own connector (WidgetStandaloneModeUpdater → cow-widget, and connectWalletById(SAFE_CONNECTOR_ID) for Safe), not by a blanket reconnect that ignores which connector the context actually owns.

So blanket-broadening enableReconnect is the wrong lever. The storage keys are already namespaced per context (cowswap-wallet-cow-widget, ..._safe-app), so the real fix should keep enableReconnect: hasRecentConnector untouched and instead make sure the embedded context's own connector reconnects/persists (via the updater / Safe connect path) rather than showing "Connect Wallet".

Before I re-push I want to get the intended behavior right rather than guess again, since I can't reproduce the MM-mobile / Safe-in-widget cases locally. Two questions:

  • For the widget inside Safe, should it always use only the Safe connector and ignore any persisted cow-widget connector?
  • Is the "Connect Wallet while actually connected" case you originally reported the Safe App, the injected widget (dapp mode), or both?

cc @fairlighteth since this borders on #7757.

@elena-zh

elena-zh commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Hey @tenderdeve , thank you. No need to work further on this PR since we're fixing the issue by ourselves in #7790

@elena-zh elena-zh closed this Jul 2, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 2, 2026

This branch was previously deployed

3 inactive deployments
Preview – cowfi — 6a50e2cd Deployed Jul 1, 2026 by vercel[bot]
Preview – widget-configurator — 6a50e2cd Deployed Jul 1, 2026 by vercel[bot]
Preview – storybook — 6a50e2cd Deployed Jul 1, 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, dapp+Safe: app says 'connect wallet' when it is connected

3 participants