Skip to content

fix(account): handle disconnection of injected wallets after a refresh - #7894

Merged
elena-zh merged 14 commits into
developfrom
fix/reconnect-wallet-after-refresh-account-page
Sep 3, 2026
Merged

elena-zh merged 14 commits into
developfrom
fix/reconnect-wallet-after-refresh-account-page

Conversation

@limitofzero

@limitofzero limitofzero commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes the wallet connection being dropped when refreshing the account page (/account), and the follow-on "can't reconnect the same wallet". Two independent root causes are addressed — one for EVM wallets, one for Solana. Full context is here

The account page is affected specifically because it has no chain in the URL, which is the condition both bugs depend on.

To Test

EVM wallet (MetaMask / Rabby)

  1. Connect an injected EVM wallet, go to /account.
  • Refresh the page → wallet stays connected (previously it disconnected).
  • If it was disconnected, reconnecting the same wallet works (previously it errored, only a different wallet connected).
  • Refresh on a chain-pathed route (e.g. /137/swap) → still connected (no regression).

Solana wallet

  1. Enable Solana with ?IS_SOLANA_ENABLED=true in the URL, refresh, then connect a Solana wallet and go to /account.
  • Refresh the page → Solana wallet stays connected (previously it showed as disconnected).
  • EVM wallet on /account still connects/restores fine with Solana enabled (no cross-namespace regression).

Summary by CodeRabbit

  • Bug Fixes
    • Improved wallet reconnection by reading the recent-connector signal from wagmi storage, while preserving the Solana fallback behavior.
    • Improved initial network selection by seeding the initial chainId from restored connection state.
    • Refined network selection so a URL chain id is only used when present, with sensible defaults when it’s missing.
    • Added an SSR-safe localStorage getter to prevent runtime errors when localStorage is unavailable.
    • Updated ENS mainnet token list resolution to use a read-only wallet configuration (no persistence, no multi-injected discovery).
  • Chores
    • Updated bundle size metrics for affected packages.

@vercel

vercel Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
cowfi Ready Ready Preview Sep 3, 2026 11:38am UTC
explorer-dev Ready Ready Preview Sep 3, 2026 11:38am UTC
storybook Ready Ready Preview Sep 3, 2026 11:38am UTC
swap-dev Ready Ready Preview Sep 3, 2026 11:38am UTC
widget-configurator Ready Ready Preview Sep 3, 2026 11:38am UTC
2 Skipped Deployments
Project Deployment Actions Updated
cosmos Ignored Ignored Sep 3, 2026 11:38am UTC
sdk-tools Ignored Ignored Preview Sep 3, 2026 11:38am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Reown wallet initialization now reads wagmi’s recent connector state for reconnection, uses URL or persisted AppKit state to select the default network, and seeds account state from the restored AppKit network when no URL chain ID is present. ENS wagmi configuration and bundle-size records are also updated.

Changes

Reown wallet state

Layer / File(s) Summary
Storage-safe connector detection
libs/common-utils/src/localStorage.ts, libs/wallet/src/wagmi/config.ts
Adds an SSR-safe local-storage reader and uses wagmi’s persisted recent connector ID for reconnect detection while retaining the Solana connector check.
Default network selection
libs/wallet/src/wagmi/getReownDefaultNetwork.ts
URL chain IDs determine Solana or EVM networks; without one, persisted connector and active-namespace state determine whether Solana or EVM mainnet is selected.
Initial account network state
libs/wallet/src/wagmi/hooks/useAccountState.ts
Initial chain state now prefers the URL, then the restored AppKit CAIP network, and finally supported EVM mainnet.

Token configuration and metrics

Layer / File(s) Summary
Read-only ENS configuration
libs/tokens/src/services/fetchTokenList.ts
Disables multi-injected provider discovery and persistence for the ENS mainnet wagmi configuration.
Application bundle size records
bundle-size.jsonc
Updates uncompressed byte counts for the CowSwap and SDK tools application entries.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant WalletApp
  participant URL
  participant Storage
  participant getReownDefaultNetwork
  participant AppKit
  participant useAccountState
  WalletApp->>URL: read raw chain id
  getReownDefaultNetwork->>Storage: read persisted connector and namespace state
  Storage-->>getReownDefaultNetwork: return wallet state
  getReownDefaultNetwork->>AppKit: resolve selected network
  WalletApp->>AppKit: read restored CAIP network
  AppKit-->>useAccountState: provide restored network
  URL-->>useAccountState: provide URL chain id when present
  useAccountState->>useAccountState: map to supported chain id or mainnet
