Commit 045a39f
authored
perf: Speed up the creation of the token list for Predict withdraw (#27735)
## **Description**
This speeds up the withdraw token-selection path by moving the allowlist
filter earlier in the pipeline.
Before this change, withdraw flows loaded the full token catalog, built
`AssetType`s for all matching catalog entries, sorted the full result,
and only then filtered down to the small allowlisted set we actually
care about. This change adds a `tokenFilter` hook parameter so
`useAccountTokens` can skip irrelevant catalog entries before building
them, and `useWithdrawTokenFilter` passes the withdraw allowlist down to
that lower-level loop.
It also keeps the existing post-filter in place for correctness, so
allowlisted tokens already owned by the user and native-token address
mapping still work as before.
Local dev measurements while opening **Predict Withdraw**:
| Metric | Before | After |
| --- | ---: | ---: |
| `useAccountTokens` | 954-1,143ms | 41-48ms |
| Catalog tokens built | 18,524 | 0 |
| Total tokens sorted | 18,618 | 15 |
This brings the measured token-loading path from roughly `~1.05s` down
to `~44ms` (`~24x` faster).
## **Changelog**
CHANGELOG entry: Improved performance when loading Predict withdraw
token selection
## **Related issues**
Fixes: https://consensyssoftware.atlassian.net/browse/CONF-1054
## **Manual testing steps**
1. Open Predict Withdraw, it will load much faster now
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Medium risk because it changes how withdraw token lists are
constructed and filtered, which could inadvertently hide valid tokens if
chainId/address normalization or `assetId` handling is wrong. Scope is
limited to token-selection hooks and is covered by updated/added unit
tests.
>
> **Overview**
> Speeds up Predict Withdraw token selection by pushing the withdraw
allowlist filter down into token collection, avoiding building/sorting
the full token catalog before narrowing to allowlisted entries.
>
> This introduces an optional `tokenFilter(chainId, address)` plumbed
from `useWithdrawTokenFilter` → `useSendTokens` → `useAccountTokens`,
and replaces the previous post-filtering in `useWithdrawTokenFilter`
with a precomputed allowlist lookup that also maps zero-address entries
to chain-specific native token addresses.
>
> Tests are updated to assert `useSendTokens` is called with the new
filtering options and to validate `tokenFilter` behavior
(case-insensitive matching, chain gating, and native-token mapping),
plus new `useAccountTokens` coverage ensuring both owned assets and
catalog token building respect `tokenFilter`.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
b8e1cc7. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>1 parent 5ff018e commit 045a39f
6 files changed
Lines changed: 244 additions & 170 deletions
File tree
- app/components/Views/confirmations/hooks
- pay
- send
Lines changed: 63 additions & 132 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
136 | | - | |
| 137 | + | |
137 | 138 | | |
138 | 139 | | |
139 | 140 | | |
| |||
144 | 145 | | |
145 | 146 | | |
146 | 147 | | |
147 | | - | |
| 148 | + | |
148 | 149 | | |
149 | | - | |
150 | | - | |
151 | | - | |
| 150 | + | |
152 | 151 | | |
153 | 152 | | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
| 153 | + | |
| 154 | + | |
166 | 155 | | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
172 | 161 | | |
173 | 162 | | |
174 | | - | |
175 | | - | |
| 163 | + | |
| 164 | + | |
176 | 165 | | |
177 | 166 | | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
| 167 | + | |
188 | 168 | | |
189 | 169 | | |
190 | 170 | | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
195 | 176 | | |
196 | 177 | | |
197 | | - | |
198 | | - | |
| 178 | + | |
| 179 | + | |
199 | 180 | | |
200 | 181 | | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
| 182 | + | |
211 | 183 | | |
212 | 184 | | |
213 | 185 | | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
219 | 191 | | |
220 | 192 | | |
221 | | - | |
222 | | - | |
| 193 | + | |
| 194 | + | |
223 | 195 | | |
224 | 196 | | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
| 197 | + | |
232 | 198 | | |
233 | 199 | | |
234 | 200 | | |
235 | | - | |
| 201 | + | |
| 202 | + | |
236 | 203 | | |
237 | | - | |
238 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
239 | 209 | | |
240 | 210 | | |
241 | | - | |
242 | | - | |
| 211 | + | |
| 212 | + | |
243 | 213 | | |
244 | 214 | | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
| 215 | + | |
251 | 216 | | |
252 | 217 | | |
253 | 218 | | |
254 | | - | |
| 219 | + | |
| 220 | + | |
255 | 221 | | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
260 | 225 | | |
261 | 226 | | |
262 | | - | |
263 | | - | |
| 227 | + | |
| 228 | + | |
264 | 229 | | |
265 | 230 | | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
| 231 | + | |
270 | 232 | | |
271 | 233 | | |
272 | 234 | | |
273 | | - | |
| 235 | + | |
| 236 | + | |
274 | 237 | | |
275 | | - | |
276 | | - | |
| 238 | + | |
| 239 | + | |
277 | 240 | | |
278 | 241 | | |
279 | | - | |
280 | | - | |
| 242 | + | |
| 243 | + | |
281 | 244 | | |
282 | 245 | | |
283 | 246 | | |
284 | 247 | | |
285 | | - | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
286 | 251 | | |
287 | 252 | | |
288 | 253 | | |
289 | 254 | | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
304 | 258 | | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
331 | 262 | | |
332 | 263 | | |
Lines changed: 37 additions & 37 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
32 | 42 | | |
33 | 43 | | |
34 | 44 | | |
| 45 | + | |
35 | 46 | | |
36 | 47 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | 48 | | |
45 | 49 | | |
46 | | - | |
| 50 | + | |
47 | 51 | | |
48 | 52 | | |
49 | | - | |
| 53 | + | |
50 | 54 | | |
51 | | - | |
| 55 | + | |
52 | 56 | | |
53 | 57 | | |
54 | 58 | | |
55 | | - | |
56 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
57 | 64 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
| 65 | + | |
| 66 | + | |
63 | 67 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
71 | 71 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
83 | 80 | | |
84 | | - | |
85 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
86 | 86 | | |
0 commit comments