@metamask-previews/assets-controller 19.1.0-preview-bd4de146a → 19.1.0-preview-a0d99e051
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/dist/AssetsController-method-action-types.d.ts +18 -1
- package/dist/AssetsController-method-action-types.d.ts.map +1 -1
- package/dist/AssetsController-method-action-types.js.map +1 -1
- package/dist/AssetsController.d.ts +15 -10
- package/dist/AssetsController.d.ts.map +1 -1
- package/dist/AssetsController.js +77 -135
- package/dist/AssetsController.js.map +1 -1
- package/dist/data-sources/PriceDataSource.d.ts +22 -17
- package/dist/data-sources/PriceDataSource.d.ts.map +1 -1
- package/dist/data-sources/PriceDataSource.js +60 -123
- package/dist/data-sources/PriceDataSource.js.map +1 -1
- package/dist/data-sources/RpcDataSource.d.ts.map +1 -1
- package/dist/data-sources/RpcDataSource.js +0 -6
- package/dist/data-sources/RpcDataSource.js.map +1 -1
- package/dist/data-sources/TokenDataSource.d.ts +19 -19
- package/dist/data-sources/TokenDataSource.d.ts.map +1 -1
- package/dist/data-sources/TokenDataSource.js +32 -87
- package/dist/data-sources/TokenDataSource.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/middlewares/ParallelMiddleware.d.ts.map +1 -1
- package/dist/middlewares/ParallelMiddleware.js +0 -6
- package/dist/middlewares/ParallelMiddleware.js.map +1 -1
- package/dist/middlewares/index.d.ts +0 -2
- package/dist/middlewares/index.d.ts.map +1 -1
- package/dist/middlewares/index.js +0 -1
- package/dist/middlewares/index.js.map +1 -1
- package/dist/pipeline/buildFastFetchSources.d.ts +9 -12
- package/dist/pipeline/buildFastFetchSources.d.ts.map +1 -1
- package/dist/pipeline/buildFastFetchSources.js +10 -13
- package/dist/pipeline/buildFastFetchSources.js.map +1 -1
- package/dist/pipeline/buildUpdateSources.d.ts +0 -1
- package/dist/pipeline/buildUpdateSources.d.ts.map +1 -1
- package/dist/pipeline/buildUpdateSources.js +1 -2
- package/dist/pipeline/buildUpdateSources.js.map +1 -1
- package/dist/pipeline/buildWsUpdateSources.d.ts +0 -1
- package/dist/pipeline/buildWsUpdateSources.d.ts.map +1 -1
- package/dist/pipeline/buildWsUpdateSources.js +1 -2
- package/dist/pipeline/buildWsUpdateSources.js.map +1 -1
- package/dist/types.d.ts +0 -11
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/getAssetIdsForMetadataFetch.d.ts +36 -0
- package/dist/utils/getAssetIdsForMetadataFetch.d.ts.map +1 -0
- package/dist/utils/getAssetIdsForMetadataFetch.js +145 -0
- package/dist/utils/getAssetIdsForMetadataFetch.js.map +1 -0
- package/dist/utils/getAssetIdsForPriceFetch.d.ts +74 -0
- package/dist/utils/getAssetIdsForPriceFetch.d.ts.map +1 -0
- package/dist/utils/getAssetIdsForPriceFetch.js +224 -0
- package/dist/utils/getAssetIdsForPriceFetch.js.map +1 -0
- package/package.json +9 -12
- package/dist/middlewares/DetectionMiddleware.d.ts +0 -48
- package/dist/middlewares/DetectionMiddleware.d.ts.map +0 -1
- package/dist/middlewares/DetectionMiddleware.js +0 -130
- package/dist/middlewares/DetectionMiddleware.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,14 +9,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Added
|
|
11
11
|
|
|
12
|
+
- Add `syncAssetsPrices(assetIds)`, exposed as the `AssetsController:syncAssetsPrices` messenger action. It force-fetches spot prices for an explicit CAIP-19 asset list through `PriceDataSource` and merges them into state ([#10892](https://github.com/MetaMask/core/pull/10892))
|
|
12
13
|
- Add support for Node.js 26 ([#10981](https://github.com/MetaMask/core/pull/10981))
|
|
13
14
|
|
|
14
15
|
### Changed
|
|
15
16
|
|
|
17
|
+
- Fetch token metadata again when stored metadata is missing a field that controller logic or a client reads (`symbol`, `name`, `decimals`, `image`, `aggregators`, or `occurrences`), instead of treating an `image` as complete
|
|
18
|
+
- **BREAKING:** Remove `DetectionMiddleware`. A balance refresh prices balances on the current response only when they have no stored price, and excludes hidden assets. The price poll still refreshes stored prices for held balances and custom assets, and does not price metadata that has no balance. `TokenDataSource` fetches metadata for state balances that have none and for response balances, and excludes hidden assets ([#10892](https://github.com/MetaMask/core/pull/10892))
|
|
19
|
+
- **BREAKING:** Remove `assetsForPriceUpdate` from `getAssets` options. Refresh an explicit asset list with `syncAssetsPrices` instead ([#10892](https://github.com/MetaMask/core/pull/10892))
|
|
16
20
|
- Bump `@metamask/account-tree-controller` from `^11.0.1` to `^11.1.1` ([#10891](https://github.com/MetaMask/core/pull/10891), [#10925](https://github.com/MetaMask/core/pull/10925))
|
|
17
21
|
- Bump `@metamask/assets-controllers` from `^112.1.2` to `^112.1.3` ([#10925](https://github.com/MetaMask/core/pull/10925))
|
|
18
22
|
- Bump `@metamask/network-controller` from `^37.1.0` to `^37.1.1` ([#10982](https://github.com/MetaMask/core/pull/10982))
|
|
19
23
|
|
|
24
|
+
### Removed
|
|
25
|
+
|
|
26
|
+
- **BREAKING:** Remove the `AssetsController:assetsDetected` event and the `AssetsControllerAssetsDetectedEvent` type. No client subscribed to it ([#10892](https://github.com/MetaMask/core/pull/10892))
|
|
27
|
+
- **BREAKING:** Remove `detectedAssets` from `DataResponse` and the unused `AssetsDetectedEvent` type. Newly detected tokens still arrive as balances and metadata ([#10892](https://github.com/MetaMask/core/pull/10892))
|
|
28
|
+
|
|
20
29
|
## [19.1.0]
|
|
21
30
|
|
|
22
31
|
### Changed
|
|
@@ -7,6 +7,23 @@ export type AssetsControllerGetAssetsAction = {
|
|
|
7
7
|
type: `AssetsController:getAssets`;
|
|
8
8
|
handler: AssetsController['getAssets'];
|
|
9
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Force-fetch spot prices for an explicit asset list.
|
|
12
|
+
*
|
|
13
|
+
* Calls `PriceDataSource` directly and merges the result into `assetsPrice`.
|
|
14
|
+
* Prices are shared across accounts, so this does not take an account or
|
|
15
|
+
* chain scope and does not run the balance pipeline.
|
|
16
|
+
*
|
|
17
|
+
* Returns without calling the Price API when basic functionality is off.
|
|
18
|
+
* That matches the asset pipeline, which drops the price source in RPC-only
|
|
19
|
+
* mode, and `setSelectedCurrency`, which skips its price refresh.
|
|
20
|
+
*
|
|
21
|
+
* @param assetIds - CAIP-19 asset IDs to sync.
|
|
22
|
+
*/
|
|
23
|
+
export type AssetsControllerSyncAssetsPricesAction = {
|
|
24
|
+
type: `AssetsController:syncAssetsPrices`;
|
|
25
|
+
handler: AssetsController['syncAssetsPrices'];
|
|
26
|
+
};
|
|
10
27
|
export type AssetsControllerGetAssetsBalanceAction = {
|
|
11
28
|
type: `AssetsController:getAssetsBalance`;
|
|
12
29
|
handler: AssetsController['getAssetsBalance'];
|
|
@@ -181,5 +198,5 @@ export type AssetsControllerSetSelectedCurrencyAction = {
|
|
|
181
198
|
/**
|
|
182
199
|
* Union of all AssetsController action types.
|
|
183
200
|
*/
|
|
184
|
-
export type AssetsControllerMethodActions = AssetsControllerGetAssetsAction | AssetsControllerGetAssetsBalanceAction | AssetsControllerGetAssetMetadataAction | AssetsControllerGetAccountAssetByIDAction | AssetsControllerGetAccountAssetsByIDsAction | AssetsControllerGetAccountAssetsByScopeAction | AssetsControllerGetAssetsPriceAction | AssetsControllerGetExchangeRatesForBridgeAction | AssetsControllerGetStateForTransactionPayAction | AssetsControllerAddCustomAssetAction | AssetsControllerRemoveCustomAssetAction | AssetsControllerGetCustomAssetsAction | AssetsControllerHideAssetAction | AssetsControllerUnhideAssetAction | AssetsControllerSetSelectedCurrencyAction;
|
|
201
|
+
export type AssetsControllerMethodActions = AssetsControllerGetAssetsAction | AssetsControllerSyncAssetsPricesAction | AssetsControllerGetAssetsBalanceAction | AssetsControllerGetAssetMetadataAction | AssetsControllerGetAccountAssetByIDAction | AssetsControllerGetAccountAssetsByIDsAction | AssetsControllerGetAccountAssetsByScopeAction | AssetsControllerGetAssetsPriceAction | AssetsControllerGetExchangeRatesForBridgeAction | AssetsControllerGetStateForTransactionPayAction | AssetsControllerAddCustomAssetAction | AssetsControllerRemoveCustomAssetAction | AssetsControllerGetCustomAssetsAction | AssetsControllerHideAssetAction | AssetsControllerUnhideAssetAction | AssetsControllerSetSelectedCurrencyAction;
|
|
185
202
|
//# sourceMappingURL=AssetsController-method-action-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetsController-method-action-types.d.ts","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;CAC/C,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,yCAAyC,GAAG;IACtD,IAAI,EAAE,sCAAsC,CAAC;IAC7C,OAAO,EAAE,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;CAClD,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,gBAAgB,CAAC,uBAAuB,CAAC,CAAC;CACpD,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,MA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C;IACrC,OAAO,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,yCAAyC,GAAG;IACtD,IAAI,EAAE,sCAAsC,CAAC;IAC7C,OAAO,EAAE,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;CAClD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACrC,+BAA+B,GAC/B,sCAAsC,GACtC,sCAAsC,GACtC,yCAAyC,GACzC,2CAA2C,GAC3C,6CAA6C,GAC7C,oCAAoC,GACpC,+CAA+C,GAC/C,+CAA+C,GAC/C,oCAAoC,GACpC,uCAAuC,GACvC,qCAAqC,GACrC,+BAA+B,GAC/B,iCAAiC,GACjC,yCAAyC,CAAC"}
|
|
1
|
+
{"version":3,"file":"AssetsController-method-action-types.d.ts","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;CACxC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;CAC/C,CAAC;AAEF;;;;;;;;;;;;;;;;;GAi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AAG;IAClD,IAAI,EAAE,kCAAkC,CAAC;IACzC,OAAO,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;CAC9C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;CACxC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,yCAAyC,GAAG;IACtD,IAAI,EAAE,sCAAsC,CAAC;IAC7C,OAAO,EAAE,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;CAClD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACrC,+BAA+B,GAC/B,sCAAsC,GACtC,sCAAsC,GACtC,sCAAsC,GACtC,yCAAyC,GACzC,2CAA2C,GAC3C,6CAA6C,GAC7C,oCAAoC,GACpC,+CAA+C,GAC/C,+CAA+C,GAC/C,oCAAoC,GACpC,uCAAuC,GACvC,qCAAqC,GACrC,+BAA+B,GAC/B,iCAAiC,GACjC,yCAAyC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetsController-method-action-types.js","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { AssetsController } from './AssetsController.js';\n\nexport type AssetsControllerGetAssetsAction = {\n type: `AssetsController:getAssets`;\n handler: AssetsController['getAssets'];\n};\n\nexport type AssetsControllerGetAssetsBalanceAction = {\n type: `AssetsController:getAssetsBalance`;\n handler: AssetsController['getAssetsBalance'];\n};\n\nexport type AssetsControllerGetAssetMetadataAction = {\n type: `AssetsController:getAssetMetadata`;\n handler: AssetsController['getAssetMetadata'];\n};\n\n/**\n * Get a single combined asset (balance + metadata + price + computed\n * `fiatValue`) for an account directly from controller state.\n *\n * Reuses the same state-composition and filtering logic as `getAssets`\n * (balance and metadata are required, a missing price falls back to\n * `{ price: 0, lastUpdated: 0 }` with `fiatValue: 0`, and hidden or\n * otherwise filtered assets are excluded) so the returned shape never\n * drifts from `getAssets`. Reads from current state only and does not\n * trigger a data-source refresh.\n *\n * @param accountId - The account ID (`InternalAccount.id`, not an address).\n * @param assetId - The CAIP-19 asset ID including chain scope\n * (e.g. `eip155:1/erc20:0x...`).\n * @returns The combined `Asset`, or `undefined` when no complete\n * renderable asset (balance + metadata) exists for the account/asset pair.\n * @throws If `accountId` is empty or `assetId` is not a valid CAIP-19 asset ID.\n */\nexport type AssetsControllerGetAccountAssetByIDAction = {\n type: `AssetsController:getAccountAssetByID`;\n handler: AssetsController['getAccountAssetByID'];\n};\n\n/**\n * Get multiple combined assets (balance + metadata + price + computed\n * `fiatValue`) for an account directly from controller state.\n *\n * Applies the same state-composition and filtering rules as\n * `getAccountAssetByID` to each requested asset ID. Asset IDs that do not\n * resolve to a complete renderable asset (missing balance/metadata, hidden,\n * or otherwise filtered out) are omitted from the result. Reads from\n * current state only and does not trigger a data-source refresh.\n *\n * @param accountId - The account ID (`InternalAccount.id`, not an address).\n * @param assetIds - The CAIP-19 asset IDs including chain scope\n * (e.g. `eip155:1/erc20:0x...`).\n * @returns A record of combined `Asset`s keyed by normalized CAIP-19 asset\n * ID, containing only the requested assets that resolved.\n * @throws If `accountId` is empty or any `assetIds` entry is not a valid\n * CAIP-19 asset ID.\n */\nexport type AssetsControllerGetAccountAssetsByIDsAction = {\n type: `AssetsController:getAccountAssetsByIDs`;\n handler: AssetsController['getAccountAssetsByIDs'];\n};\n\n/**\n * Get all combined assets (balance + metadata + price + computed\n * `fiatValue`) an account holds on a given chain scope, directly from\n * controller state.\n *\n * Applies the same state-composition and filtering rules as\n * `getAccountAssetByID` (hidden or otherwise filtered assets are excluded).\n * Reads from current state only and does not trigger a data-source refresh.\n *\n * @param accountId - The account ID (`InternalAccount.id`, not an address).\n * @param scope - The CAIP-2 chain ID to filter by (e.g. `eip155:1`).\n * @returns A record of combined `Asset`s keyed by CAIP-19 asset ID,\n * containing only the account's assets on the given scope.\n * @throws If `accountId` is empty or `scope` is not a valid CAIP-2 chain ID.\n */\nexport type AssetsControllerGetAccountAssetsByScopeAction = {\n type: `AssetsController:getAccountAssetsByScope`;\n handler: AssetsController['getAccountAssetsByScope'];\n};\n\nexport type AssetsControllerGetAssetsPriceAction = {\n type: `AssetsController:getAssetsPrice`;\n handler: AssetsController['getAssetsPrice'];\n};\n\n/**\n * Returns exchange rates in the format expected by the bridge controller\n * (conversionRates, currencyRates, marketData, currentCurrency) so that\n * when useAssetsControllerForRates is true the bridge can use a single\n * action instead of MultichainAssetsRatesController, TokenRatesController,\n * and CurrencyRateController.\n *\n * @returns Bridge-compatible exchange rate state derived from assetsPrice and selectedCurrency.\n */\nexport type AssetsControllerGetExchangeRatesForBridgeAction = {\n type: `AssetsController:getExchangeRatesForBridge`;\n handler: AssetsController['getExchangeRatesForBridge'];\n};\n\n/**\n * Returns state in the legacy format expected by transaction-pay-controller\n * (TokenBalancesController, AccountTrackerController, TokensController,\n * TokenRatesController, CurrencyRateController shapes) so that when\n * useAssetsController is true the transaction-pay-controller can use a\n * single action instead of five separate getState calls.\n *\n * @returns Legacy-compatible state for transaction-pay-controller.\n */\nexport type AssetsControllerGetStateForTransactionPayAction = {\n type: `AssetsController:getStateForTransactionPay`;\n handler: AssetsController['getStateForTransactionPay'];\n};\n\n/**\n * Add a custom asset for an account.\n * Custom assets are included in subscription and fetch operations.\n * Adding a custom asset also unhides it if it was previously hidden,\n * and force-fetches that asset's chain (including every visible pin).\n *\n * When `pendingMetadata` is provided (e.g. from the extension's pending-tokens\n * flow), the token metadata is persisted immediately into `assetsInfo` so the\n * UI can render it without waiting for the next pipeline fetch.\n *\n * @param accountId - The account ID to add the custom asset for.\n * @param assetId - The CAIP-19 asset ID to add.\n * @param pendingMetadata - Optional token metadata from the UI (pendingTokens format).\n */\nexport type AssetsControllerAddCustomAssetAction = {\n type: `AssetsController:addCustomAsset`;\n handler: AssetsController['addCustomAsset'];\n};\n\n/**\n * Remove a custom asset from an account.\n *\n * @param accountId - The account ID to remove the custom asset from.\n * @param assetId - The CAIP-19 asset ID to remove.\n */\nexport type AssetsControllerRemoveCustomAssetAction = {\n type: `AssetsController:removeCustomAsset`;\n handler: AssetsController['removeCustomAsset'];\n};\n\n/**\n * Get all custom assets for an account.\n *\n * @param accountId - The account ID to get custom assets for.\n * @returns Array of CAIP-19 asset IDs for the account's custom assets.\n */\nexport type AssetsControllerGetCustomAssetsAction = {\n type: `AssetsController:getCustomAssets`;\n handler: AssetsController['getCustomAssets'];\n};\n\n/**\n * Hide an asset globally.\n * Hidden assets are excluded from the asset list returned by getAssets.\n * The hidden state is stored in assetPreferences.\n *\n * @param assetId - The CAIP-19 asset ID to hide.\n */\nexport type AssetsControllerHideAssetAction = {\n type: `AssetsController:hideAsset`;\n handler: AssetsController['hideAsset'];\n};\n\n/**\n * Unhide an asset globally.\n * Force-fetches that asset's chain (including every visible pin) so a\n * `full` snapshot can restore the balance immediately, then re-evaluates\n * subscriptions so later polls stop excluding it.\n *\n * @param assetId - The CAIP-19 asset ID to unhide.\n */\nexport type AssetsControllerUnhideAssetAction = {\n type: `AssetsController:unhideAsset`;\n handler: AssetsController['unhideAsset'];\n};\n\n/**\n * Set the current currency.\n *\n * @param selectedCurrency - The ISO 4217 currency code to set.\n */\nexport type AssetsControllerSetSelectedCurrencyAction = {\n type: `AssetsController:setSelectedCurrency`;\n handler: AssetsController['setSelectedCurrency'];\n};\n\n/**\n * Union of all AssetsController action types.\n */\nexport type AssetsControllerMethodActions =\n | AssetsControllerGetAssetsAction\n | AssetsControllerGetAssetsBalanceAction\n | AssetsControllerGetAssetMetadataAction\n | AssetsControllerGetAccountAssetByIDAction\n | AssetsControllerGetAccountAssetsByIDsAction\n | AssetsControllerGetAccountAssetsByScopeAction\n | AssetsControllerGetAssetsPriceAction\n | AssetsControllerGetExchangeRatesForBridgeAction\n | AssetsControllerGetStateForTransactionPayAction\n | AssetsControllerAddCustomAssetAction\n | AssetsControllerRemoveCustomAssetAction\n | AssetsControllerGetCustomAssetsAction\n | AssetsControllerHideAssetAction\n | AssetsControllerUnhideAssetAction\n | AssetsControllerSetSelectedCurrencyAction;\n"]}
|
|
1
|
+
{"version":3,"file":"AssetsController-method-action-types.js","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { AssetsController } from './AssetsController.js';\n\nexport type AssetsControllerGetAssetsAction = {\n type: `AssetsController:getAssets`;\n handler: AssetsController['getAssets'];\n};\n\n/**\n * Force-fetch spot prices for an explicit asset list.\n *\n * Calls `PriceDataSource` directly and merges the result into `assetsPrice`.\n * Prices are shared across accounts, so this does not take an account or\n * chain scope and does not run the balance pipeline.\n *\n * Returns without calling the Price API when basic functionality is off.\n * That matches the asset pipeline, which drops the price source in RPC-only\n * mode, and `setSelectedCurrency`, which skips its price refresh.\n *\n * @param assetIds - CAIP-19 asset IDs to sync.\n */\nexport type AssetsControllerSyncAssetsPricesAction = {\n type: `AssetsController:syncAssetsPrices`;\n handler: AssetsController['syncAssetsPrices'];\n};\n\nexport type AssetsControllerGetAssetsBalanceAction = {\n type: `AssetsController:getAssetsBalance`;\n handler: AssetsController['getAssetsBalance'];\n};\n\nexport type AssetsControllerGetAssetMetadataAction = {\n type: `AssetsController:getAssetMetadata`;\n handler: AssetsController['getAssetMetadata'];\n};\n\n/**\n * Get a single combined asset (balance + metadata + price + computed\n * `fiatValue`) for an account directly from controller state.\n *\n * Reuses the same state-composition and filtering logic as `getAssets`\n * (balance and metadata are required, a missing price falls back to\n * `{ price: 0, lastUpdated: 0 }` with `fiatValue: 0`, and hidden or\n * otherwise filtered assets are excluded) so the returned shape never\n * drifts from `getAssets`. Reads from current state only and does not\n * trigger a data-source refresh.\n *\n * @param accountId - The account ID (`InternalAccount.id`, not an address).\n * @param assetId - The CAIP-19 asset ID including chain scope\n * (e.g. `eip155:1/erc20:0x...`).\n * @returns The combined `Asset`, or `undefined` when no complete\n * renderable asset (balance + metadata) exists for the account/asset pair.\n * @throws If `accountId` is empty or `assetId` is not a valid CAIP-19 asset ID.\n */\nexport type AssetsControllerGetAccountAssetByIDAction = {\n type: `AssetsController:getAccountAssetByID`;\n handler: AssetsController['getAccountAssetByID'];\n};\n\n/**\n * Get multiple combined assets (balance + metadata + price + computed\n * `fiatValue`) for an account directly from controller state.\n *\n * Applies the same state-composition and filtering rules as\n * `getAccountAssetByID` to each requested asset ID. Asset IDs that do not\n * resolve to a complete renderable asset (missing balance/metadata, hidden,\n * or otherwise filtered out) are omitted from the result. Reads from\n * current state only and does not trigger a data-source refresh.\n *\n * @param accountId - The account ID (`InternalAccount.id`, not an address).\n * @param assetIds - The CAIP-19 asset IDs including chain scope\n * (e.g. `eip155:1/erc20:0x...`).\n * @returns A record of combined `Asset`s keyed by normalized CAIP-19 asset\n * ID, containing only the requested assets that resolved.\n * @throws If `accountId` is empty or any `assetIds` entry is not a valid\n * CAIP-19 asset ID.\n */\nexport type AssetsControllerGetAccountAssetsByIDsAction = {\n type: `AssetsController:getAccountAssetsByIDs`;\n handler: AssetsController['getAccountAssetsByIDs'];\n};\n\n/**\n * Get all combined assets (balance + metadata + price + computed\n * `fiatValue`) an account holds on a given chain scope, directly from\n * controller state.\n *\n * Applies the same state-composition and filtering rules as\n * `getAccountAssetByID` (hidden or otherwise filtered assets are excluded).\n * Reads from current state only and does not trigger a data-source refresh.\n *\n * @param accountId - The account ID (`InternalAccount.id`, not an address).\n * @param scope - The CAIP-2 chain ID to filter by (e.g. `eip155:1`).\n * @returns A record of combined `Asset`s keyed by CAIP-19 asset ID,\n * containing only the account's assets on the given scope.\n * @throws If `accountId` is empty or `scope` is not a valid CAIP-2 chain ID.\n */\nexport type AssetsControllerGetAccountAssetsByScopeAction = {\n type: `AssetsController:getAccountAssetsByScope`;\n handler: AssetsController['getAccountAssetsByScope'];\n};\n\nexport type AssetsControllerGetAssetsPriceAction = {\n type: `AssetsController:getAssetsPrice`;\n handler: AssetsController['getAssetsPrice'];\n};\n\n/**\n * Returns exchange rates in the format expected by the bridge controller\n * (conversionRates, currencyRates, marketData, currentCurrency) so that\n * when useAssetsControllerForRates is true the bridge can use a single\n * action instead of MultichainAssetsRatesController, TokenRatesController,\n * and CurrencyRateController.\n *\n * @returns Bridge-compatible exchange rate state derived from assetsPrice and selectedCurrency.\n */\nexport type AssetsControllerGetExchangeRatesForBridgeAction = {\n type: `AssetsController:getExchangeRatesForBridge`;\n handler: AssetsController['getExchangeRatesForBridge'];\n};\n\n/**\n * Returns state in the legacy format expected by transaction-pay-controller\n * (TokenBalancesController, AccountTrackerController, TokensController,\n * TokenRatesController, CurrencyRateController shapes) so that when\n * useAssetsController is true the transaction-pay-controller can use a\n * single action instead of five separate getState calls.\n *\n * @returns Legacy-compatible state for transaction-pay-controller.\n */\nexport type AssetsControllerGetStateForTransactionPayAction = {\n type: `AssetsController:getStateForTransactionPay`;\n handler: AssetsController['getStateForTransactionPay'];\n};\n\n/**\n * Add a custom asset for an account.\n * Custom assets are included in subscription and fetch operations.\n * Adding a custom asset also unhides it if it was previously hidden,\n * and force-fetches that asset's chain (including every visible pin).\n *\n * When `pendingMetadata` is provided (e.g. from the extension's pending-tokens\n * flow), the token metadata is persisted immediately into `assetsInfo` so the\n * UI can render it without waiting for the next pipeline fetch.\n *\n * @param accountId - The account ID to add the custom asset for.\n * @param assetId - The CAIP-19 asset ID to add.\n * @param pendingMetadata - Optional token metadata from the UI (pendingTokens format).\n */\nexport type AssetsControllerAddCustomAssetAction = {\n type: `AssetsController:addCustomAsset`;\n handler: AssetsController['addCustomAsset'];\n};\n\n/**\n * Remove a custom asset from an account.\n *\n * @param accountId - The account ID to remove the custom asset from.\n * @param assetId - The CAIP-19 asset ID to remove.\n */\nexport type AssetsControllerRemoveCustomAssetAction = {\n type: `AssetsController:removeCustomAsset`;\n handler: AssetsController['removeCustomAsset'];\n};\n\n/**\n * Get all custom assets for an account.\n *\n * @param accountId - The account ID to get custom assets for.\n * @returns Array of CAIP-19 asset IDs for the account's custom assets.\n */\nexport type AssetsControllerGetCustomAssetsAction = {\n type: `AssetsController:getCustomAssets`;\n handler: AssetsController['getCustomAssets'];\n};\n\n/**\n * Hide an asset globally.\n * Hidden assets are excluded from the asset list returned by getAssets.\n * The hidden state is stored in assetPreferences.\n *\n * @param assetId - The CAIP-19 asset ID to hide.\n */\nexport type AssetsControllerHideAssetAction = {\n type: `AssetsController:hideAsset`;\n handler: AssetsController['hideAsset'];\n};\n\n/**\n * Unhide an asset globally.\n * Force-fetches that asset's chain (including every visible pin) so a\n * `full` snapshot can restore the balance immediately, then re-evaluates\n * subscriptions so later polls stop excluding it.\n *\n * @param assetId - The CAIP-19 asset ID to unhide.\n */\nexport type AssetsControllerUnhideAssetAction = {\n type: `AssetsController:unhideAsset`;\n handler: AssetsController['unhideAsset'];\n};\n\n/**\n * Set the current currency.\n *\n * @param selectedCurrency - The ISO 4217 currency code to set.\n */\nexport type AssetsControllerSetSelectedCurrencyAction = {\n type: `AssetsController:setSelectedCurrency`;\n handler: AssetsController['setSelectedCurrency'];\n};\n\n/**\n * Union of all AssetsController action types.\n */\nexport type AssetsControllerMethodActions =\n | AssetsControllerGetAssetsAction\n | AssetsControllerSyncAssetsPricesAction\n | AssetsControllerGetAssetsBalanceAction\n | AssetsControllerGetAssetMetadataAction\n | AssetsControllerGetAccountAssetByIDAction\n | AssetsControllerGetAccountAssetsByIDsAction\n | AssetsControllerGetAccountAssetsByScopeAction\n | AssetsControllerGetAssetsPriceAction\n | AssetsControllerGetExchangeRatesForBridgeAction\n | AssetsControllerGetStateForTransactionPayAction\n | AssetsControllerAddCustomAssetAction\n | AssetsControllerRemoveCustomAssetAction\n | AssetsControllerGetCustomAssetsAction\n | AssetsControllerHideAssetAction\n | AssetsControllerUnhideAssetAction\n | AssetsControllerSetSelectedCurrencyAction;\n"]}
|
|
@@ -72,14 +72,7 @@ export type AssetsControllerPriceChangedEvent = {
|
|
|
72
72
|
prices: Record<Caip19AssetId, AssetPrice>;
|
|
73
73
|
}];
|
|
74
74
|
};
|
|
75
|
-
export type
|
|
76
|
-
type: `${typeof CONTROLLER_NAME}:assetsDetected`;
|
|
77
|
-
payload: [{
|
|
78
|
-
accountId: AccountId;
|
|
79
|
-
assetIds: Caip19AssetId[];
|
|
80
|
-
}];
|
|
81
|
-
};
|
|
82
|
-
export type AssetsControllerEvents = AssetsControllerStateChangeEvent | AssetsControllerBalanceChangedEvent | AssetsControllerPriceChangedEvent | AssetsControllerAssetsDetectedEvent;
|
|
75
|
+
export type AssetsControllerEvents = AssetsControllerStateChangeEvent | AssetsControllerBalanceChangedEvent | AssetsControllerPriceChangedEvent;
|
|
83
76
|
type AllowedActions = AccountsControllerGetSelectedAccountAction | AccountTreeControllerGetAccountsFromSelectedAccountGroupAction | AccountTreeControllerIsInitializedAction | ClientControllerGetStateAction | KeyringControllerIsUnlockedAction | NetworkControllerGetStateAction | NetworkControllerGetNetworkClientByIdAction | ConfigRegistryControllerGetNetworkConfigByCaip2ChainIdAction | NetworkEnablementControllerGetStateAction | SnapControllerGetRunnableSnapsAction | SnapControllerHandleRequestAction | GetPermissions | PhishingControllerBulkScanTokensAction | RemoteFeatureFlagControllerGetStateAction;
|
|
84
77
|
type AllowedEvents = AccountTreeControllerSelectedAccountGroupChangeEvent | AccountTreeControllerInitializedEvent | AccountTreeControllerUninitializedEvent | ClientControllerStateChangeEvent | KeyringControllerLockEvent | KeyringControllerUnlockEvent | PreferencesControllerStateChangeEvent | TransactionControllerUnapprovedTransactionAddedEvent | TransactionControllerTransactionConfirmedEvent | MultichainTransactionsControllerTransactionConfirmedEvent | NetworkControllerStateChangeEvent | NetworkControllerNetworkAddedEvent | NetworkControllerNetworkDidChangeEvent | NetworkControllerNetworkRemovedEvent | NetworkEnablementControllerEvents | AccountsControllerAccountBalancesUpdatedEvent | PermissionControllerStateChange | SnapControllerSnapInstalledEvent | AccountActivityServiceBalanceUpdatedEvent | AccountActivityServiceStatusChangedEvent | RemoteFeatureFlagControllerStateChangeEvent;
|
|
85
78
|
export type AssetsControllerMessenger = Messenger<typeof CONTROLLER_NAME, AssetsControllerActions | AllowedActions, AssetsControllerEvents | AllowedEvents>;
|
|
@@ -195,9 +188,21 @@ export declare class AssetsController extends BaseController<typeof CONTROLLER_N
|
|
|
195
188
|
*/
|
|
196
189
|
bypassServerCache?: boolean;
|
|
197
190
|
dataTypes?: DataType[];
|
|
198
|
-
/** Specific CAIP-19 asset IDs whose prices should be refreshed. */
|
|
199
|
-
assetsForPriceUpdate?: Caip19AssetId[];
|
|
200
191
|
}): Promise<Record<AccountId, Record<Caip19AssetId, Asset>>>;
|
|
192
|
+
/**
|
|
193
|
+
* Force-fetch spot prices for an explicit asset list.
|
|
194
|
+
*
|
|
195
|
+
* Calls `PriceDataSource` directly and merges the result into `assetsPrice`.
|
|
196
|
+
* Prices are shared across accounts, so this does not take an account or
|
|
197
|
+
* chain scope and does not run the balance pipeline.
|
|
198
|
+
*
|
|
199
|
+
* Returns without calling the Price API when basic functionality is off.
|
|
200
|
+
* That matches the asset pipeline, which drops the price source in RPC-only
|
|
201
|
+
* mode, and `setSelectedCurrency`, which skips its price refresh.
|
|
202
|
+
*
|
|
203
|
+
* @param assetIds - CAIP-19 asset IDs to sync.
|
|
204
|
+
*/
|
|
205
|
+
syncAssetsPrices(assetIds: Caip19AssetId[]): Promise<void>;
|
|
201
206
|
getAssetsBalance(accounts: InternalAccount[], options?: {
|
|
202
207
|
chainIds?: ChainId[];
|
|
203
208
|
assetTypes?: AssetType[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetsController.d.ts","sourceRoot":"","sources":["../src/Ass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;;;;;OASG;IACG,kBAAkB,CACtB,QAAQ,EAAE,YAAY,EACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,IAAI,CAAC,CAYf;IAsMD,OAAO,IAAI,IAAI,CAoDd;CACF"}
|
package/dist/AssetsController.js
CHANGED
|
@@ -42,7 +42,7 @@ import { AccountActivityDataSource } from './data-sources/AccountActivityDataSou
|
|
|
42
42
|
import { AccountsApiDataSource } from './data-sources/AccountsApiDataSource.js';
|
|
43
43
|
import { isStakingContractAssetId } from './data-sources/evm-rpc-services/index.js';
|
|
44
44
|
import { shouldSkipNativeForCaipChainId } from './data-sources/evm-rpc-services/utils/assets.js';
|
|
45
|
-
import {
|
|
45
|
+
import { PriceDataSource } from './data-sources/PriceDataSource.js';
|
|
46
46
|
import { RpcDataSource } from './data-sources/RpcDataSource.js';
|
|
47
47
|
import { SnapDataSource } from './data-sources/SnapDataSource.js';
|
|
48
48
|
import { StakedBalanceDataSource } from './data-sources/StakedBalanceDataSource.js';
|
|
@@ -50,7 +50,6 @@ import { CaipAssetNamespace, TokenDataSource, } from './data-sources/TokenDataSo
|
|
|
50
50
|
import { CHAINS_WITH_DEFAULT_TRACKED_ASSETS, DEFAULT_TRACKED_ASSETS_BY_CHAIN, buildDefaultAssetsInfo, getDefaultAssetMetadata, } from './defaults.js';
|
|
51
51
|
import { projectLogger, createModuleLogger } from './logger.js';
|
|
52
52
|
import { CustomAssetGraduationMiddleware } from './middlewares/CustomAssetGraduationMiddleware.js';
|
|
53
|
-
import { DetectionMiddleware } from './middlewares/DetectionMiddleware.js';
|
|
54
53
|
import { createParallelBalanceMiddleware, createParallelMiddleware, } from './middlewares/ParallelMiddleware.js';
|
|
55
54
|
import { RpcFallbackMiddleware } from './middlewares/RpcFallbackMiddleware.js';
|
|
56
55
|
import { dropBalancesOutsideAccountScopes } from './migrations/dropBalancesOutsideAccountScopes.js';
|
|
@@ -78,6 +77,7 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
78
77
|
'getAccountAssetsByIDs',
|
|
79
78
|
'getAccountAssetsByScope',
|
|
80
79
|
'getAssetsPrice',
|
|
80
|
+
'syncAssetsPrices',
|
|
81
81
|
'getExchangeRatesForBridge',
|
|
82
82
|
'getStateForTransactionPay',
|
|
83
83
|
'addCustomAsset',
|
|
@@ -213,13 +213,6 @@ function normalizeResponse(response) {
|
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
|
-
// Preserve detectedAssets with normalized asset IDs
|
|
217
|
-
if (response.detectedAssets) {
|
|
218
|
-
normalized.detectedAssets = {};
|
|
219
|
-
for (const [accountId, assetIds] of Object.entries(response.detectedAssets)) {
|
|
220
|
-
normalized.detectedAssets[accountId] = assetIds.map((assetId) => normalizeAssetId(assetId));
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
216
|
// Preserve errors (chain IDs don't need normalization)
|
|
224
217
|
if (response.errors) {
|
|
225
218
|
normalized.errors = { ...response.errors };
|
|
@@ -498,7 +491,6 @@ let AssetsController = (() => {
|
|
|
498
491
|
];
|
|
499
492
|
}
|
|
500
493
|
#priceDataSource;
|
|
501
|
-
#detectionMiddleware;
|
|
502
494
|
#customAssetGraduationMiddleware;
|
|
503
495
|
#rpcFallbackMiddleware;
|
|
504
496
|
#tokenDataSource;
|
|
@@ -596,9 +588,6 @@ let AssetsController = (() => {
|
|
|
596
588
|
getAssetsState: () => this.state,
|
|
597
589
|
...priceDataSourceConfig,
|
|
598
590
|
});
|
|
599
|
-
this.#detectionMiddleware = new DetectionMiddleware({
|
|
600
|
-
getAssetsState: () => this.state,
|
|
601
|
-
});
|
|
602
591
|
this.#customAssetGraduationMiddleware = new CustomAssetGraduationMiddleware({
|
|
603
592
|
getSelectedAccountId: () => {
|
|
604
593
|
try {
|
|
@@ -935,14 +924,12 @@ let AssetsController = (() => {
|
|
|
935
924
|
this.#ensureDefaultTrackedAssetsSeeded();
|
|
936
925
|
// Balances were just force-fetched — skip AccountsApi's subscribe-time poll.
|
|
937
926
|
this.#subscribeAssets({ skipInitialFetch: true });
|
|
938
|
-
this.#fetchMissingPricesWithoutCache(accounts, [...this.#enabledChains]);
|
|
939
927
|
}
|
|
940
928
|
catch (error) {
|
|
941
929
|
log('Failed to fetch assets on startup', error);
|
|
942
930
|
this.#ensureNativeBalancesDefaultZero();
|
|
943
931
|
this.#ensureDefaultTrackedAssetsSeeded();
|
|
944
932
|
this.#subscribeAssets({ skipInitialFetch: true });
|
|
945
|
-
this.#fetchMissingPricesWithoutCache(accounts, [...this.#enabledChains]);
|
|
946
933
|
}
|
|
947
934
|
finally {
|
|
948
935
|
releaseLock();
|
|
@@ -1029,36 +1016,74 @@ let AssetsController = (() => {
|
|
|
1029
1016
|
return this.#getAssetsFromState(accounts, chainIds, assetTypes);
|
|
1030
1017
|
}
|
|
1031
1018
|
if (options?.forceUpdate) {
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
};
|
|
1042
|
-
if (this.#isBalanceV6Enabled()) {
|
|
1043
|
-
await this.#forceUpdateAssetsV6({
|
|
1044
|
-
accounts,
|
|
1045
|
-
chainIds,
|
|
1046
|
-
request: this.#buildDataRequest(accounts, chainIds, requestOptions),
|
|
1047
|
-
pipelineTrace,
|
|
1048
|
-
});
|
|
1049
|
-
}
|
|
1050
|
-
else {
|
|
1051
|
-
await this.#forceUpdateAssetsV5({
|
|
1052
|
-
accounts,
|
|
1053
|
-
chainIds,
|
|
1054
|
-
request: this.#buildForceUpdateRequestV5(accounts, chainIds, requestOptions),
|
|
1055
|
-
pipelineTrace,
|
|
1056
|
-
});
|
|
1057
|
-
}
|
|
1019
|
+
await this.#forceUpdateAssets({
|
|
1020
|
+
accounts,
|
|
1021
|
+
chainIds,
|
|
1022
|
+
requestOptions: {
|
|
1023
|
+
assetTypes,
|
|
1024
|
+
dataTypes,
|
|
1025
|
+
forceUpdate: true,
|
|
1026
|
+
bypassServerCache: options.bypassServerCache,
|
|
1027
|
+
},
|
|
1028
|
+
});
|
|
1058
1029
|
}
|
|
1059
1030
|
const result = this.#getAssetsFromState(accounts, chainIds, assetTypes);
|
|
1060
1031
|
return result;
|
|
1061
1032
|
}
|
|
1033
|
+
/**
|
|
1034
|
+
* Force-fetch spot prices for an explicit asset list.
|
|
1035
|
+
*
|
|
1036
|
+
* Calls `PriceDataSource` directly and merges the result into `assetsPrice`.
|
|
1037
|
+
* Prices are shared across accounts, so this does not take an account or
|
|
1038
|
+
* chain scope and does not run the balance pipeline.
|
|
1039
|
+
*
|
|
1040
|
+
* Returns without calling the Price API when basic functionality is off.
|
|
1041
|
+
* That matches the asset pipeline, which drops the price source in RPC-only
|
|
1042
|
+
* mode, and `setSelectedCurrency`, which skips its price refresh.
|
|
1043
|
+
*
|
|
1044
|
+
* @param assetIds - CAIP-19 asset IDs to sync.
|
|
1045
|
+
*/
|
|
1046
|
+
async syncAssetsPrices(assetIds) {
|
|
1047
|
+
if (!this.#isBasicFunctionality() || assetIds.length === 0) {
|
|
1048
|
+
return;
|
|
1049
|
+
}
|
|
1050
|
+
const assetsPrice = await this.#priceDataSource.fetchAssetPrices(assetIds);
|
|
1051
|
+
if (Object.keys(assetsPrice).length === 0) {
|
|
1052
|
+
return;
|
|
1053
|
+
}
|
|
1054
|
+
await this.#updateState({
|
|
1055
|
+
assetsPrice,
|
|
1056
|
+
updateMode: 'merge',
|
|
1057
|
+
});
|
|
1058
|
+
}
|
|
1059
|
+
/**
|
|
1060
|
+
* Run a forced fetch on the v5 or v6 pipeline.
|
|
1061
|
+
*
|
|
1062
|
+
* @param params - Accounts, chains, and request fields for this fetch.
|
|
1063
|
+
* @param params.accounts - Accounts in this fetch.
|
|
1064
|
+
* @param params.chainIds - Chains in this fetch.
|
|
1065
|
+
* @param params.requestOptions - Shared force-update request fields.
|
|
1066
|
+
*/
|
|
1067
|
+
async #forceUpdateAssets({ accounts, chainIds, requestOptions, }) {
|
|
1068
|
+
const pipelineTrace = this.#firstInitFetchReported
|
|
1069
|
+
? undefined
|
|
1070
|
+
: this.#trace;
|
|
1071
|
+
if (this.#isBalanceV6Enabled()) {
|
|
1072
|
+
await this.#forceUpdateAssetsV6({
|
|
1073
|
+
accounts,
|
|
1074
|
+
chainIds,
|
|
1075
|
+
request: this.#buildDataRequest(accounts, chainIds, requestOptions),
|
|
1076
|
+
pipelineTrace,
|
|
1077
|
+
});
|
|
1078
|
+
return;
|
|
1079
|
+
}
|
|
1080
|
+
await this.#forceUpdateAssetsV5({
|
|
1081
|
+
accounts,
|
|
1082
|
+
chainIds,
|
|
1083
|
+
request: this.#buildForceUpdateRequestV5(accounts, chainIds, requestOptions),
|
|
1084
|
+
pipelineTrace,
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1062
1087
|
/**
|
|
1063
1088
|
* v5 force-update request: every pin of the requested accounts, unscoped.
|
|
1064
1089
|
* Delete with the rest of the v5 path when `assetsAccountsApiV6` is the default.
|
|
@@ -1070,7 +1095,6 @@ let AssetsController = (() => {
|
|
|
1070
1095
|
* @param requestOptions.dataTypes - Data types to fetch.
|
|
1071
1096
|
* @param requestOptions.forceUpdate - Always `true` to bypass caches.
|
|
1072
1097
|
* @param requestOptions.bypassServerCache - Also bypass server-side HTTP caches.
|
|
1073
|
-
* @param requestOptions.assetsForPriceUpdate - Assets to refresh prices for.
|
|
1074
1098
|
* @returns The v5 data request.
|
|
1075
1099
|
*/
|
|
1076
1100
|
#buildForceUpdateRequestV5(accounts, chainIds, requestOptions) {
|
|
@@ -1089,7 +1113,6 @@ let AssetsController = (() => {
|
|
|
1089
1113
|
accountsApiDataSource: this.#accountsApiDataSource,
|
|
1090
1114
|
customAssetGraduationMiddleware: this.#customAssetGraduationMiddleware,
|
|
1091
1115
|
rpcFallbackMiddleware: this.#rpcFallbackMiddleware,
|
|
1092
|
-
detectionMiddleware: this.#detectionMiddleware,
|
|
1093
1116
|
tokenDataSource: this.#tokenDataSource,
|
|
1094
1117
|
priceDataSource: this.#priceDataSource,
|
|
1095
1118
|
}, { isBasicFunctionality, includeCustomAssetGraduation: true });
|
|
@@ -1116,7 +1139,6 @@ let AssetsController = (() => {
|
|
|
1116
1139
|
accountsApiDataSource: this.#accountsApiDataSource,
|
|
1117
1140
|
customAssetGraduationMiddleware: this.#customAssetGraduationMiddleware,
|
|
1118
1141
|
rpcFallbackMiddleware: this.#rpcFallbackMiddleware,
|
|
1119
|
-
detectionMiddleware: this.#detectionMiddleware,
|
|
1120
1142
|
tokenDataSource: this.#tokenDataSource,
|
|
1121
1143
|
priceDataSource: this.#priceDataSource,
|
|
1122
1144
|
}, {
|
|
@@ -1227,7 +1249,6 @@ let AssetsController = (() => {
|
|
|
1227
1249
|
const { response } = await this.#executeMiddlewares({
|
|
1228
1250
|
sources: [
|
|
1229
1251
|
createParallelBalanceMiddleware(slowSources),
|
|
1230
|
-
this.#detectionMiddleware,
|
|
1231
1252
|
...(isBasicFunctionality
|
|
1232
1253
|
? [
|
|
1233
1254
|
createParallelMiddleware([
|
|
@@ -1683,60 +1704,10 @@ let AssetsController = (() => {
|
|
|
1683
1704
|
}
|
|
1684
1705
|
// Currency changed — old cached prices are in the wrong currency.
|
|
1685
1706
|
this.#priceDataSource.invalidatePriceCache();
|
|
1686
|
-
this.
|
|
1687
|
-
forceUpdate: true,
|
|
1688
|
-
dataTypes: ['price'],
|
|
1689
|
-
assetsForPriceUpdate: Object.values(this.state.assetsBalance).flatMap((balances) => Object.keys(balances)),
|
|
1690
|
-
}).catch((error) => {
|
|
1707
|
+
this.syncAssetsPrices(Object.values(this.state.assetsBalance).flatMap((balances) => Object.keys(balances))).catch((error) => {
|
|
1691
1708
|
log('Failed to fetch asset prices after current currency change', error);
|
|
1692
1709
|
});
|
|
1693
1710
|
}
|
|
1694
|
-
/**
|
|
1695
|
-
* Fetch spot prices (bypassing deduper cache) for held assets that have no
|
|
1696
|
-
* entry in `assetsPrice` yet. Used when switching or adding a network.
|
|
1697
|
-
*
|
|
1698
|
-
* @param accounts - Accounts whose held assets should be priced.
|
|
1699
|
-
* @param chainIds - Chains to scope the check and fetch.
|
|
1700
|
-
*/
|
|
1701
|
-
#fetchMissingPricesWithoutCache(accounts, chainIds) {
|
|
1702
|
-
if (!this.#isBasicFunctionality() || accounts.length === 0) {
|
|
1703
|
-
return;
|
|
1704
|
-
}
|
|
1705
|
-
const accountIds = new Set(accounts.map((account) => account.id));
|
|
1706
|
-
const chainFilter = new Set(chainIds);
|
|
1707
|
-
const assetsForPriceUpdate = [];
|
|
1708
|
-
const prices = this.state.assetsPrice;
|
|
1709
|
-
for (const [accountId, accountBalances] of Object.entries(this.state.assetsBalance)) {
|
|
1710
|
-
if (!accountIds.has(accountId)) {
|
|
1711
|
-
continue;
|
|
1712
|
-
}
|
|
1713
|
-
for (const assetId of Object.keys(accountBalances)) {
|
|
1714
|
-
if (!chainFilter.has(assetId.split('/')[0])) {
|
|
1715
|
-
continue;
|
|
1716
|
-
}
|
|
1717
|
-
const normalizedAssetId = normalizeAssetId(assetId);
|
|
1718
|
-
if (prices[normalizedAssetId] ?? prices[assetId]) {
|
|
1719
|
-
continue;
|
|
1720
|
-
}
|
|
1721
|
-
if (!isPriceableAsset(normalizedAssetId)) {
|
|
1722
|
-
continue;
|
|
1723
|
-
}
|
|
1724
|
-
assetsForPriceUpdate.push(normalizedAssetId);
|
|
1725
|
-
}
|
|
1726
|
-
}
|
|
1727
|
-
if (assetsForPriceUpdate.length === 0) {
|
|
1728
|
-
return;
|
|
1729
|
-
}
|
|
1730
|
-
this.#priceDataSource.invalidatePriceCache();
|
|
1731
|
-
this.getAssets(accounts, {
|
|
1732
|
-
forceUpdate: true,
|
|
1733
|
-
dataTypes: ['price'],
|
|
1734
|
-
chainIds,
|
|
1735
|
-
assetsForPriceUpdate,
|
|
1736
|
-
}).catch((error) => {
|
|
1737
|
-
log('Failed to fetch missing prices', { error });
|
|
1738
|
-
});
|
|
1739
|
-
}
|
|
1740
1711
|
// ============================================================================
|
|
1741
1712
|
// SUBSCRIPTIONS
|
|
1742
1713
|
// ============================================================================
|
|
@@ -2055,8 +2026,6 @@ let AssetsController = (() => {
|
|
|
2055
2026
|
try {
|
|
2056
2027
|
const previousState = this.state;
|
|
2057
2028
|
const previousPrices = { ...this.state.assetsPrice };
|
|
2058
|
-
// Use detectedAssets from response (assets without metadata)
|
|
2059
|
-
const detectedAssets = normalizedResponse.detectedAssets ?? {};
|
|
2060
2029
|
// Track actual changes for logging
|
|
2061
2030
|
const changedBalances = [];
|
|
2062
2031
|
const changedMetadata = [];
|
|
@@ -2226,12 +2195,6 @@ let AssetsController = (() => {
|
|
|
2226
2195
|
changedBalances: changedBalances.length > 0 ? changedBalances : undefined,
|
|
2227
2196
|
changedMetadata: changedMetadata.length > 0 ? changedMetadata : undefined,
|
|
2228
2197
|
changedPrices: changedPriceAssets.length > 0 ? changedPriceAssets : undefined,
|
|
2229
|
-
newAssets: Object.keys(detectedAssets).length > 0
|
|
2230
|
-
? Object.entries(detectedAssets).map(([accountId, assets]) => ({
|
|
2231
|
-
accountId,
|
|
2232
|
-
assets,
|
|
2233
|
-
}))
|
|
2234
|
-
: undefined,
|
|
2235
2198
|
});
|
|
2236
2199
|
}
|
|
2237
2200
|
// Publish balance changed events
|
|
@@ -2257,15 +2220,6 @@ let AssetsController = (() => {
|
|
|
2257
2220
|
prices: changedPrices,
|
|
2258
2221
|
});
|
|
2259
2222
|
}
|
|
2260
|
-
// Publish assets detected events
|
|
2261
|
-
for (const [accountId, assetIds] of Object.entries(detectedAssets)) {
|
|
2262
|
-
if (assetIds.length > 0) {
|
|
2263
|
-
this.messenger.publish('AssetsController:assetsDetected', {
|
|
2264
|
-
accountId,
|
|
2265
|
-
assetIds,
|
|
2266
|
-
});
|
|
2267
|
-
}
|
|
2268
|
-
}
|
|
2269
2223
|
}
|
|
2270
2224
|
finally {
|
|
2271
2225
|
releaseLock();
|
|
@@ -2828,16 +2782,15 @@ let AssetsController = (() => {
|
|
|
2828
2782
|
});
|
|
2829
2783
|
const releaseLock = await this.#accountRefreshMutex.acquire();
|
|
2830
2784
|
try {
|
|
2785
|
+
this.#ensureNativeBalancesDefaultZero();
|
|
2786
|
+
this.#ensureDefaultTrackedAssetsSeeded();
|
|
2831
2787
|
if (accounts.length > 0) {
|
|
2832
2788
|
await this.getAssets(accounts, {
|
|
2833
2789
|
chainIds: [...this.#enabledChains],
|
|
2834
2790
|
forceUpdate: true,
|
|
2835
2791
|
});
|
|
2836
2792
|
}
|
|
2837
|
-
this.#ensureNativeBalancesDefaultZero();
|
|
2838
|
-
this.#ensureDefaultTrackedAssetsSeeded();
|
|
2839
2793
|
this.#subscribeAssets({ skipInitialFetch: true });
|
|
2840
|
-
this.#fetchMissingPricesWithoutCache(accounts, [...this.#enabledChains]);
|
|
2841
2794
|
}
|
|
2842
2795
|
finally {
|
|
2843
2796
|
releaseLock();
|
|
@@ -2869,25 +2822,21 @@ let AssetsController = (() => {
|
|
|
2869
2822
|
// Note: We intentionally do NOT delete balance data for disabled chains.
|
|
2870
2823
|
// Users may want to see historical balances even if the network is currently disabled.
|
|
2871
2824
|
// The data will simply not be updated until the network is re-enabled.
|
|
2825
|
+
const accounts = this.#getSelectedAccounts();
|
|
2826
|
+
this.#ensureNativeBalancesDefaultZero();
|
|
2827
|
+
if (addedChains.length > 0) {
|
|
2828
|
+
this.#ensureDefaultTrackedAssetsSeeded(addedChains);
|
|
2829
|
+
}
|
|
2872
2830
|
// Refresh subscriptions for new chain set
|
|
2873
2831
|
this.#subscribeAssets();
|
|
2874
2832
|
// One-time fetch for newly enabled chains. v6 `full` replace is scoped to
|
|
2875
2833
|
// those chains; existing balances on other chains are left untouched.
|
|
2876
|
-
const accounts = this.#getSelectedAccounts();
|
|
2877
2834
|
if (addedChains.length > 0 && accounts.length > 0) {
|
|
2878
2835
|
await this.getAssets(accounts, {
|
|
2879
2836
|
chainIds: addedChains,
|
|
2880
2837
|
forceUpdate: true,
|
|
2881
2838
|
});
|
|
2882
2839
|
}
|
|
2883
|
-
this.#ensureNativeBalancesDefaultZero();
|
|
2884
|
-
// Seed default tracked assets (mUSD) for any chain the user has
|
|
2885
|
-
// *just* enabled. This is what makes mUSD appear on Monad after
|
|
2886
|
-
// the user finally adds it to NetworkEnablementController.
|
|
2887
|
-
if (addedChains.length > 0) {
|
|
2888
|
-
this.#ensureDefaultTrackedAssetsSeeded(addedChains);
|
|
2889
|
-
}
|
|
2890
|
-
this.#fetchMissingPricesWithoutCache(accounts, [...this.#enabledChains]);
|
|
2891
2840
|
}
|
|
2892
2841
|
/**
|
|
2893
2842
|
* Handle a `NetworkController:networkAdded` event. When the user
|
|
@@ -2916,8 +2865,6 @@ let AssetsController = (() => {
|
|
|
2916
2865
|
caipChainId,
|
|
2917
2866
|
});
|
|
2918
2867
|
this.#ensureDefaultTrackedAssetsSeeded([caipChainId]);
|
|
2919
|
-
const accounts = this.#getSelectedAccounts();
|
|
2920
|
-
this.#fetchMissingPricesWithoutCache(accounts, [caipChainId]);
|
|
2921
2868
|
}
|
|
2922
2869
|
/**
|
|
2923
2870
|
* Refresh data-source `activeChains` after an EVM network switch so API/Rpc
|
|
@@ -2971,14 +2918,13 @@ let AssetsController = (() => {
|
|
|
2971
2918
|
const releaseLock = await this.#accountRefreshMutex.acquire();
|
|
2972
2919
|
try {
|
|
2973
2920
|
await this.#refreshActiveChainsOnNetworkSwitch();
|
|
2921
|
+
this.#ensureNativeBalancesDefaultZero();
|
|
2974
2922
|
this.#subscribeAssets();
|
|
2975
2923
|
await this.getAssets(accounts, {
|
|
2976
2924
|
chainIds: [selectedChainId],
|
|
2977
2925
|
forceUpdate: true,
|
|
2978
2926
|
dataTypes: ['balance', 'metadata', 'price'],
|
|
2979
2927
|
});
|
|
2980
|
-
this.#ensureNativeBalancesDefaultZero();
|
|
2981
|
-
this.#fetchMissingPricesWithoutCache(accounts, [selectedChainId]);
|
|
2982
2928
|
}
|
|
2983
2929
|
finally {
|
|
2984
2930
|
releaseLock();
|
|
@@ -3016,13 +2962,12 @@ let AssetsController = (() => {
|
|
|
3016
2962
|
catch {
|
|
3017
2963
|
return;
|
|
3018
2964
|
}
|
|
2965
|
+
this.#ensureNativeBalancesDefaultZero();
|
|
3019
2966
|
await this.getAssets(accounts, {
|
|
3020
2967
|
chainIds: [caipChainId],
|
|
3021
2968
|
forceUpdate: true,
|
|
3022
2969
|
dataTypes: ['balance', 'metadata', 'price'],
|
|
3023
2970
|
});
|
|
3024
|
-
this.#ensureNativeBalancesDefaultZero();
|
|
3025
|
-
this.#fetchMissingPricesWithoutCache(accounts, [caipChainId]);
|
|
3026
2971
|
}
|
|
3027
2972
|
/**
|
|
3028
2973
|
* Handle assets updated from a data source.
|
|
@@ -3063,14 +3008,12 @@ let AssetsController = (() => {
|
|
|
3063
3008
|
? buildWsUpdateSources({
|
|
3064
3009
|
customAssetGraduationMiddleware: this.#customAssetGraduationMiddleware,
|
|
3065
3010
|
rpcFallbackMiddleware: this.#rpcFallbackMiddleware,
|
|
3066
|
-
detectionMiddleware: this.#detectionMiddleware,
|
|
3067
3011
|
tokenDataSource: this.#tokenDataSource,
|
|
3068
3012
|
priceDataSource: this.#priceDataSource,
|
|
3069
3013
|
}, { isBasicFunctionality, includeCustomAssetGraduation: true })
|
|
3070
3014
|
: buildUpdateSources({
|
|
3071
3015
|
customAssetGraduationMiddleware: this.#customAssetGraduationMiddleware,
|
|
3072
3016
|
rpcFallbackMiddleware: this.#rpcFallbackMiddleware,
|
|
3073
|
-
detectionMiddleware: this.#detectionMiddleware,
|
|
3074
3017
|
tokenDataSource: this.#tokenDataSource,
|
|
3075
3018
|
priceDataSource: this.#priceDataSource,
|
|
3076
3019
|
}, {
|
|
@@ -3116,14 +3059,12 @@ let AssetsController = (() => {
|
|
|
3116
3059
|
? buildWsUpdateSources({
|
|
3117
3060
|
customAssetGraduationMiddleware: this.#customAssetGraduationMiddleware,
|
|
3118
3061
|
rpcFallbackMiddleware: this.#rpcFallbackMiddleware,
|
|
3119
|
-
detectionMiddleware: this.#detectionMiddleware,
|
|
3120
3062
|
tokenDataSource: this.#tokenDataSource,
|
|
3121
3063
|
priceDataSource: this.#priceDataSource,
|
|
3122
3064
|
}, { isBasicFunctionality, includeCustomAssetGraduation: false })
|
|
3123
3065
|
: buildUpdateSources({
|
|
3124
3066
|
customAssetGraduationMiddleware: this.#customAssetGraduationMiddleware,
|
|
3125
3067
|
rpcFallbackMiddleware: this.#rpcFallbackMiddleware,
|
|
3126
|
-
detectionMiddleware: this.#detectionMiddleware,
|
|
3127
3068
|
tokenDataSource: this.#tokenDataSource,
|
|
3128
3069
|
priceDataSource: this.#priceDataSource,
|
|
3129
3070
|
}, {
|
|
@@ -3219,6 +3160,7 @@ let AssetsController = (() => {
|
|
|
3219
3160
|
this.messenger.unregisterActionHandler('AssetsController:getAccountAssetsByIDs');
|
|
3220
3161
|
this.messenger.unregisterActionHandler('AssetsController:getAccountAssetsByScope');
|
|
3221
3162
|
this.messenger.unregisterActionHandler('AssetsController:getAssetsPrice');
|
|
3163
|
+
this.messenger.unregisterActionHandler('AssetsController:syncAssetsPrices');
|
|
3222
3164
|
this.messenger.unregisterActionHandler('AssetsController:getExchangeRatesForBridge');
|
|
3223
3165
|
this.messenger.unregisterActionHandler('AssetsController:getStateForTransactionPay');
|
|
3224
3166
|
this.messenger.unregisterActionHandler('AssetsController:addCustomAsset');
|