Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
app/scripts/lib/static-assets-controller/static-assets-controller.ts
Outdated
Show resolved
Hide resolved
Builds ready [0adf053]
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
app/scripts/lib/static-assets-controller/static-assets-controller.ts
Outdated
Show resolved
Hide resolved
app/scripts/lib/static-assets-controller/static-assets-controller.ts
Outdated
Show resolved
Hide resolved
app/scripts/lib/static-assets-controller/static-assets-controller.ts
Outdated
Show resolved
Hide resolved
Builds ready [3f87cc5]
UI Startup Metrics (1336 ± 104 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [f76bf4d]
UI Startup Metrics (1325 ± 107 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [bbd357c]
UI Startup Metrics (1386 ± 108 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [7196131]
UI Startup Metrics (1352 ± 83 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
| const caip2ChainId = toEvmCaipChainId(chainId); | ||
| const url = new URL(`${TOKEN_API_BASE_URL}/v3/tokens/trending`); | ||
| url.searchParams.set('chainIds', caip2ChainId); | ||
| // Set the minimum volume, liquidity and market cap to 1 to fetch all tokens. | ||
| url.searchParams.set('minVolume24hUsd', '1'); | ||
| url.searchParams.set('minLiquidity', '1'); | ||
| url.searchParams.set('minMarketCap', '1'); | ||
|
|
||
| const response = await fetchWithCache({ | ||
| url: url.toString(), | ||
| fetchOptions: { method: 'GET' }, | ||
| cacheOptions: { cacheRefreshTime: cacheExpirationTime }, | ||
| functionName: 'fetchTopAssets', | ||
| }); | ||
| return response; |
There was a problem hiding this comment.
Thoughts on reusing the core trending service for fetching?
https://github.com/MetaMask/core/blob/main/packages/assets-controllers/src/token-service.ts#L285
There was a problem hiding this comment.
That would be a good idea. We should be using one service per API (or set of APIs, if it makes sense to group them). No embedded fetch calls in our business logic classes. We have some guidance on this pattern here: https://github.com/MetaMask/core/blob/main/docs/code-guidelines/data-services.md
| return; | ||
| } | ||
|
|
||
| const tokens = await this.#fetchTopAssets(chainId); |
There was a problem hiding this comment.
nit - I thought the trending API can take multiple chains at once? We can revisit to reduce # of API requests.
There was a problem hiding this comment.
thx for the advice, i also aware that, but likely it requires some changes on the PR, since the PR is only enable in megaETH, will revisit when we need to support more networks
| }; | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/ban-types | ||
| export type StaticAssetsControllerState = {}; |
There was a problem hiding this comment.
🤔 Why use the controller base class if there is no state?
There was a problem hiding this comment.
it is because the polling controller is extending the base controller
and we are extending the polling controller
There was a problem hiding this comment.
Why here rather than in core? Will mobile require this functionality at some point?
There was a problem hiding this comment.
This PR is to add a stateless controller on extension to poll some tokens from API and add to token controller, thus to show the token on user wallet
and the only use case will be megaETH, they dont have accounts API (due to no payment made to us)
as it may be a temp solution, and no plan to move to mobile for now, so we only do it in extension
Description
This pull request adds a new StaticAssetsController that implements polling functionality to fetch and add top static assets (tokens) for enabled chains. The controller fetches assets from the MetaMask tokens API and filters them against the user's ignored tokens list before adding them to the TokensController.
Changes:
Changelog
CHANGELOG entry: Added a static assets polling controller
Related issues
Jira: https://consensyssoftware.atlassian.net/browse/NEB-285
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Introduces a new background polling controller that periodically fetches token data from an external API and mutates
TokensControllerstate; regressions could affect token lists, network usage, or polling lifecycle.Overview
Adds a new
StaticAssetsController(plus init + restricted messenger) that periodically fetches “top/trending” tokens per enabled EVM chain (with caching), filters out ignored tokens, and callsTokensController:addTokens.Wires this controller into background initialization (
metamask-controller.js), exposesstaticAssetsStartPolling/staticAssetsStopPollingByPollingTokenbackground RPC methods, and starts polling from the UI via a newuseStaticTokensPollinghook included inAssetPollingProvider.Updates Sentry state masking and E2E snapshot fixtures for the new controller, adds unit tests for the controller/init/messenger/hook, and adjusts LavaMoat policies + dependencies to include
@metamask/polling-controlleras a direct dependency.Written by Cursor Bugbot for commit d80181d. This will update automatically on new commits. Configure here.