feat(core-backend): add token search API client#8822
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 2b7eaed. Configure here.
| } | ||
|
|
||
| return this.queryClient.fetchQuery( | ||
| this.getTokenSearchQueryOptions(normalizedQueryOptions, options), |
There was a problem hiding this comment.
Double normalization of query options is redundant
Low Severity
fetchTokenSearch calls normalizeTokenSearchQueryOptions on the raw input, then passes the already-normalized result to getTokenSearchQueryOptions, which calls normalizeTokenSearchQueryOptions again. The normalization happens to be idempotent (trim/sort), so this is functionally harmless, but it's unnecessary work and deviates from how every other fetch* method in this class delegates to its corresponding get*QueryOptions — none of the others pre-normalize. The early-return check could use queryOptions.query.trim() inline instead, passing the original queryOptions through to getTokenSearchQueryOptions which already handles normalization.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 2b7eaed. Configure here.
The queryFn branch for normalized empty queries was only reachable via getTokenSearchQueryOptions; fetchTokenSearch returns early without invoking it, which dropped global branch coverage below the 99% Jest threshold. Co-authored-by: Francis Nepomuceno <n3ps@users.noreply.github.com>


Explanation
Adds the Token API search to
@metamask/core-backendso consumers can use the sharedApiPlatformClientforGET /tokens/searchinstead of hand-rolling fetch calls.This adds
TokenApiClient.getTokenSearchQueryOptions,TokenApiClient.fetchTokenSearch, exported token search request/response types, empty-query short-circuit behavior, deterministic network sorting, and focused tests.References
Related to MetaMask/metamask-extension#42624.
Checklist
Note
Medium Risk
Adds a new Token API search endpoint wrapper and related exported types, which may affect consumers relying on query caching keys and request parameter formatting. Risk is limited to the token API client surface area and is covered by new unit tests (including empty-query short-circuiting).
Overview
Adds first-class support for
GET /tokens/searchtoTokenApiClientvia newfetchTokenSearchandgetTokenSearchQueryOptionshelpers, including query normalization (trimmedquery, deterministically sortednetworks) and a no-network-call short-circuit for empty queries.Exports new token-search request/response types (
TokenSearchResult,TokenSearchPageInfo,TokenSearchResponse,TokenSearchQueryOptions) through the API barrels and package root, updates tests to validate URL params, caching defaults (STALE_TIMES.DEFAULT/GC_TIMES.DEFAULT), and empty-query behavior, and records the addition in the changelog.Reviewed by Cursor Bugbot for commit 77572bb. Bugbot is set up for automated code reviews on this repo. Configure here.