Skip to content

feat(core-backend): add token search API client#8822

Open
n3ps wants to merge 4 commits into
mainfrom
codex/token-search-api-client
Open

feat(core-backend): add token search API client#8822
n3ps wants to merge 4 commits into
mainfrom
codex/token-search-api-client

Conversation

@n3ps
Copy link
Copy Markdown
Contributor

@n3ps n3ps commented May 15, 2026

Explanation

Adds the Token API search to @metamask/core-backend so consumers can use the shared ApiPlatformClient for GET /tokens/search instead 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

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

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/search to TokenApiClient via new fetchTokenSearch and getTokenSearchQueryOptions helpers, including query normalization (trimmed query, deterministically sorted networks) 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.

@n3ps n3ps marked this pull request as ready for review May 15, 2026 00:48
@n3ps n3ps requested review from a team as code owners May 15, 2026 00:48
@n3ps n3ps temporarily deployed to default-branch May 15, 2026 00:48 — with GitHub Actions Inactive
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)
Fix in Cursor Fix in Web

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants