Skip to content

fix(webapp): seed selectedChainIds from validChainIds when empty#2786

Open
thedavidmeister wants to merge 1 commit into
mainfrom
2026-06-22-issue-2747-orders-without-wallet
Open

fix(webapp): seed selectedChainIds from validChainIds when empty#2786
thedavidmeister wants to merge 1 commit into
mainfrom
2026-06-22-issue-2747-orders-without-wallet

Conversation

@thedavidmeister

@thedavidmeister thedavidmeister commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

What

Orders page showed nothing for fresh/wallet-disconnected users because selectedChainIds started as [] and no code ever seeded it.

validChainIds.subscribe only filtered stale entries — it never auto-selected chains for users with an empty selection. Connecting a wallet didn't directly fix this either (the wallet sets chainId, not selectedChainIds). In practice, users only saw orders if they had a prior chain selection persisted in localStorage, which is why the issue correlates with wallet connection: the wallet flow incidentally triggers a chain-selection UI.

Fix

One-line guard in validChainIds.subscribe: when validChainIds first becomes non-empty and selectedChainIds is empty, seed selectedChainIds with all valid chain IDs. Returning users (non-empty selectedChainIds in localStorage) keep their stored selection unchanged.

 validChainIds.subscribe((valid) => {
   if (valid.length > 0) {
     selectedChainIds.update((current) => {
+      if (current.length === 0) return [...valid];
       const filtered = current.filter((id) => valid.includes(id));
       return filtered.length !== current.length ? filtered : current;
     });
   }
 });

Tests

Two new unit tests in settings.test.ts:

  • seeds selectedChainIds with all validChainIds when selectedChainIds is empty — fresh-user path
  • does not re-seed selectedChainIds when validChainIds updates and selectedChainIds is already set — returning-user path (no clobber)

All seven existing pruning/persistence tests continue to pass.

Closes #2747

Co-Authored-By: Claude noreply@anthropic.com

Summary by CodeRabbit

  • Bug Fixes
    • Improved chain selection initialization to automatically populate available chains when no explicit selection exists, while preserving user-selected chains during subsequent updates.

Fresh users and users who cleared localStorage had selectedChainIds=[]
after app init. validChainIds.subscribe only filtered stale IDs but never
seeded an empty selection, so no orders were visible without a wallet.

When validChainIds first populates and selectedChainIds is empty, set it
to all valid chain IDs so orders are browsable wallet-disconnected.
Returning users keep their stored selection unchanged.

Closes #2747

Co-Authored-By: Claude <noreply@anthropic.com>
@thedavidmeister thedavidmeister self-assigned this Jun 22, 2026
@coderabbitai

coderabbitai Bot commented Jun 22, 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d8914df5-cd7d-4adb-931f-1c0d1d0abb5c

📥 Commits

Reviewing files that changed from the base of the PR and between 32266db and e84292b.

📒 Files selected for processing (2)
  • packages/webapp/src/lib/stores/settings.test.ts
  • packages/webapp/src/lib/stores/settings.ts

📝 Walkthrough

Walkthrough

A one-line early-return is added to the validChainIds subscriber in settings.ts so that when selectedChainIds is empty, it is populated with all valid chain IDs instead of remaining empty. Two tests are added to cover the auto-seed path and the no-clobber path.

Changes

Chain ID auto-seeding logic and tests

Layer / File(s) Summary
selectedChainIds auto-seed on empty + tests
packages/webapp/src/lib/stores/settings.ts, packages/webapp/src/lib/stores/settings.test.ts
Inside validChainIds.subscribe, an early return replaces an empty selectedChainIds with the full valid array. Two new tests verify that an empty selection is seeded on validChainIds update and that an existing non-empty selection is not overwritten.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐇 Hoppity-hop, the chains all appear,
When the list was empty, nothing was clear!
Now valid IDs fill the store with a leap,
No orders lost, no wallet to keep.
The bunny rejoices — browse freely, my dear! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: seeding selectedChainIds from validChainIds when empty, which directly addresses the root cause of the linked issue.
Linked Issues check ✅ Passed The PR directly implements the solution for issue #2747 by seeding selectedChainIds with valid chain IDs when empty, enabling wallet-disconnected order browsing without affecting returning users.
Out of Scope Changes check ✅ Passed All changes are in-scope, focused solely on the selectedChainIds initialization logic and its test coverage. No unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 2026-06-22-issue-2747-orders-without-wallet

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


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.

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.

Can't view any orders on the dex without connecting a wallet

1 participant