Skip to content

fix: use chain-correct token lists in selector#37

Open
arunabha003 wants to merge 1 commit into
StabilityNexus:mainfrom
arunabha003:orb-tokenlist-chain-correct
Open

fix: use chain-correct token lists in selector#37
arunabha003 wants to merge 1 commit into
StabilityNexus:mainfrom
arunabha003:orb-tokenlist-chain-correct

Conversation

@arunabha003
Copy link
Copy Markdown

@arunabha003 arunabha003 commented Mar 28, 2026

Addressed Issues:

Fixes #32

Summary

  • remove incorrect token-list fallbacks across mismatched chains
  • only show curated tokens when the token list matches the active chain
  • fall back to manual token address entry on unsupported networks
  • improve selector messaging for unsupported or unavailable curated lists

Validation

  • npm run build

Screenshots/Recordings:

Now it shows no token found in Scroll sepolia, and It will show the tokens once the Scroll Sepolia tokens are added by the StabilityNexus/TokenList#4 .
Screenshot 2026-03-28 at 4 32 44 PM

Additional Notes:

AI Usage Disclosure:

We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact. AI slop is strongly discouraged and may lead to banning and blocking. Do not spam our repos with AI slop.

Check one of the checkboxes below:

  • This PR does not contain AI-generated code at all.
  • This PR contains AI-generated code. I have read the AI Usage Policy and this PR complies with this policy. I have tested the code locally and I am responsible for it.

I have used the following AI models and tools: TODO

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • My code follows the project's code style and conventions
  • If applicable, I have made corresponding changes or additions to the documentation
  • If applicable, I have made corresponding changes or additions to tests
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • I have read the Contribution Guidelines
  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.
  • I have filled this PR template completely and carefully, and I understand that my PR may be closed without review otherwise.

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling and user feedback when token lists fail to load or are unavailable.
  • New Features

    • Users can now manually enter token addresses when curated lists are not available.
    • Enhanced UI messaging clearly indicating available curated token lists by chain.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 28, 2026

📝 Walkthrough

Walkthrough

The changes refactor the token-list chain-name resolution to prevent displaying curated tokens from unsupported chains. A new getTokenListInfo function replaces getChainNameForTokenList, supporting only explicitly mapped chain-to-list pairings with no fallback behavior. Error and empty states now inform users when a curated list is unavailable for the active chain.

Changes

Cohort / File(s) Summary
Token Selector Component
components/TokenSelector.tsx
Integrated new getTokenListInfo() lookup API, added Wagmi useChains() for fallback chain naming, introduced fetchError state tracking, and implemented conditional empty-state messaging (search no-results, fetch error, missing list, or empty list). Modal UI now indicates whether curated tokens apply to the current chain or if none exist.
Chain Mapping Utilities
utils/chainMapping.ts
Replaced getChainNameForTokenList() with new getTokenListInfo() function backed by stricter TOKEN_LISTS_BY_CHAIN mapping. Removed fallback chain IDs (Sepolia, Mumbai, BSC testnet, Base Sepolia). Introduced TokenListInfo interface exposing both chainLabel and tokenListName fields.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 No more tokens from chains far and wide,
Just curated lists that truthfully reside,
When the list is missing, we gently confess,
The selector now shows what's truly the best! ✨

🚥 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 'fix: use chain-correct token lists in selector' is concise and directly reflects the main change: improving token list selection to use chain-correct mappings instead of incorrect fallbacks.
Linked Issues check ✅ Passed The PR successfully addresses all objectives from issue #32: removes wrong-chain token list fallbacks, displays only valid chain-specific tokens, prevents misleading cross-chain token display, and implements manual entry fallback with clear messaging.
Out of Scope Changes check ✅ Passed All changes are directly within scope of issue #32. The modifications to token list resolution and error messaging are necessary to prevent wrong-chain token display and improve user communication for unsupported networks.
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 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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
components/TokenSelector.tsx (1)

65-97: ⚠️ Potential issue | 🔴 Critical

Prevent stale fetches from restoring wrong-chain tokens.

Line 65-97 can race on chain switches: an older request may resolve after network change and overwrite tokens with a previous chain’s curated list. That reintroduces the wrong-chain selector bug.

Suggested fix (abort + stale response guard)
 useEffect(() => {
+  const controller = new AbortController();
+  let active = true;
+
   const fetchTokens = async () => {
     if (!tokenListInfo) {
       setTokens([]);
       setFetchError(null);
+      setLoading(false);
       return;
     }

     setLoading(true);
     setFetchError(null);
     try {
       const url = `https://raw.githubusercontent.com/StabilityNexus/TokenList/main/${tokenListInfo.tokenListName}-tokens.json`;
-      const response = await fetch(url);
+      const response = await fetch(url, { signal: controller.signal });
       if (!response.ok) {
         throw new Error(`Failed to fetch tokens: ${response.statusText}`);
       }
       const data = await response.json();
       // Handle both array and object formats
       const tokenArray = Array.isArray(data) ? data : Object.values(data);
-      setTokens(tokenArray as Token[]);
+      if (!active) return;
+      setTokens(tokenArray as Token[]);
     } catch (error) {
+      if (controller.signal.aborted) return;
       console.error("Error fetching tokens:", error);
       setTokens([]);
       setFetchError(
         `Couldn't load the curated token list for ${tokenListInfo.chainLabel}. You can still enter a token address manually.`
       );
     } finally {
-      setLoading(false);
+      if (active) setLoading(false);
     }
   };

   fetchTokens();
+  return () => {
+    active = false;
+    controller.abort();
+  };
 }, [tokenListInfo]);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@components/TokenSelector.tsx` around lines 65 - 97, The fetchTokens useEffect
can race across chain switches; update it to create an AbortController and a
local requestId/stale guard tied to tokenListInfo so that when the effect cleans
up it aborts the fetch and marks the request as stale; inside fetchTokens check
the controller.signal and the requestId before calling
setTokens/setFetchError/setLoading so only the latest successful response
updates state; ensure the effect's cleanup aborts the controller and
increments/invalidates the guard to prevent older responses from overwriting
tokens (references: useEffect, fetchTokens, tokenListInfo, setTokens,
setLoading, setFetchError).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@components/TokenSelector.tsx`:
- Around line 65-97: The fetchTokens useEffect can race across chain switches;
update it to create an AbortController and a local requestId/stale guard tied to
tokenListInfo so that when the effect cleans up it aborts the fetch and marks
the request as stale; inside fetchTokens check the controller.signal and the
requestId before calling setTokens/setFetchError/setLoading so only the latest
successful response updates state; ensure the effect's cleanup aborts the
controller and increments/invalidates the guard to prevent older responses from
overwriting tokens (references: useEffect, fetchTokens, tokenListInfo,
setTokens, setLoading, setFetchError).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 057d7e7d-6404-409f-9dfb-1cd4eaf46429

📥 Commits

Reviewing files that changed from the base of the PR and between bb0bf2b and db4c2c8.

📒 Files selected for processing (2)
  • components/TokenSelector.tsx
  • utils/chainMapping.ts

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.

[BUG]: Token selector shows wrong-chain curated tokens on unsupported networks

1 participant