Loading

Possibly related PRs

Suggested labels: solana

Suggested reviewers: alfetopito, shoom3301, elena-zh

Poem

I hopped through chains beneath the sun,
Wagmi remembered everyone.
Solana stayed within the flow,
AppKit helped the network show.
A bunny cheers: reconnect—go!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: fixing wallet reconnect/disconnection after refresh.
Description check ✅ Passed The description includes a clear summary and test steps; the optional background section is the only missing template part.
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
  • Commit unit tests in branch fix/reconnect-wallet-after-refresh-account-page

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.

@limitofzero limitofzero added Account New account page related stuff Bug Something isn't working labels Jul 23, 2026
@limitofzero
limitofzero marked this pull request as ready for review July 23, 2026 19:59
@limitofzero limitofzero self-assigned this Jul 23, 2026
@limitofzero
limitofzero requested review from a team, alfetopito and shoom3301 July 23, 2026 20:00
@limitofzero limitofzero changed the title fix(account): check wagmi storage key to set hasRecentConnector flag fix(account): handle disconnection of injected wallets after a refresh Jul 23, 2026

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

🧹 Nitpick comments (1)
libs/wallet/src/wagmi/getReownDefaultNetwork.ts (1)

13-36: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add regression coverage for persisted namespace fallback.

Cover /account with Solana as the active namespace, explicit EVM/Solana URLs overriding persisted state, Solana disabled, and unavailable storage. These cases directly cover the PR’s refresh-time wallet restoration contract.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@libs/wallet/src/wagmi/getReownDefaultNetwork.ts` around lines 13 - 36, Add
regression tests for getReownDefaultNetwork covering /account with a persisted
Solana namespace, explicit EVM and Solana URL chain IDs taking precedence,
Solana-disabled behavior, and unavailable localStorage. Mock the relevant URL,
feature-flag, namespace, and chain helpers so the tests verify the refresh-time
fallback contract without relying on browser storage.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@libs/wallet/src/wagmi/getReownDefaultNetwork.ts`:
- Around line 13-36: Add regression tests for getReownDefaultNetwork covering
/account with a persisted Solana namespace, explicit EVM and Solana URL chain
IDs taking precedence, Solana-disabled behavior, and unavailable localStorage.
Mock the relevant URL, feature-flag, namespace, and chain helpers so the tests
verify the refresh-time fallback contract without relying on browser storage.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 56ecb6bc-4ecc-483d-9ba0-c5d30b89ce4f

📥 Commits

Reviewing files that changed from the base of the PR and between 67a775b and 2bf2415.

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

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

Thanks! Works as expected

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

@limitofzero sorry, it actually doesn't work

vdfvdfvdf.mov

@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 @limitofzero , the app still disconnets a wallet after refreshing

Image

@limitofzero

Copy link
Copy Markdown
Contributor Author

Hey @limitofzero , the app still disconnets a wallet after refreshing

Image

Hey @elena-zh, addressed it. Should works now

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@libs/common-utils/src/localStorage.ts`:
- Around line 5-8: Update getLocalStorageItem to wrap the
localStorage.getItem(key) access in exception handling, returning null when
storage access throws while preserving the existing undefined-global fallback
and successful string/null result.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f6cfb8c8-f741-4d81-8d4f-54c21dd57470

📥 Commits

Reviewing files that changed from the base of the PR and between 2bf2415 and 6472d35.

📒 Files selected for processing (4)
  • libs/common-utils/src/localStorage.ts
  • libs/wallet/src/wagmi/config.ts
  • libs/wallet/src/wagmi/getReownDefaultNetwork.ts
  • libs/wallet/src/wagmi/hooks/useAccountState.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • libs/wallet/src/wagmi/config.ts

Comment thread libs/common-utils/src/localStorage.ts Resolved

@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 @limitofzero , the issue is still reproducible :(

@elena-zh
elena-zh removed the request for review from alfetopito July 29, 2026 09:33
@shoom3301

Copy link
Copy Markdown
Contributor

@limitofzero I think the changes are valid, we should not loose them.
Anyway, the initial case - reload Accounts page doesn't work. Wallet still disconnects after reload.

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

Let's merged it and keep the bug open to fix it in the future

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

The issue looks like is fixed

@elena-zh
elena-zh merged commit 0374041 into develop Sep 3, 2026
17 of 18 checks passed
@elena-zh
elena-zh deleted the fix/reconnect-wallet-after-refresh-account-page branch September 3, 2026 12:07
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Account New account page related stuff Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants