Skip to content

fix(token-lists): drop tokens for chains absent from viem/chains#470

Merged
gabitoesmiapodo merged 4 commits into
developfrom
fix/465
Apr 21, 2026
Merged

fix(token-lists): drop tokens for chains absent from viem/chains#470
gabitoesmiapodo merged 4 commits into
developfrom
fix/465

Conversation

@gabitoesmiapodo
Copy link
Copy Markdown
Collaborator

Summary

Closes #465

@uniswap/default-token-list still ships tokens for deprecated testnets (Ropsten chain ID 3, Rinkeby chain ID 4) that viem/chains no longer exports. On every cold load, combineTokenLists caught the buildNativeToken throw and emitted it via console.error -- noise despite the intent to ignore it. This implements Option B from the issue: filter out tokens whose chainId is absent from viem/chains before they reach buildNativeToken, eliminating the errors at source and keeping tokensByChainId free of unreachable chain buckets.

Changes

  • Filter tokens with unsupported chainId values out of combined token lists before building native tokens
  • Replace the supportedChainIds Set with a shared chainsById Map for O(1) lookups and reuse across the pipeline
  • Annotate the chainsById Map key as number to satisfy tsc
  • Preserve first-wins semantics in chainsById population and drop the now-dead catch block

Acceptance criteria

  • No Native token not found errors logged when loading the app with default config
  • tokensByChainId contains only chains supported by viem/chains
  • Tests cover the unsupported-chainId case
  • pnpm lint, pnpm test, pnpm build all pass

Test plan

Automated tests

src/hooks/useTokenLists.test.ts -- updated with coverage for the unsupported-chainId filter case.

Run: pnpm test src/hooks/useTokenLists.test.ts

Manual verification
  1. pnpm dev
  2. Open the home page (TokenInput demo calls useTokenLists)
  3. Open browser devtools console
  4. Verify no Native token not found for chain ID: 3 or ... chain ID: 4 errors appear on cold load

Breaking changes

None.

Checklist

  • Self-reviewed my own diff
  • Tests added or updated
  • Docs updated (if applicable)
  • No unrelated changes bundled in

Screenshots

None.

@uniswap/default-token-list still ships tokens for Ropsten (chainId 3)
and Rinkeby (chainId 4), both removed from viem/chains. combineTokenLists
caught the buildNativeToken throw but logged it via console.error before
ignoring it, producing noise on every cold load.

Extend the existing safeParse filter to also drop tokens whose chainId
is not present in viem/chains, mirroring the existing non-EVM drop. This
removes the throw at source and keeps tokensByChainId free of
unreachable buckets.

Closes #465
…nsById Map

Eliminates the double enumeration of viem/chains: the Set built for
filter membership and the Object.values().find() in buildNativeToken
both traversed the same data. A single module-level Map keyed by chain
id serves both lookups, making buildNativeToken an O(1) get instead of
O(n) find.

Also flattens the two-statement filter predicate into a single && expression
and condenses the 7-line inline comment to the essential WHY.
…p dead catch

viem/chains exports 702 chain objects spanning 675 unique IDs; 27 export
names share a chainId, and 10 of those collisions have divergent
nativeCurrency. The previous Map(...map) construction was last-wins, silently
changing buildNativeToken results versus the original find()-first-wins
behaviour for chainIds 9, 166, 260, 999, 1001, 1337, 8217, 9496, 200810,
200901 -- most consequentially chainId 1337 (Localhost ETH/18 → Tempo USD/6).
Replace with an explicit first-wins loop.

Hoist chainsById to the top of the module so both the filter in
combineTokenLists and buildNativeToken reference the same declaration without
a forward-reference.

After the chainsById.has(token.chainId) filter, every token entering the
reduce accumulator has a known chain, making the try/catch/console.error
branch unreachable. Remove it; the throw inside buildNativeToken remains as
a defensive invariant for callers that bypass the filter.

Add a positive-survival assertion to the unsupported-chainId test to guard
against future filter inversions silently dropping valid tokens.
Copilot AI review requested due to automatic review settings April 21, 2026 15:26
@gabitoesmiapodo gabitoesmiapodo self-assigned this Apr 21, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 21, 2026

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

Project Deployment Actions Updated (UTC)
components.dappbooster Ready Ready Preview, Comment Apr 21, 2026 3:26pm
demo.dappbooster Ready Ready Preview, Comment Apr 21, 2026 3:26pm
docs.dappbooster Ready Ready Preview, Comment Apr 21, 2026 3:26pm

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes noisy console errors caused by deprecated testnet tokens (e.g., chainIds 3 and 4) still present in @uniswap/default-token-list, by filtering out tokens whose chainId is not available in viem/chains before native-token injection occurs.

Changes:

  • Introduces a shared chainsById map for O(1) chain lookups and reuse across token processing.
  • Filters out tokens whose chainId is absent from viem/chains, preventing buildNativeToken from throwing.
  • Updates tests to cover the unsupported-chainId filtering behavior and ensure no logging occurs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/hooks/useTokenLists.ts Adds chainsById, filters unsupported chain IDs early, and simplifies native-token injection by removing the now-unreachable catch path.
src/hooks/useTokenLists.test.ts Adds a regression test ensuring unsupported chain IDs are filtered out and no console.error is emitted.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gabitoesmiapodo gabitoesmiapodo merged commit 35b4548 into develop Apr 21, 2026
13 checks passed
@gabitoesmiapodo gabitoesmiapodo deleted the fix/465 branch April 21, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Console errors for deprecated chain IDs in default token list

2 participants