@metamask-previews/assets-controller 2.0.2-preview-835c0b0 → 2.0.2-preview-1e855a9f5
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 +1 -17
- package/dist/AssetsController-method-action-types.cjs.map +1 -1
- package/dist/AssetsController-method-action-types.d.cts +0 -5
- package/dist/AssetsController-method-action-types.d.cts.map +1 -1
- package/dist/AssetsController-method-action-types.d.mts +0 -5
- package/dist/AssetsController-method-action-types.d.mts.map +1 -1
- package/dist/AssetsController-method-action-types.mjs.map +1 -1
- package/dist/AssetsController.cjs +29 -148
- package/dist/AssetsController.cjs.map +1 -1
- package/dist/AssetsController.d.cts +5 -37
- package/dist/AssetsController.d.cts.map +1 -1
- package/dist/AssetsController.d.mts +5 -37
- package/dist/AssetsController.d.mts.map +1 -1
- package/dist/AssetsController.mjs +29 -148
- package/dist/AssetsController.mjs.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.cjs +0 -1
- package/dist/data-sources/AccountsApiDataSource.cjs.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.d.cts.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.d.mts.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.mjs +0 -1
- package/dist/data-sources/AccountsApiDataSource.mjs.map +1 -1
- package/dist/data-sources/BackendWebsocketDataSource.cjs +4 -16
- package/dist/data-sources/BackendWebsocketDataSource.cjs.map +1 -1
- package/dist/data-sources/BackendWebsocketDataSource.d.cts.map +1 -1
- package/dist/data-sources/BackendWebsocketDataSource.d.mts.map +1 -1
- package/dist/data-sources/BackendWebsocketDataSource.mjs +4 -13
- package/dist/data-sources/BackendWebsocketDataSource.mjs.map +1 -1
- package/dist/data-sources/PriceDataSource.cjs +14 -20
- package/dist/data-sources/PriceDataSource.cjs.map +1 -1
- package/dist/data-sources/PriceDataSource.d.cts +2 -2
- package/dist/data-sources/PriceDataSource.d.cts.map +1 -1
- package/dist/data-sources/PriceDataSource.d.mts +2 -2
- package/dist/data-sources/PriceDataSource.d.mts.map +1 -1
- package/dist/data-sources/PriceDataSource.mjs +14 -20
- package/dist/data-sources/PriceDataSource.mjs.map +1 -1
- package/dist/data-sources/RpcDataSource.cjs +0 -2
- package/dist/data-sources/RpcDataSource.cjs.map +1 -1
- package/dist/data-sources/RpcDataSource.d.cts.map +1 -1
- package/dist/data-sources/RpcDataSource.d.mts.map +1 -1
- package/dist/data-sources/RpcDataSource.mjs +0 -2
- package/dist/data-sources/RpcDataSource.mjs.map +1 -1
- package/dist/data-sources/SnapDataSource.cjs +2 -3
- package/dist/data-sources/SnapDataSource.cjs.map +1 -1
- package/dist/data-sources/SnapDataSource.d.cts.map +1 -1
- package/dist/data-sources/SnapDataSource.d.mts.map +1 -1
- package/dist/data-sources/SnapDataSource.mjs +2 -3
- package/dist/data-sources/SnapDataSource.mjs.map +1 -1
- package/dist/data-sources/TokenDataSource.cjs +0 -1
- package/dist/data-sources/TokenDataSource.cjs.map +1 -1
- package/dist/data-sources/TokenDataSource.d.cts.map +1 -1
- package/dist/data-sources/TokenDataSource.d.mts.map +1 -1
- package/dist/data-sources/TokenDataSource.mjs +0 -1
- package/dist/data-sources/TokenDataSource.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/middlewares/DetectionMiddleware.cjs +27 -44
- package/dist/middlewares/DetectionMiddleware.cjs.map +1 -1
- package/dist/middlewares/DetectionMiddleware.d.cts +9 -15
- package/dist/middlewares/DetectionMiddleware.d.cts.map +1 -1
- package/dist/middlewares/DetectionMiddleware.d.mts +9 -15
- package/dist/middlewares/DetectionMiddleware.d.mts.map +1 -1
- package/dist/middlewares/DetectionMiddleware.mjs +27 -44
- package/dist/middlewares/DetectionMiddleware.mjs.map +1 -1
- package/dist/middlewares/index.cjs +1 -5
- package/dist/middlewares/index.cjs.map +1 -1
- package/dist/middlewares/index.d.cts +0 -2
- package/dist/middlewares/index.d.cts.map +1 -1
- package/dist/middlewares/index.d.mts +0 -2
- package/dist/middlewares/index.d.mts.map +1 -1
- package/dist/middlewares/index.mjs +0 -1
- package/dist/middlewares/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +0 -16
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +0 -16
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +5 -6
- package/dist/middlewares/ParallelMiddleware.cjs +0 -216
- package/dist/middlewares/ParallelMiddleware.cjs.map +0 -1
- package/dist/middlewares/ParallelMiddleware.d.cts +0 -45
- package/dist/middlewares/ParallelMiddleware.d.cts.map +0 -1
- package/dist/middlewares/ParallelMiddleware.d.mts +0 -45
- package/dist/middlewares/ParallelMiddleware.d.mts.map +0 -1
- package/dist/middlewares/ParallelMiddleware.mjs +0 -214
- package/dist/middlewares/ParallelMiddleware.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,26 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
### Added
|
|
11
|
-
|
|
12
|
-
- Add `PendingTokenMetadata` type and optional `pendingMetadata` parameter to `addCustomAsset(accountId, assetId, pendingMetadata?)`. When provided (e.g. from the extension's pending-tokens flow), token metadata is written to `assetsInfo` immediately so the UI can render the token without waiting for the pipeline ([#8021](https://github.com/MetaMask/core/pull/8021))
|
|
13
|
-
- Add `currentCurrency` state (ISO 4217 code, default `'usd'`) and `setCurrentCurrency(currentCurrency)` to `AssetsController`. Changing the currency updates state and triggers a one-off price refetch so displayed prices use the new currency ([#7991](https://github.com/MetaMask/core/pull/7991))
|
|
14
|
-
- Add support for forcibly updating prices ([#7991](https://github.com/MetaMask/core/pull/7991))
|
|
15
|
-
- Add parallel middlewares in `ParallelMiddleware.ts`: `createParallelBalanceMiddleware` runs balance data sources (Accounts API, Snap, RPC) in parallel with chain partitioning and a fallback round for failed chains; `createParallelMiddleware` runs TokenDataSource and PriceDataSource in parallel (same request, merged response). Both use `mergeDataResponses` and limited concurrency via `p-limit` ([#7950](https://github.com/MetaMask/core/pull/7950))
|
|
16
|
-
- Add `@metamask/client-controller` dependency and subscribe to `ClientController:stateChange`. Asset tracking runs only when the UI is open (ClientController) and the keyring is unlocked (KeyringController), and stops when either the UI closes or the keyring locks (Client + Keyring lifecycle) ([#7950](https://github.com/MetaMask/core/pull/7950))
|
|
17
|
-
- Add full and merge update modes: `DataResponse.updateMode` and type `AssetsUpdateMode` (`'full'` | `'merge'`). Fetch uses `'full'` (response is authoritative for scope; custom assets not in response are preserved). Subscriptions could use `'merge'` or `'full'` depending on data sources. Default is `'merge'` when omitted ([#7950](https://github.com/MetaMask/core/pull/7950))
|
|
18
|
-
|
|
19
10
|
### Changed
|
|
20
11
|
|
|
21
|
-
- Bump `@metamask/transaction-controller` from `^62.17.1` to `^62.
|
|
12
|
+
- Bump `@metamask/transaction-controller` from `^62.17.1` to `^62.18.0` ([#8005](https://github.com/MetaMask/core/pull/8005))
|
|
22
13
|
- Bump `@metamask/assets-controllers` from `^100.0.1` to `^100.0.2` ([#8004](https://github.com/MetaMask/core/pull/8004))
|
|
23
|
-
- Bump `@metamask/assets-controllers` from `^100.0.2` to `^100.0.3` ([#8029](https://github.com/MetaMask/core/pull/8029))
|
|
24
|
-
|
|
25
|
-
### Fixed
|
|
26
|
-
|
|
27
|
-
- Convert WebSocket balance updates in `BackendWebsocketDataSource` from raw smallest-units to human-readable amounts using asset decimals (same behavior as RPC/Accounts API), so `assetsBalance` remains consistent across data sources ([#8032](https://github.com/MetaMask/core/pull/8032))
|
|
28
|
-
- Include all assets from balance and each account's custom assets from state in `detectedAssets`, so prices and metadata are fetched for existing assets and custom tokens (previously only assets without metadata were included, so existing assets did not get prices) ([#8021](https://github.com/MetaMask/core/pull/8021))
|
|
29
|
-
- Request `includeAggregators: true` when fetching token metadata from the v3 assets API so aggregator data is returned and stored in `assetsInfo` ([#8021](https://github.com/MetaMask/core/pull/8021))
|
|
30
14
|
|
|
31
15
|
## [2.0.2]
|
|
32
16
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetsController-method-action-types.cjs","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { AssetsController } from './AssetsController';\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\nexport type AssetsControllerGetAssetsPriceAction = {\n type: `AssetsController:getAssetsPrice`;\n handler: AssetsController['getAssetsPrice'];\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 *\n *
|
|
1
|
+
{"version":3,"file":"AssetsController-method-action-types.cjs","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { AssetsController } from './AssetsController';\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\nexport type AssetsControllerGetAssetsPriceAction = {\n type: `AssetsController:getAssetsPrice`;\n handler: AssetsController['getAssetsPrice'];\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 *\n * @param accountId - The account ID to add the custom asset for.\n * @param assetId - The CAIP-19 asset ID to add.\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 *\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 * Union of all AssetsController action types.\n */\nexport type AssetsControllerMethodActions =\n | AssetsControllerGetAssetsAction\n | AssetsControllerGetAssetsBalanceAction\n | AssetsControllerGetAssetMetadataAction\n | AssetsControllerGetAssetsPriceAction\n | AssetsControllerAddCustomAssetAction\n | AssetsControllerRemoveCustomAssetAction\n | AssetsControllerGetCustomAssetsAction\n | AssetsControllerHideAssetAction\n | AssetsControllerUnhideAssetAction;\n"]}
|
|
@@ -24,13 +24,8 @@ export type AssetsControllerGetAssetsPriceAction = {
|
|
|
24
24
|
* Custom assets are included in subscription and fetch operations.
|
|
25
25
|
* Adding a custom asset also unhides it if it was previously hidden.
|
|
26
26
|
*
|
|
27
|
-
* When `pendingMetadata` is provided (e.g. from the extension's pending-tokens
|
|
28
|
-
* flow), the token metadata is persisted immediately into `assetsInfo` so the
|
|
29
|
-
* UI can render it without waiting for the next pipeline fetch.
|
|
30
|
-
*
|
|
31
27
|
* @param accountId - The account ID to add the custom asset for.
|
|
32
28
|
* @param assetId - The CAIP-19 asset ID to add.
|
|
33
|
-
* @param pendingMetadata - Optional token metadata from the UI (pendingTokens format).
|
|
34
29
|
*/
|
|
35
30
|
export type AssetsControllerAddCustomAssetAction = {
|
|
36
31
|
type: `AssetsController:addCustomAsset`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetsController-method-action-types.d.cts","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,+BAA2B;AAE3D,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,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"AssetsController-method-action-types.d.cts","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,+BAA2B;AAE3D,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,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,qCAAqC,GAAG;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;;;;GAIG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC;CAC1C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACrC,+BAA+B,GAC/B,sCAAsC,GACtC,sCAAsC,GACtC,oCAAoC,GACpC,oCAAoC,GACpC,uCAAuC,GACvC,qCAAqC,GACrC,+BAA+B,GAC/B,iCAAiC,CAAC"}
|
|
@@ -24,13 +24,8 @@ export type AssetsControllerGetAssetsPriceAction = {
|
|
|
24
24
|
* Custom assets are included in subscription and fetch operations.
|
|
25
25
|
* Adding a custom asset also unhides it if it was previously hidden.
|
|
26
26
|
*
|
|
27
|
-
* When `pendingMetadata` is provided (e.g. from the extension's pending-tokens
|
|
28
|
-
* flow), the token metadata is persisted immediately into `assetsInfo` so the
|
|
29
|
-
* UI can render it without waiting for the next pipeline fetch.
|
|
30
|
-
*
|
|
31
27
|
* @param accountId - The account ID to add the custom asset for.
|
|
32
28
|
* @param assetId - The CAIP-19 asset ID to add.
|
|
33
|
-
* @param pendingMetadata - Optional token metadata from the UI (pendingTokens format).
|
|
34
29
|
*/
|
|
35
30
|
export type AssetsControllerAddCustomAssetAction = {
|
|
36
31
|
type: `AssetsController:addCustomAsset`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetsController-method-action-types.d.mts","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,+BAA2B;AAE3D,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,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"AssetsController-method-action-types.d.mts","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,+BAA2B;AAE3D,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,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,qCAAqC,GAAG;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;;;;GAIG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC;CAC1C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACrC,+BAA+B,GAC/B,sCAAsC,GACtC,sCAAsC,GACtC,oCAAoC,GACpC,oCAAoC,GACpC,uCAAuC,GACvC,qCAAqC,GACrC,+BAA+B,GAC/B,iCAAiC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetsController-method-action-types.mjs","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { AssetsController } from './AssetsController';\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\nexport type AssetsControllerGetAssetsPriceAction = {\n type: `AssetsController:getAssetsPrice`;\n handler: AssetsController['getAssetsPrice'];\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 *\n *
|
|
1
|
+
{"version":3,"file":"AssetsController-method-action-types.mjs","sourceRoot":"","sources":["../src/AssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { AssetsController } from './AssetsController';\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\nexport type AssetsControllerGetAssetsPriceAction = {\n type: `AssetsController:getAssetsPrice`;\n handler: AssetsController['getAssetsPrice'];\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 *\n * @param accountId - The account ID to add the custom asset for.\n * @param assetId - The CAIP-19 asset ID to add.\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 *\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 * Union of all AssetsController action types.\n */\nexport type AssetsControllerMethodActions =\n | AssetsControllerGetAssetsAction\n | AssetsControllerGetAssetsBalanceAction\n | AssetsControllerGetAssetMetadataAction\n | AssetsControllerGetAssetsPriceAction\n | AssetsControllerAddCustomAssetAction\n | AssetsControllerRemoveCustomAssetAction\n | AssetsControllerGetCustomAssetsAction\n | AssetsControllerHideAssetAction\n | AssetsControllerUnhideAssetAction;\n"]}
|
|
@@ -13,11 +13,10 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
13
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
|
-
var _AssetsController_instances, _AssetsController_isEnabled, _AssetsController_isBasicFunctionality, _AssetsController_defaultUpdateInterval, _AssetsController_trackMetaMetricsEvent, _AssetsController_firstInitFetchReported,
|
|
16
|
+
var _AssetsController_instances, _AssetsController_isEnabled, _AssetsController_isBasicFunctionality, _AssetsController_defaultUpdateInterval, _AssetsController_trackMetaMetricsEvent, _AssetsController_firstInitFetchReported, _AssetsController_controllerMutex, _AssetsController_activeSubscriptions, _AssetsController_enabledChains, _AssetsController_selectedAccounts_get, _AssetsController_backendWebsocketDataSource, _AssetsController_accountsApiDataSource, _AssetsController_snapDataSource, _AssetsController_rpcDataSource, _AssetsController_stakedBalanceDataSource, _AssetsController_allBalanceDataSources_get, _AssetsController_priceDataSource, _AssetsController_detectionMiddleware, _AssetsController_tokenDataSource, _AssetsController_unsubscribeBasicFunctionality, _AssetsController_initializeState, _AssetsController_extractEnabledChains, _AssetsController_normalizeChainReference, _AssetsController_subscribeToEvents, _AssetsController_registerActionHandlers, _AssetsController_executeMiddlewares, _AssetsController_updateState, _AssetsController_getAssetsFromState, _AssetsController_tokenStandardToAssetType, _AssetsController_start, _AssetsController_stop, _AssetsController_subscribeAssets, _AssetsController_subscribeAssetsBalance, _AssetsController_subscribeStakedBalance, _AssetsController_buildChainToAccountsMap, _AssetsController_subscribeDataSource, _AssetsController_unsubscribeDataSource, _AssetsController_buildDataRequest, _AssetsController_getEnabledChainsForAccount, _AssetsController_handleAccountGroupChanged, _AssetsController_handleEnabledNetworksChanged;
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.AssetsController = exports.getDefaultAssetsControllerState = void 0;
|
|
19
19
|
const base_controller_1 = require("@metamask/base-controller");
|
|
20
|
-
const client_controller_1 = require("@metamask/client-controller");
|
|
21
20
|
const utils_1 = require("@metamask/utils");
|
|
22
21
|
const async_mutex_1 = require("async-mutex");
|
|
23
22
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
@@ -31,7 +30,6 @@ const StakedBalanceDataSource_1 = require("./data-sources/StakedBalanceDataSourc
|
|
|
31
30
|
const TokenDataSource_1 = require("./data-sources/TokenDataSource.cjs");
|
|
32
31
|
const logger_1 = require("./logger.cjs");
|
|
33
32
|
const DetectionMiddleware_1 = require("./middlewares/DetectionMiddleware.cjs");
|
|
34
|
-
const ParallelMiddleware_1 = require("./middlewares/ParallelMiddleware.cjs");
|
|
35
33
|
const utils_2 = require("./utils.cjs");
|
|
36
34
|
// ============================================================================
|
|
37
35
|
// CONTROLLER CONSTANTS
|
|
@@ -64,7 +62,6 @@ function getDefaultAssetsControllerState() {
|
|
|
64
62
|
assetsPrice: {},
|
|
65
63
|
customAssets: {},
|
|
66
64
|
assetPreferences: {},
|
|
67
|
-
selectedCurrency: 'usd',
|
|
68
65
|
};
|
|
69
66
|
}
|
|
70
67
|
exports.getDefaultAssetsControllerState = getDefaultAssetsControllerState;
|
|
@@ -102,12 +99,6 @@ const stateMetadata = {
|
|
|
102
99
|
includeInDebugSnapshot: false,
|
|
103
100
|
usedInUi: true,
|
|
104
101
|
},
|
|
105
|
-
selectedCurrency: {
|
|
106
|
-
persist: true,
|
|
107
|
-
includeInStateLogs: false,
|
|
108
|
-
includeInDebugSnapshot: false,
|
|
109
|
-
usedInUi: true,
|
|
110
|
-
},
|
|
111
102
|
};
|
|
112
103
|
// ============================================================================
|
|
113
104
|
// HELPER FUNCTIONS
|
|
@@ -161,9 +152,6 @@ function normalizeResponse(response) {
|
|
|
161
152
|
if (response.errors) {
|
|
162
153
|
normalized.errors = { ...response.errors };
|
|
163
154
|
}
|
|
164
|
-
if (response.updateMode) {
|
|
165
|
-
normalized.updateMode = response.updateMode;
|
|
166
|
-
}
|
|
167
155
|
return normalized;
|
|
168
156
|
}
|
|
169
157
|
// ============================================================================
|
|
@@ -185,10 +173,8 @@ function normalizeResponse(response) {
|
|
|
185
173
|
* based on which chains they support. When active chains change, the controller
|
|
186
174
|
* dynamically adjusts subscriptions.
|
|
187
175
|
*
|
|
188
|
-
* 4. **
|
|
189
|
-
*
|
|
190
|
-
* Stops when either the UI closes or the keyring locks. See client-controller
|
|
191
|
-
* README for the combined pattern.
|
|
176
|
+
* 4. **Keyring Lifecycle**: Listens to KeyringController unlock/lock events to
|
|
177
|
+
* start/stop subscriptions when the wallet is unlocked or locked.
|
|
192
178
|
*
|
|
193
179
|
* ## Architecture
|
|
194
180
|
*
|
|
@@ -218,10 +204,6 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
218
204
|
_AssetsController_trackMetaMetricsEvent.set(this, void 0);
|
|
219
205
|
/** Whether we have already reported first init fetch for this session (reset on #stop). */
|
|
220
206
|
_AssetsController_firstInitFetchReported.set(this, false);
|
|
221
|
-
/** Whether the client (UI) is open. Combined with #keyringUnlocked for #updateActive. */
|
|
222
|
-
_AssetsController_uiOpen.set(this, false);
|
|
223
|
-
/** Whether the keyring is unlocked. Combined with #uiOpen for #updateActive. */
|
|
224
|
-
_AssetsController_keyringUnlocked.set(this, false);
|
|
225
207
|
_AssetsController_controllerMutex.set(this, new async_mutex_1.Mutex());
|
|
226
208
|
/**
|
|
227
209
|
* Active balance subscriptions keyed by account ID.
|
|
@@ -278,7 +260,6 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
278
260
|
}), "f");
|
|
279
261
|
__classPrivateFieldSet(this, _AssetsController_priceDataSource, new PriceDataSource_1.PriceDataSource({
|
|
280
262
|
queryApiClient,
|
|
281
|
-
getSelectedCurrency: () => this.state.selectedCurrency,
|
|
282
263
|
...priceDataSourceConfig,
|
|
283
264
|
}), "f");
|
|
284
265
|
__classPrivateFieldSet(this, _AssetsController_detectionMiddleware, new DetectionMiddleware_1.DetectionMiddleware(), "f");
|
|
@@ -292,7 +273,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
292
273
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_initializeState).call(this);
|
|
293
274
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeToEvents).call(this);
|
|
294
275
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_registerActionHandlers).call(this);
|
|
295
|
-
// Subscriptions start only
|
|
276
|
+
// Subscriptions start only on KeyringController:unlock -> #start(), not here.
|
|
296
277
|
// Subscribe to basic-functionality changes after construction so a synchronous
|
|
297
278
|
// onChange during subscribe cannot run before data sources are initialized.
|
|
298
279
|
if (subscribeToBasicFunctionalityChange) {
|
|
@@ -356,9 +337,6 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
356
337
|
const chainIds = options?.chainIds ?? [...__classPrivateFieldGet(this, _AssetsController_enabledChains, "f")];
|
|
357
338
|
const assetTypes = options?.assetTypes ?? ['fungible'];
|
|
358
339
|
const dataTypes = options?.dataTypes ?? ['balance', 'metadata', 'price'];
|
|
359
|
-
if (accounts.length === 0 || chainIds.length === 0) {
|
|
360
|
-
return __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getAssetsFromState).call(this, accounts, chainIds, assetTypes);
|
|
361
|
-
}
|
|
362
340
|
// Collect custom assets for all requested accounts
|
|
363
341
|
const customAssets = [];
|
|
364
342
|
for (const account of accounts) {
|
|
@@ -372,21 +350,16 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
372
350
|
dataTypes,
|
|
373
351
|
customAssets: customAssets.length > 0 ? customAssets : undefined,
|
|
374
352
|
forceUpdate: true,
|
|
375
|
-
assetsForPriceUpdate: options?.assetsForPriceUpdate,
|
|
376
353
|
});
|
|
377
354
|
const sources = __classPrivateFieldGet(this, _AssetsController_isBasicFunctionality, "f").call(this)
|
|
378
355
|
? [
|
|
379
|
-
(
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
__classPrivateFieldGet(this, _AssetsController_stakedBalanceDataSource, "f"),
|
|
384
|
-
]),
|
|
356
|
+
__classPrivateFieldGet(this, _AssetsController_accountsApiDataSource, "f"),
|
|
357
|
+
__classPrivateFieldGet(this, _AssetsController_snapDataSource, "f"),
|
|
358
|
+
__classPrivateFieldGet(this, _AssetsController_rpcDataSource, "f"),
|
|
359
|
+
__classPrivateFieldGet(this, _AssetsController_stakedBalanceDataSource, "f"),
|
|
385
360
|
__classPrivateFieldGet(this, _AssetsController_detectionMiddleware, "f"),
|
|
386
|
-
(
|
|
387
|
-
|
|
388
|
-
__classPrivateFieldGet(this, _AssetsController_priceDataSource, "f"),
|
|
389
|
-
]),
|
|
361
|
+
__classPrivateFieldGet(this, _AssetsController_tokenDataSource, "f"),
|
|
362
|
+
__classPrivateFieldGet(this, _AssetsController_priceDataSource, "f"),
|
|
390
363
|
]
|
|
391
364
|
: [
|
|
392
365
|
__classPrivateFieldGet(this, _AssetsController_rpcDataSource, "f"),
|
|
@@ -394,7 +367,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
394
367
|
__classPrivateFieldGet(this, _AssetsController_detectionMiddleware, "f"),
|
|
395
368
|
];
|
|
396
369
|
const { response, durationByDataSource } = await __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_executeMiddlewares).call(this, sources, request);
|
|
397
|
-
await __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_updateState).call(this,
|
|
370
|
+
await __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_updateState).call(this, response);
|
|
398
371
|
if (__classPrivateFieldGet(this, _AssetsController_trackMetaMetricsEvent, "f") && !__classPrivateFieldGet(this, _AssetsController_firstInitFetchReported, "f")) {
|
|
399
372
|
__classPrivateFieldSet(this, _AssetsController_firstInitFetchReported, true, "f");
|
|
400
373
|
const durationMs = Date.now() - startTime;
|
|
@@ -405,8 +378,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
405
378
|
});
|
|
406
379
|
}
|
|
407
380
|
}
|
|
408
|
-
|
|
409
|
-
return result;
|
|
381
|
+
return __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getAssetsFromState).call(this, accounts, chainIds, assetTypes);
|
|
410
382
|
}
|
|
411
383
|
async getAssetsBalance(accounts, options) {
|
|
412
384
|
// Reuse getAssets with dataTypes: ['balance'] only
|
|
@@ -457,15 +429,10 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
457
429
|
* Custom assets are included in subscription and fetch operations.
|
|
458
430
|
* Adding a custom asset also unhides it if it was previously hidden.
|
|
459
431
|
*
|
|
460
|
-
* When `pendingMetadata` is provided (e.g. from the extension's pending-tokens
|
|
461
|
-
* flow), the token metadata is persisted immediately into `assetsInfo` so the
|
|
462
|
-
* UI can render it without waiting for the next pipeline fetch.
|
|
463
|
-
*
|
|
464
432
|
* @param accountId - The account ID to add the custom asset for.
|
|
465
433
|
* @param assetId - The CAIP-19 asset ID to add.
|
|
466
|
-
* @param pendingMetadata - Optional token metadata from the UI (pendingTokens format).
|
|
467
434
|
*/
|
|
468
|
-
async addCustomAsset(accountId, assetId
|
|
435
|
+
async addCustomAsset(accountId, assetId) {
|
|
469
436
|
const normalizedAssetId = (0, utils_2.normalizeAssetId)(assetId);
|
|
470
437
|
log('Adding custom asset', { accountId, assetId: normalizedAssetId });
|
|
471
438
|
this.update((state) => {
|
|
@@ -485,28 +452,6 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
485
452
|
delete state.assetPreferences[normalizedAssetId];
|
|
486
453
|
}
|
|
487
454
|
}
|
|
488
|
-
// Persist metadata from the UI so the token is immediately renderable
|
|
489
|
-
if (pendingMetadata) {
|
|
490
|
-
const parsed = (0, utils_1.parseCaipAssetType)(normalizedAssetId);
|
|
491
|
-
let tokenType = 'erc20';
|
|
492
|
-
if (parsed.assetNamespace === 'slip44') {
|
|
493
|
-
tokenType = 'native';
|
|
494
|
-
}
|
|
495
|
-
else if (parsed.assetNamespace === 'spl') {
|
|
496
|
-
tokenType = 'spl';
|
|
497
|
-
}
|
|
498
|
-
const assetMetadata = {
|
|
499
|
-
type: tokenType,
|
|
500
|
-
symbol: pendingMetadata.symbol,
|
|
501
|
-
name: pendingMetadata.name,
|
|
502
|
-
decimals: pendingMetadata.decimals,
|
|
503
|
-
image: pendingMetadata.iconUrl,
|
|
504
|
-
aggregators: pendingMetadata.aggregators,
|
|
505
|
-
occurrences: pendingMetadata.occurrences,
|
|
506
|
-
};
|
|
507
|
-
state.assetsInfo[normalizedAssetId] =
|
|
508
|
-
assetMetadata;
|
|
509
|
-
}
|
|
510
455
|
});
|
|
511
456
|
// Fetch data for the newly added custom asset
|
|
512
457
|
const account = __classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get).find((a) => a.id === accountId);
|
|
@@ -585,34 +530,6 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
585
530
|
});
|
|
586
531
|
}
|
|
587
532
|
// ============================================================================
|
|
588
|
-
// CURRENT CURRENCY MANAGEMENT
|
|
589
|
-
// ============================================================================
|
|
590
|
-
/**
|
|
591
|
-
* Set the current currency.
|
|
592
|
-
*
|
|
593
|
-
* @param selectedCurrency - The ISO 4217 currency code to set.
|
|
594
|
-
*/
|
|
595
|
-
setSelectedCurrency(selectedCurrency) {
|
|
596
|
-
const previousCurrency = this.state.selectedCurrency;
|
|
597
|
-
if (previousCurrency === selectedCurrency) {
|
|
598
|
-
return;
|
|
599
|
-
}
|
|
600
|
-
this.update((state) => {
|
|
601
|
-
state.selectedCurrency = selectedCurrency;
|
|
602
|
-
});
|
|
603
|
-
log('Current currency changed', {
|
|
604
|
-
previousCurrency,
|
|
605
|
-
selectedCurrency,
|
|
606
|
-
});
|
|
607
|
-
this.getAssets(__classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get), {
|
|
608
|
-
forceUpdate: true,
|
|
609
|
-
dataTypes: ['price'],
|
|
610
|
-
assetsForPriceUpdate: Object.values(this.state.assetsBalance).flatMap((balances) => Object.keys(balances)),
|
|
611
|
-
}).catch((error) => {
|
|
612
|
-
log('Failed to fetch asset prices after current currency change', error);
|
|
613
|
-
});
|
|
614
|
-
}
|
|
615
|
-
// ============================================================================
|
|
616
533
|
// SUBSCRIPTIONS
|
|
617
534
|
// ============================================================================
|
|
618
535
|
/**
|
|
@@ -690,15 +607,9 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
690
607
|
hasBalance: Boolean(response.assetsBalance),
|
|
691
608
|
hasPrice: Boolean(response.assetsPrice),
|
|
692
609
|
});
|
|
693
|
-
// Run through enrichment middlewares (Detection
|
|
610
|
+
// Run through enrichment middlewares (Event Stack: Detection → Token → Price)
|
|
694
611
|
// Include 'metadata' in dataTypes so TokenDataSource runs to enrich detected assets
|
|
695
|
-
const { response: enrichedResponse } = await __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_executeMiddlewares).call(this, [
|
|
696
|
-
__classPrivateFieldGet(this, _AssetsController_detectionMiddleware, "f"),
|
|
697
|
-
(0, ParallelMiddleware_1.createParallelMiddleware)([
|
|
698
|
-
__classPrivateFieldGet(this, _AssetsController_tokenDataSource, "f"),
|
|
699
|
-
__classPrivateFieldGet(this, _AssetsController_priceDataSource, "f"),
|
|
700
|
-
]),
|
|
701
|
-
], request ?? {
|
|
612
|
+
const { response: enrichedResponse } = await __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_executeMiddlewares).call(this, [__classPrivateFieldGet(this, _AssetsController_detectionMiddleware, "f"), __classPrivateFieldGet(this, _AssetsController_tokenDataSource, "f"), __classPrivateFieldGet(this, _AssetsController_priceDataSource, "f")], request ?? {
|
|
702
613
|
accountsWithSupportedChains: [],
|
|
703
614
|
chainIds: [],
|
|
704
615
|
dataTypes: ['balance', 'metadata', 'price'],
|
|
@@ -738,7 +649,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
738
649
|
}
|
|
739
650
|
}
|
|
740
651
|
exports.AssetsController = AssetsController;
|
|
741
|
-
_AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctionality = new WeakMap(), _AssetsController_defaultUpdateInterval = new WeakMap(), _AssetsController_trackMetaMetricsEvent = new WeakMap(), _AssetsController_firstInitFetchReported = new WeakMap(),
|
|
652
|
+
_AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctionality = new WeakMap(), _AssetsController_defaultUpdateInterval = new WeakMap(), _AssetsController_trackMetaMetricsEvent = new WeakMap(), _AssetsController_firstInitFetchReported = new WeakMap(), _AssetsController_controllerMutex = new WeakMap(), _AssetsController_activeSubscriptions = new WeakMap(), _AssetsController_enabledChains = new WeakMap(), _AssetsController_backendWebsocketDataSource = new WeakMap(), _AssetsController_accountsApiDataSource = new WeakMap(), _AssetsController_snapDataSource = new WeakMap(), _AssetsController_rpcDataSource = new WeakMap(), _AssetsController_stakedBalanceDataSource = new WeakMap(), _AssetsController_priceDataSource = new WeakMap(), _AssetsController_detectionMiddleware = new WeakMap(), _AssetsController_tokenDataSource = new WeakMap(), _AssetsController_unsubscribeBasicFunctionality = new WeakMap(), _AssetsController_instances = new WeakSet(), _AssetsController_selectedAccounts_get = function _AssetsController_selectedAccounts_get() {
|
|
742
653
|
return this.messenger.call('AccountTreeController:getAccountsFromSelectedAccountGroup');
|
|
743
654
|
}, _AssetsController_allBalanceDataSources_get = function _AssetsController_allBalanceDataSources_get() {
|
|
744
655
|
return [
|
|
@@ -788,27 +699,9 @@ _AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctional
|
|
|
788
699
|
this.messenger.subscribe('NetworkEnablementController:stateChange', ({ enabledNetworkMap }) => {
|
|
789
700
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_handleEnabledNetworksChanged).call(this, enabledNetworkMap).catch(console.error);
|
|
790
701
|
});
|
|
791
|
-
//
|
|
792
|
-
this.messenger.subscribe('
|
|
793
|
-
|
|
794
|
-
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_updateActive).call(this);
|
|
795
|
-
}, client_controller_1.clientControllerSelectors.selectIsUiOpen);
|
|
796
|
-
this.messenger.subscribe('KeyringController:unlock', () => {
|
|
797
|
-
__classPrivateFieldSet(this, _AssetsController_keyringUnlocked, true, "f");
|
|
798
|
-
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_updateActive).call(this);
|
|
799
|
-
});
|
|
800
|
-
this.messenger.subscribe('KeyringController:lock', () => {
|
|
801
|
-
__classPrivateFieldSet(this, _AssetsController_keyringUnlocked, false, "f");
|
|
802
|
-
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_updateActive).call(this);
|
|
803
|
-
});
|
|
804
|
-
}, _AssetsController_updateActive = function _AssetsController_updateActive() {
|
|
805
|
-
const shouldRun = __classPrivateFieldGet(this, _AssetsController_uiOpen, "f") && __classPrivateFieldGet(this, _AssetsController_keyringUnlocked, "f");
|
|
806
|
-
if (shouldRun) {
|
|
807
|
-
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_start).call(this);
|
|
808
|
-
}
|
|
809
|
-
else {
|
|
810
|
-
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_stop).call(this);
|
|
811
|
-
}
|
|
702
|
+
// Keyring lifecycle: start when unlocked, stop when locked
|
|
703
|
+
this.messenger.subscribe('KeyringController:unlock', () => __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_start).call(this));
|
|
704
|
+
this.messenger.subscribe('KeyringController:lock', () => __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_stop).call(this));
|
|
812
705
|
}, _AssetsController_registerActionHandlers = function _AssetsController_registerActionHandlers() {
|
|
813
706
|
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
814
707
|
}, _AssetsController_executeMiddlewares =
|
|
@@ -866,8 +759,8 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
866
759
|
// STATE MANAGEMENT
|
|
867
760
|
// ============================================================================
|
|
868
761
|
async function _AssetsController_updateState(response) {
|
|
762
|
+
// Normalize asset IDs (checksum EVM addresses) before storing in state
|
|
869
763
|
const normalizedResponse = normalizeResponse(response);
|
|
870
|
-
const mode = normalizedResponse.updateMode ?? 'merge';
|
|
871
764
|
const releaseLock = await __classPrivateFieldGet(this, _AssetsController_controllerMutex, "f").acquire();
|
|
872
765
|
try {
|
|
873
766
|
const previousState = this.state;
|
|
@@ -893,27 +786,15 @@ async function _AssetsController_updateState(response) {
|
|
|
893
786
|
if (normalizedResponse.assetsBalance) {
|
|
894
787
|
for (const [accountId, accountBalances] of Object.entries(normalizedResponse.assetsBalance)) {
|
|
895
788
|
const previousBalances = previousState.assetsBalance[accountId] ?? {};
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
const next = {
|
|
901
|
-
...accountBalances,
|
|
902
|
-
};
|
|
903
|
-
for (const customId of customAssetIds) {
|
|
904
|
-
if (!(customId in next)) {
|
|
905
|
-
const prev = previousBalances[customId];
|
|
906
|
-
next[customId] =
|
|
907
|
-
prev ?? { amount: '0' };
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
return next;
|
|
911
|
-
})()
|
|
912
|
-
: { ...previousBalances, ...accountBalances };
|
|
913
|
-
for (const [assetId, balance] of Object.entries(effective)) {
|
|
789
|
+
if (!balances[accountId]) {
|
|
790
|
+
balances[accountId] = {};
|
|
791
|
+
}
|
|
792
|
+
for (const [assetId, balance] of Object.entries(accountBalances)) {
|
|
914
793
|
const previousBalance = previousBalances[assetId];
|
|
915
|
-
const
|
|
794
|
+
const balanceData = balance;
|
|
795
|
+
const newAmount = balanceData.amount;
|
|
916
796
|
const oldAmount = previousBalance?.amount;
|
|
797
|
+
// Track if balance actually changed
|
|
917
798
|
if (oldAmount !== newAmount) {
|
|
918
799
|
changedBalances.push({
|
|
919
800
|
accountId,
|
|
@@ -923,7 +804,7 @@ async function _AssetsController_updateState(response) {
|
|
|
923
804
|
});
|
|
924
805
|
}
|
|
925
806
|
}
|
|
926
|
-
balances[accountId]
|
|
807
|
+
Object.assign(balances[accountId], accountBalances);
|
|
927
808
|
}
|
|
928
809
|
}
|
|
929
810
|
// Update prices in state
|
|
@@ -1101,7 +982,7 @@ async function _AssetsController_updateState(response) {
|
|
|
1101
982
|
}
|
|
1102
983
|
__classPrivateFieldGet(this, _AssetsController_activeSubscriptions, "f").clear();
|
|
1103
984
|
}, _AssetsController_subscribeAssets = function _AssetsController_subscribeAssets() {
|
|
1104
|
-
if (__classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get).length === 0
|
|
985
|
+
if (__classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get).length === 0) {
|
|
1105
986
|
return;
|
|
1106
987
|
}
|
|
1107
988
|
// Subscribe to balance updates (batched by data source)
|