Commit fc65ac9
committed
fix(token-lists): preserve first-wins semantics in chainsById and drop 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.1 parent 72059eb commit fc65ac9
2 files changed
Lines changed: 9 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
| 244 | + | |
244 | 245 | | |
245 | 246 | | |
246 | 247 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
16 | 21 | | |
17 | 22 | | |
18 | 23 | | |
| |||
122 | 127 | | |
123 | 128 | | |
124 | 129 | | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
137 | 133 | | |
138 | 134 | | |
139 | 135 | | |
| |||
197 | 193 | | |
198 | 194 | | |
199 | 195 | | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | 196 | | |
205 | 197 | | |
206 | 198 | | |
| |||
0 commit comments