fix: use chain-correct token lists in selector#37
Conversation
📝 WalkthroughWalkthroughThe changes refactor the token-list chain-name resolution to prevent displaying curated tokens from unsupported chains. A new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 | 🔴 CriticalPrevent 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
tokenswith 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
📒 Files selected for processing (2)
components/TokenSelector.tsxutils/chainMapping.ts
Addressed Issues:
Fixes #32
Summary
Validation
npm run buildScreenshots/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 .

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:
I have used the following AI models and tools: TODO
Checklist
Summary by CodeRabbit
Bug Fixes
New Features