Repository navigation
Commit 2659ea1
authored
feat: send x-mm-service-profile on token search (assets-controllers ^113.2.0) (#47655)
## **Description**
Token search requests now send the `x-mm-service-profile:
assets--trending-search` header, so backend services can identify this
traffic
([ASSETS-4243](https://consensyssoftware.atlassian.net/browse/ASSETS-4243)).
This is the extension version of
MetaMask/metamask-mobile#38852.
The extension makes `/tokens/search` requests from two places:
1. **Discover crypto search**
(`ui/hooks/discover-search/useDiscoverCryptoSearch.ts`) calls core's
`searchTokens`. Since MetaMask/core#11274
(released in `@metamask/assets-controllers` 113.2.0), core sends this
header with `assets--trending-search` as the default. The hook now also
passes `serviceProfile` explicitly.
2. **Token management search** (`ui/hooks/useTokenSearch.ts`) uses a
local helper, `shared/lib/token-search/token-search-api.ts`, that builds
its own `/tokens/search` URL. Bumping the package alone would not tag
these requests. Core's `searchTokens` can't replace this helper as-is:
it has a different signature and response shape, and it takes no
`AbortSignal`. So the helper's fetch now adds the header itself.
Changes:
- Bump `@metamask/assets-controllers` from `^113.1.1` to `^113.2.0`.
Peer dependencies are the same as 113.1.1. The only transitive change is
the `uuid` range (`^14.0.1` → `^14.0.2`), which still resolves to
14.0.3, so there are no LavaMoat policy changes. The lockfile is
deduped.
- Add the shared constant `TOKEN_SEARCH_SERVICE_PROFILE =
'assets--trending-search'`, used by both paths.
- Unit tests check the header on the local fetch, and check
`serviceProfile` on both the first page and the next page of the
Discover search.
- The token API allows this header in CORS
(`access-control-allow-headers: x-client-id,x-mm-service-profile`).
Note: the token-management search is tagged as
`assets--trending-search`, the same profile core now uses by default for
every `searchTokens` caller. If backend wants a separate profile for it,
that is a one-line change to the constant.
## **Changelog**
CHANGELOG entry: null
## **Related issues**
Fixes: https://consensyssoftware.atlassian.net/browse/ASSETS-4243
Refs: MetaMask/core#11274,
MetaMask/metamask-mobile#38852
## **Manual testing steps**
1. Run the extension and open DevTools on the extension UI with the
Network tab open.
2. Open Discover/Explore and search for a token (e.g. "USDC"). Check
that the `GET /tokens/search` request includes the header
`x-mm-service-profile: assets--trending-search`. Scroll to load more
results and check that the paginated request sends the same header.
3. Go to token management (Import tokens / Manage tokens) and type a
token name in the search. Check that the `/tokens/search` request
includes `x-mm-service-profile: assets--trending-search` and still
includes `X-Client-Id: extension`.
4. Check that search results still show up as before in both places.
<!--
## **Screenshots/Recordings**
### **Before**
### **After**
-->
## **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.
## **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.
## Adversarial review (adverse)
Final verdict (round 2/3): SHIP (unanimous, 3/3)
Findings: 0 critical · 1 warning · 11 info (across both rounds). Fixed:
the comment wrongly said the constant "matches the core default" (round
1 warning); it now says both paths pass the constant explicitly.
Declined: none. Info items were not actioned (some are notes only, e.g.
that the header is not a trust boundary and that the transitive `uuid`
range changed).
Reviewer: claude -p via adverse 0.2.1 (3 personas, 2 rounds).
[ASSETS-4243]:
https://consensyssoftware.atlassian.net/browse/ASSETS-4243?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Adds a request header and bumps a dependency; no auth, signing, or
response parsing changes beyond what tests cover.
>
> **Overview**
> Extension **token search** traffic is now tagged for backend analytics
by sending **`x-mm-service-profile: assets--trending-search`** on every
`/tokens/search` call, alongside the existing **`X-Client-Id:
extension`**.
>
> A shared **`TOKEN_SEARCH_SERVICE_PROFILE`** constant keeps both call
paths aligned: **Discover crypto search** passes **`serviceProfile`**
into **`@metamask/assets-controllers`** **`searchTokens`** (including
paginated loads), and the **local**
**`shared/lib/token-search/token-search-api`** helper (used for
import/manage token search) sets the same header on its direct fetch.
**`@metamask/assets-controllers`** is bumped to **`^113.2.0`** so core’s
search client supports the option; tests assert the headers and
**`serviceProfile`** on first and next pages.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
9d7e1ce. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 0c56a84 commit 2659ea1
6 files changed
Lines changed: 53 additions & 11 deletions
File tree
- ui/hooks/discover-search
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
417 | 417 | | |
418 | 418 | | |
419 | 419 | | |
420 | | - | |
| 420 | + | |
421 | 421 | | |
422 | 422 | | |
423 | 423 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
126 | 149 | | |
127 | 150 | | |
128 | 151 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
10 | 18 | | |
11 | 19 | | |
12 | 20 | | |
| |||
77 | 85 | | |
78 | 86 | | |
79 | 87 | | |
80 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
81 | 92 | | |
82 | 93 | | |
83 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
| |||
229 | 230 | | |
230 | 231 | | |
231 | 232 | | |
232 | | - | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
233 | 237 | | |
234 | 238 | | |
235 | 239 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
9 | 12 | | |
10 | 13 | | |
11 | 14 | | |
| |||
129 | 132 | | |
130 | 133 | | |
131 | 134 | | |
| 135 | + | |
132 | 136 | | |
133 | 137 | | |
134 | 138 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7429 | 7429 | | |
7430 | 7430 | | |
7431 | 7431 | | |
7432 | | - | |
7433 | | - | |
7434 | | - | |
| 7432 | + | |
| 7433 | + | |
| 7434 | + | |
7435 | 7435 | | |
7436 | 7436 | | |
7437 | 7437 | | |
| |||
7478 | 7478 | | |
7479 | 7479 | | |
7480 | 7480 | | |
7481 | | - | |
| 7481 | + | |
7482 | 7482 | | |
7483 | 7483 | | |
7484 | 7484 | | |
7485 | | - | |
| 7485 | + | |
7486 | 7486 | | |
7487 | 7487 | | |
7488 | 7488 | | |
| |||
35493 | 35493 | | |
35494 | 35494 | | |
35495 | 35495 | | |
35496 | | - | |
| 35496 | + | |
35497 | 35497 | | |
35498 | 35498 | | |
35499 | 35499 | | |
| |||
47633 | 47633 | | |
47634 | 47634 | | |
47635 | 47635 | | |
47636 | | - | |
| 47636 | + | |
47637 | 47637 | | |
47638 | 47638 | | |
47639 | 47639 | | |
| |||
0 commit comments