Repository navigation
Commit f0ab05f
authored
fix(discover-search): remove client sorting (#47699)
## **Description**
Discover Search's crypto results should display in the order their data
source provides. A Slack-reported issue (parent ticket ASSETS-4296)
surfaced risky-flagged tokens at the top of Explore/Search because the
extension re-sorted results client-side. Per the ASSETS-4296 decision
("We do not need this client side filtering. It's causing us more
headaches than good."), the crypto search client-side ordering is
removed so the search API owns the order.
Scope (per the ASSETS-4298/ASSETS-4296 update recorded on the tickets):
- **Crypto search — changed:** removed the first-page merge/re-sort in
`ui/hooks/discover-search/useDiscoverCryptoSearch.ts`. Search results
now pass through in the API's relevance order — no merging of locally
cached trending matches into page 1 and no `byMarketCap` re-sort. Cursor
pages over live market data can repeat an asset, so exact `assetId`
repeats across pages are dropped (first occurrence wins) to keep the
consumer's assetId-keyed list rows unique; ordering is otherwise
untouched. The RWA membership filter is unchanged (stocks are served by
their own section).
- **Perps — intentionally unchanged:** the perps market stream comes
from the perps team with no server ordering, so the client-side 24h %
change sort in the Discover Search perps feed is load-bearing and stays
as-is.
`byMarketCap` remains in `shared/lib/token-search/token-search-api.ts`
(still used by cashtag resolution); only the Discover Search usage is
removed.
Other surfaces intentionally untouched:
- The volume-descending base ordering in
`ui/hooks/perps/stream/usePerpsLiveMarketData.ts` (shared by other perps
surfaces — Perps Market List default sort, Top Movers input).
- Perps Top Movers and the Perps Market List page (user-driven sorting
is the feature there).
- The stocks feed (already server-ordered via
`sortBy=price_change_desc`).
- Perps active-query Fuse.js relevance ordering.
## **Changelog**
CHANGELOG entry: Updated Discover Search crypto results to show the
order provided by the search API
## **Related issues**
Fixes:
[ASSETS-4298](https://consensyssoftware.atlassian.net/browse/ASSETS-4298)
Sibling (mobile, parallel):
[ASSETS-4297](https://consensyssoftware.atlassian.net/browse/ASSETS-4297)
Parent:
[ASSETS-4296](https://consensyssoftware.atlassian.net/browse/ASSETS-4296)
## **Manual testing steps**
1. Run the extension (`yarn start`), unlock a wallet.
2. Open Discover Search from the home search bar (Explore).
3. Type a query (e.g. "eth") and check the Crypto results: the list
should follow the API's relevance order (no market-cap reshuffle, no
locally cached trending matches merged in ahead of the API's own
results).
4. Use "View X more" / "View all" on the crypto results: later pages
should append in server order, with no repeated rows.
5. Check the Perps section (empty query and with a query): ordering
behavior is unchanged — the empty-query feed still sorts by 24h price
change (intentionally kept; the perps stream has no server ordering).
## **Screenshots/Recordings**
### **Before**
N/A — previous behavior was the client-side trending merge into the
first search page, followed by a market-cap re-sort (described above).
### **After (head `90a00458ec9`, captured 2026-11-09)**
| What it shows | Screenshot |
| --- | --- |
| Empty Discover Search query — Crypto/Perps/Stocks sections render
normally | 
|
| Crypto "pepe" query — 20 rows in API relevance order (PEPE mainnet
first, then variants across chains) | 
|
| Perps tab — intentionally unchanged client-side 24h % change sort |

|
<!--
## **Pre-merge reviewer checklist**
- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
-->
## **Pre-merge author checklist**
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I've included tests if applicable
- [x] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **Adversarial review (adverse) — superseded head**
Final verdict (round 2/3): SHIP (unanimous, 3/3 ship)
Findings: 0 critical · 1 warning · 7 info. Fixed (from round 1):
cross-page duplicate `assetId`s reaching an assetId-keyed list
(order-preserving repeat drop added, server relevance order otherwise
untouched); misleading "the server dedupes" comment (now describes what
the client does); perps empty-query order dependency on the upstream
volume sort unpinned by tests (combined `markets` volume-descending
assertion added to `usePerpsLiveMarketData` test). Declined:
"byMarketCap may now be an export with no production callers": false
positive — cashtag resolution (`app/scripts/cashtag/lib/data.ts`
`resolveTicker`, wired via the `scripts/n` background entry) still calls
it in production.
Reviewer: `pi -p --model litellm/claude-opus-5-5` via adverse 0.2.1 (3
personas, 2 rounds) — designated backup reviewer during the `claude -p`
spend-limit outage.
Note: this round reviewed the earlier head (`0fe7f3d765b`), which also
removed the perps 24h % change sort; that removal was reverted by the
ASSETS-4298 scope update (perps stream has no server ordering — the
client sort is load-bearing). The crypto search change reviewed here is
unchanged. See the section below for the re-review of the final head.
## **Adversarial review (adverse) — final head (`7c9dc5e08f6`)**
Final verdict (round 3/3): SHIP (unanimous, 3/3 ship)
Findings: 0 critical · 0 warnings · 7 info. Fixed: none required. Info
items, no action: result order depending on the search API's relevance
ranking is the ticket's intent; `totalCount` vs visible rows difference
is pre-existing server semantics (server total includes RWA items served
by the stocks section); the trending query running during active search
is an intentional cache warm for the empty-query state (pre-existing
fetch behavior); "byMarketCap may have no callers" is a false positive
(cashtag resolution still calls it in production); trending mocks in the
search tests intentionally prove that no trending merge happens
(regression guard for this change).
Reviewer: `pi -p --model litellm/claude-opus-5-5` via adverse 0.2.1 (3
personas, 2 rounds) — designated backup reviewer during the `claude -p`
spend-limit outage.
[ASSETS-4298]:
https://consensyssoftware.atlassian.net/browse/ASSETS-4298?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ1 parent 69cd4a7 commit f0ab05f
2 files changed
Lines changed: 8 additions & 56 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
139 | | - | |
| 139 | + | |
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | 155 | | |
164 | 156 | | |
165 | 157 | | |
| |||
236 | 228 | | |
237 | 229 | | |
238 | 230 | | |
239 | | - | |
240 | 231 | | |
241 | 232 | | |
242 | 233 | | |
243 | 234 | | |
244 | 235 | | |
245 | 236 | | |
246 | | - | |
| 237 | + | |
247 | 238 | | |
248 | 239 | | |
249 | 240 | | |
250 | 241 | | |
251 | | - | |
| 242 | + | |
252 | 243 | | |
253 | 244 | | |
254 | 245 | | |
| |||
277 | 268 | | |
278 | 269 | | |
279 | 270 | | |
280 | | - | |
| 271 | + | |
281 | 272 | | |
282 | 273 | | |
283 | 274 | | |
| |||
311 | 302 | | |
312 | 303 | | |
313 | 304 | | |
314 | | - | |
315 | | - | |
316 | | - | |
| 305 | + | |
317 | 306 | | |
318 | 307 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
| 8 | + | |
12 | 9 | | |
13 | 10 | | |
14 | 11 | | |
| |||
38 | 35 | | |
39 | 36 | | |
40 | 37 | | |
41 | | - | |
42 | 38 | | |
43 | 39 | | |
44 | 40 | | |
| |||
63 | 59 | | |
64 | 60 | | |
65 | 61 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | 62 | | |
88 | 63 | | |
89 | 64 | | |
| |||
147 | 122 | | |
148 | 123 | | |
149 | 124 | | |
150 | | - | |
151 | 125 | | |
152 | 126 | | |
153 | 127 | | |
| |||
165 | 139 | | |
166 | 140 | | |
167 | 141 | | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
| 142 | + | |
| 143 | + | |
180 | 144 | | |
181 | 145 | | |
182 | 146 | | |
| |||
186 | 150 | | |
187 | 151 | | |
188 | 152 | | |
189 | | - | |
190 | 153 | | |
191 | 154 | | |
192 | 155 | | |
| |||
0 commit comments