Skip to content

Commit 5859fbf

Browse files
salimtbmicaelae
authored andcommitted
feat: improve rpc data source (#8385)
## Explanation <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> ## 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](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md) - [ ] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Changes token detection and RPC metadata behavior by replacing `TokenListController:getState` with live Tokens API fetches (with caching/fallback), which can affect detected tokens and metadata availability when the API is slow or unavailable. > > **Overview** > **Token detection now pulls its token list from the Tokens API instead of `TokenListController`.** `TokenDetector` takes a new `TokensApiClient`, fetches `/v3/chains/{chain}/assets`, caches results per chain, and falls back to stale cache on API errors (logging failures). > > `RpcDataSource` and `AssetsController` drop `TokenListController:getState` from allowed actions and remove token-list-based ERC-20 metadata fallbacks; unknown ERC-20s are omitted from `assetsInfo` until downstream enrichment. Tests/fixtures are updated accordingly, and a new `TokensApiClient` (plus unit tests) is added and exported. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 9baa7da. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent e2c6a9a commit 5859fbf

File tree

14 files changed

+647
-661
lines changed

14 files changed

+647
-661
lines changed

eslint-suppressions.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,6 @@
174174
}
175175
},
176176
"packages/assets-controller/src/__fixtures__/MockAssetControllerMessenger.ts": {
177-
"import-x/no-relative-packages": {
178-
"count": 1
179-
},
180177
"no-restricted-syntax": {
181178
"count": 4
182179
}
@@ -188,7 +185,7 @@
188185
},
189186
"packages/assets-controller/src/data-sources/RpcDataSource.ts": {
190187
"no-restricted-syntax": {
191-
"count": 3
188+
"count": 2
192189
}
193190
},
194191
"packages/assets-controller/src/data-sources/SnapDataSource.ts": {

packages/assets-controller/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Changed
1111

12+
- `TokenDetector` now fetches the token list directly from the Tokens API (`/v3/chains/{chain}/assets`) via a new `TokensApiClient` instead of reading from `TokenListController:getState` ([#8385](https://github.com/MetaMask/core/pull/8385))
13+
- `TokenDetectorMessenger` type has been removed; `TokenDetector` constructor now takes a `TokensApiClient` instance as its second argument
14+
- `RpcDataSource` no longer requires `TokenListController:getState``GetTokenListState` has been removed from `RpcDataSourceAllowedActions` and `AssetsControllerAllowedActions`
15+
- Unknown ERC-20 metadata is no longer looked up from the token list as a fallback in `RpcDataSource`; `TokenDataSource` handles enrichment downstream
1216
- Split `getAssets` fetch pipeline into a fast awaited path and a parallel fire-and-forget background path to reduce perceived latency on unlock and onboarding ([#8383](https://github.com/MetaMask/core/pull/8383))
1317
- Fast pipeline: AccountsApi + StakedBalance → Detection → Token + Price (awaited, committed to state immediately)
1418
- Background pipeline: Snap + RPC run in parallel → Detection → Token + Price when basic functionality is enabled; when disabled (RPC-only mode), Token + Price are omitted (fire-and-forget merge)

packages/assets-controller/src/AssetsController.test.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,6 @@ async function withController<ReturnValue>(
178178
).registerActionHandler('NetworkController:getNetworkClientById', () => ({
179179
provider: {},
180180
}));
181-
(
182-
messenger as {
183-
registerActionHandler: (a: string, h: () => unknown) => void;
184-
}
185-
).registerActionHandler('TokenListController:getState', () => ({
186-
tokensChainsCache: {},
187-
}));
188181

189182
if (clientControllerState !== undefined) {
190183
(
@@ -292,13 +285,6 @@ describe('AssetsController', () => {
292285
).registerActionHandler('NetworkController:getNetworkClientById', () => ({
293286
provider: {},
294287
}));
295-
(
296-
messenger as {
297-
registerActionHandler: (a: string, h: () => unknown) => void;
298-
}
299-
).registerActionHandler('TokenListController:getState', () => ({
300-
tokensChainsCache: {},
301-
}));
302288

303289
const controller = new AssetsController({
304290
messenger: messenger as unknown as AssetsControllerMessenger,
@@ -393,13 +379,6 @@ describe('AssetsController', () => {
393379
).registerActionHandler('NetworkController:getNetworkClientById', () => ({
394380
provider: {},
395381
}));
396-
(
397-
messenger as {
398-
registerActionHandler: (a: string, h: () => unknown) => void;
399-
}
400-
).registerActionHandler('TokenListController:getState', () => ({
401-
tokensChainsCache: {},
402-
}));
403382

404383
expect(
405384
() =>

packages/assets-controller/src/AssetsController.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type {
22
AccountTreeControllerGetAccountsFromSelectedAccountGroupAction,
33
AccountTreeControllerSelectedAccountGroupChangeEvent,
44
} from '@metamask/account-tree-controller';
5-
import type { GetTokenListState } from '@metamask/assets-controllers';
65
import { BaseController } from '@metamask/base-controller';
76
import type {
87
ControllerGetStateAction,
@@ -267,7 +266,6 @@ type AllowedActions =
267266
// AssetsController
268267
| AccountTreeControllerGetAccountsFromSelectedAccountGroupAction
269268
// RpcDataSource
270-
| GetTokenListState
271269
| NetworkControllerGetStateAction
272270
| NetworkControllerGetNetworkClientByIdAction
273271
// RpcDataSource, StakedBalanceDataSource

packages/assets-controller/src/__fixtures__/MockAssetControllerMessenger.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import {
88
MockAnyNamespace,
99
} from '@metamask/messenger';
1010
import { NetworkStatus } from '@metamask/network-controller';
11-
1211
import {
1312
NetworkState,
1413
RpcEndpoint,
1514
RpcEndpointType,
16-
} from '../../../network-controller/src/NetworkController';
15+
} from '@metamask/network-controller/src/NetworkController';
16+
1717
import {
1818
AssetsControllerMessenger,
1919
getDefaultAssetsControllerState,
@@ -53,7 +53,6 @@ export function createMockAssetControllerMessenger(): {
5353
'AccountTreeController:getAccountsFromSelectedAccountGroup',
5454
'AssetsController:getState',
5555
// RpcDataSource
56-
'TokenListController:getState',
5756
'NetworkController:getState',
5857
'NetworkController:getNetworkClientById',
5958
// RpcDataSource, StakedBalanceDataSource
@@ -173,10 +172,6 @@ export function registerRpcDataSourceActions(
173172
getDefaultAssetsControllerState(),
174173
);
175174

176-
rootMessenger.registerActionHandler('TokenListController:getState', () => ({
177-
tokensChainsCache: {},
178-
}));
179-
180175
rootMessenger.registerActionHandler(
181176
'NetworkEnablementController:getState',
182177
() => ({

0 commit comments

Comments
 (0)