@metamask-previews/assets-controller 2.0.2-preview-1e855a9f5 → 2.0.2-preview-17adacd
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 +19 -1
- package/dist/AssetsController-method-action-types.cjs.map +1 -1
- package/dist/AssetsController-method-action-types.d.cts +5 -0
- package/dist/AssetsController-method-action-types.d.cts.map +1 -1
- package/dist/AssetsController-method-action-types.d.mts +5 -0
- 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 +214 -36
- package/dist/AssetsController.cjs.map +1 -1
- package/dist/AssetsController.d.cts +40 -6
- package/dist/AssetsController.d.cts.map +1 -1
- package/dist/AssetsController.d.mts +40 -6
- package/dist/AssetsController.d.mts.map +1 -1
- package/dist/AssetsController.mjs +214 -36
- package/dist/AssetsController.mjs.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.cjs +1 -0
- 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 +1 -0
- package/dist/data-sources/AccountsApiDataSource.mjs.map +1 -1
- package/dist/data-sources/BackendWebsocketDataSource.cjs +16 -4
- 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 +13 -4
- package/dist/data-sources/BackendWebsocketDataSource.mjs.map +1 -1
- package/dist/data-sources/PriceDataSource.cjs +20 -14
- 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 +20 -14
- package/dist/data-sources/PriceDataSource.mjs.map +1 -1
- package/dist/data-sources/RpcDataSource.cjs +2 -0
- 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 +2 -0
- package/dist/data-sources/RpcDataSource.mjs.map +1 -1
- package/dist/data-sources/SnapDataSource.cjs +3 -2
- 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 +3 -2
- package/dist/data-sources/SnapDataSource.mjs.map +1 -1
- package/dist/data-sources/TokenDataSource.cjs +1 -0
- 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 +1 -0
- package/dist/data-sources/TokenDataSource.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/middlewares/DetectionMiddleware.cjs +44 -27
- package/dist/middlewares/DetectionMiddleware.cjs.map +1 -1
- package/dist/middlewares/DetectionMiddleware.d.cts +15 -9
- package/dist/middlewares/DetectionMiddleware.d.cts.map +1 -1
- package/dist/middlewares/DetectionMiddleware.d.mts +15 -9
- package/dist/middlewares/DetectionMiddleware.d.mts.map +1 -1
- package/dist/middlewares/DetectionMiddleware.mjs +44 -27
- package/dist/middlewares/DetectionMiddleware.mjs.map +1 -1
- package/dist/middlewares/ParallelMiddleware.cjs +216 -0
- package/dist/middlewares/ParallelMiddleware.cjs.map +1 -0
- package/dist/middlewares/ParallelMiddleware.d.cts +45 -0
- package/dist/middlewares/ParallelMiddleware.d.cts.map +1 -0
- package/dist/middlewares/ParallelMiddleware.d.mts +45 -0
- package/dist/middlewares/ParallelMiddleware.d.mts.map +1 -0
- package/dist/middlewares/ParallelMiddleware.mjs +214 -0
- package/dist/middlewares/ParallelMiddleware.mjs.map +1 -0
- package/dist/middlewares/index.cjs +5 -1
- package/dist/middlewares/index.cjs.map +1 -1
- package/dist/middlewares/index.d.cts +2 -0
- package/dist/middlewares/index.d.cts.map +1 -1
- package/dist/middlewares/index.d.mts +2 -0
- package/dist/middlewares/index.d.mts.map +1 -1
- package/dist/middlewares/index.mjs +1 -0
- package/dist/middlewares/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +16 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +16 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -7,10 +7,28 @@ 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
|
+
|
|
10
19
|
### Changed
|
|
11
20
|
|
|
12
|
-
- Bump `@metamask/transaction-controller` from `^62.17.1` to `^62.
|
|
21
|
+
- Bump `@metamask/transaction-controller` from `^62.17.1` to `^62.19.0` ([#8005](https://github.com/MetaMask/core/pull/8005), [#8031](https://github.com/MetaMask/core/pull/8031))
|
|
13
22
|
- 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
|
+
- Default `assetsBalance` to `0` for native tokens of each account's supported chains using `NetworkEnablementController.nativeAssetIdentifiers`, so native entries are always present in state even before data sources respond ([#8036](https://github.com/MetaMask/core/pull/8036))
|
|
28
|
+
- Auto-select `'merge'` update mode in `getAssets` when `chainIds` is a subset of enabled chains, preventing partial-chain fetches (e.g. after a swap, adding a custom asset, or data-source chain changes) from wiping balances of other chains ([#8036](https://github.com/MetaMask/core/pull/8036))
|
|
29
|
+
- 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))
|
|
30
|
+
- 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))
|
|
31
|
+
- 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))
|
|
14
32
|
|
|
15
33
|
## [2.0.2]
|
|
16
34
|
|
|
@@ -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 * @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"]}
|
|
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 * 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 *\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,8 +24,13 @@ 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
|
+
*
|
|
27
31
|
* @param accountId - The account ID to add the custom asset for.
|
|
28
32
|
* @param assetId - The CAIP-19 asset ID to add.
|
|
33
|
+
* @param pendingMetadata - Optional token metadata from the UI (pendingTokens format).
|
|
29
34
|
*/
|
|
30
35
|
export type AssetsControllerAddCustomAssetAction = {
|
|
31
36
|
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;;;;;;;;;;;;GAYG;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,8 +24,13 @@ 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
|
+
*
|
|
27
31
|
* @param accountId - The account ID to add the custom asset for.
|
|
28
32
|
* @param assetId - The CAIP-19 asset ID to add.
|
|
33
|
+
* @param pendingMetadata - Optional token metadata from the UI (pendingTokens format).
|
|
29
34
|
*/
|
|
30
35
|
export type AssetsControllerAddCustomAssetAction = {
|
|
31
36
|
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;;;;;;;;;;;;GAYG;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 * @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"]}
|
|
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 * 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 *\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,10 +13,11 @@ 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, _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;
|
|
16
|
+
var _AssetsController_instances, _AssetsController_isEnabled, _AssetsController_isBasicFunctionality, _AssetsController_defaultUpdateInterval, _AssetsController_trackMetaMetricsEvent, _AssetsController_firstInitFetchReported, _AssetsController_uiOpen, _AssetsController_keyringUnlocked, _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_updateActive, _AssetsController_registerActionHandlers, _AssetsController_executeMiddlewares, _AssetsController_resolveNativeAssetIds, _AssetsController_getNativeAssetIdsForEnabledChains, _AssetsController_getNativeAssetIdsForAccount, _AssetsController_ensureNativeBalancesDefaultZero, _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");
|
|
20
21
|
const utils_1 = require("@metamask/utils");
|
|
21
22
|
const async_mutex_1 = require("async-mutex");
|
|
22
23
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
@@ -30,6 +31,7 @@ const StakedBalanceDataSource_1 = require("./data-sources/StakedBalanceDataSourc
|
|
|
30
31
|
const TokenDataSource_1 = require("./data-sources/TokenDataSource.cjs");
|
|
31
32
|
const logger_1 = require("./logger.cjs");
|
|
32
33
|
const DetectionMiddleware_1 = require("./middlewares/DetectionMiddleware.cjs");
|
|
34
|
+
const ParallelMiddleware_1 = require("./middlewares/ParallelMiddleware.cjs");
|
|
33
35
|
const utils_2 = require("./utils.cjs");
|
|
34
36
|
// ============================================================================
|
|
35
37
|
// CONTROLLER CONSTANTS
|
|
@@ -62,6 +64,7 @@ function getDefaultAssetsControllerState() {
|
|
|
62
64
|
assetsPrice: {},
|
|
63
65
|
customAssets: {},
|
|
64
66
|
assetPreferences: {},
|
|
67
|
+
selectedCurrency: 'usd',
|
|
65
68
|
};
|
|
66
69
|
}
|
|
67
70
|
exports.getDefaultAssetsControllerState = getDefaultAssetsControllerState;
|
|
@@ -99,6 +102,12 @@ const stateMetadata = {
|
|
|
99
102
|
includeInDebugSnapshot: false,
|
|
100
103
|
usedInUi: true,
|
|
101
104
|
},
|
|
105
|
+
selectedCurrency: {
|
|
106
|
+
persist: true,
|
|
107
|
+
includeInStateLogs: false,
|
|
108
|
+
includeInDebugSnapshot: false,
|
|
109
|
+
usedInUi: true,
|
|
110
|
+
},
|
|
102
111
|
};
|
|
103
112
|
// ============================================================================
|
|
104
113
|
// HELPER FUNCTIONS
|
|
@@ -152,6 +161,9 @@ function normalizeResponse(response) {
|
|
|
152
161
|
if (response.errors) {
|
|
153
162
|
normalized.errors = { ...response.errors };
|
|
154
163
|
}
|
|
164
|
+
if (response.updateMode) {
|
|
165
|
+
normalized.updateMode = response.updateMode;
|
|
166
|
+
}
|
|
155
167
|
return normalized;
|
|
156
168
|
}
|
|
157
169
|
// ============================================================================
|
|
@@ -173,8 +185,10 @@ function normalizeResponse(response) {
|
|
|
173
185
|
* based on which chains they support. When active chains change, the controller
|
|
174
186
|
* dynamically adjusts subscriptions.
|
|
175
187
|
*
|
|
176
|
-
* 4. **Keyring Lifecycle**:
|
|
177
|
-
*
|
|
188
|
+
* 4. **Client + Keyring Lifecycle**: Starts subscriptions only when both the UI is
|
|
189
|
+
* open (ClientController) and the wallet is unlocked (KeyringController).
|
|
190
|
+
* Stops when either the UI closes or the keyring locks. See client-controller
|
|
191
|
+
* README for the combined pattern.
|
|
178
192
|
*
|
|
179
193
|
* ## Architecture
|
|
180
194
|
*
|
|
@@ -204,6 +218,10 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
204
218
|
_AssetsController_trackMetaMetricsEvent.set(this, void 0);
|
|
205
219
|
/** Whether we have already reported first init fetch for this session (reset on #stop). */
|
|
206
220
|
_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);
|
|
207
225
|
_AssetsController_controllerMutex.set(this, new async_mutex_1.Mutex());
|
|
208
226
|
/**
|
|
209
227
|
* Active balance subscriptions keyed by account ID.
|
|
@@ -260,6 +278,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
260
278
|
}), "f");
|
|
261
279
|
__classPrivateFieldSet(this, _AssetsController_priceDataSource, new PriceDataSource_1.PriceDataSource({
|
|
262
280
|
queryApiClient,
|
|
281
|
+
getSelectedCurrency: () => this.state.selectedCurrency,
|
|
263
282
|
...priceDataSourceConfig,
|
|
264
283
|
}), "f");
|
|
265
284
|
__classPrivateFieldSet(this, _AssetsController_detectionMiddleware, new DetectionMiddleware_1.DetectionMiddleware(), "f");
|
|
@@ -273,7 +292,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
273
292
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_initializeState).call(this);
|
|
274
293
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeToEvents).call(this);
|
|
275
294
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_registerActionHandlers).call(this);
|
|
276
|
-
// Subscriptions start only
|
|
295
|
+
// Subscriptions start only when both UI is open and keyring unlocked -> #updateActive().
|
|
277
296
|
// Subscribe to basic-functionality changes after construction so a synchronous
|
|
278
297
|
// onChange during subscribe cannot run before data sources are initialized.
|
|
279
298
|
if (subscribeToBasicFunctionalityChange) {
|
|
@@ -324,6 +343,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
324
343
|
this.getAssets(__classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get), {
|
|
325
344
|
chainIds: addedEnabledChains,
|
|
326
345
|
forceUpdate: true,
|
|
346
|
+
updateMode: 'merge',
|
|
327
347
|
}).catch((error) => {
|
|
328
348
|
log('Failed to fetch balance for added chains', { error });
|
|
329
349
|
});
|
|
@@ -337,6 +357,9 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
337
357
|
const chainIds = options?.chainIds ?? [...__classPrivateFieldGet(this, _AssetsController_enabledChains, "f")];
|
|
338
358
|
const assetTypes = options?.assetTypes ?? ['fungible'];
|
|
339
359
|
const dataTypes = options?.dataTypes ?? ['balance', 'metadata', 'price'];
|
|
360
|
+
if (accounts.length === 0 || chainIds.length === 0) {
|
|
361
|
+
return __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getAssetsFromState).call(this, accounts, chainIds, assetTypes);
|
|
362
|
+
}
|
|
340
363
|
// Collect custom assets for all requested accounts
|
|
341
364
|
const customAssets = [];
|
|
342
365
|
for (const account of accounts) {
|
|
@@ -350,16 +373,21 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
350
373
|
dataTypes,
|
|
351
374
|
customAssets: customAssets.length > 0 ? customAssets : undefined,
|
|
352
375
|
forceUpdate: true,
|
|
376
|
+
assetsForPriceUpdate: options?.assetsForPriceUpdate,
|
|
353
377
|
});
|
|
354
378
|
const sources = __classPrivateFieldGet(this, _AssetsController_isBasicFunctionality, "f").call(this)
|
|
355
379
|
? [
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
380
|
+
(0, ParallelMiddleware_1.createParallelBalanceMiddleware)([
|
|
381
|
+
__classPrivateFieldGet(this, _AssetsController_accountsApiDataSource, "f"),
|
|
382
|
+
__classPrivateFieldGet(this, _AssetsController_snapDataSource, "f"),
|
|
383
|
+
__classPrivateFieldGet(this, _AssetsController_rpcDataSource, "f"),
|
|
384
|
+
__classPrivateFieldGet(this, _AssetsController_stakedBalanceDataSource, "f"),
|
|
385
|
+
]),
|
|
360
386
|
__classPrivateFieldGet(this, _AssetsController_detectionMiddleware, "f"),
|
|
361
|
-
|
|
362
|
-
|
|
387
|
+
(0, ParallelMiddleware_1.createParallelMiddleware)([
|
|
388
|
+
__classPrivateFieldGet(this, _AssetsController_tokenDataSource, "f"),
|
|
389
|
+
__classPrivateFieldGet(this, _AssetsController_priceDataSource, "f"),
|
|
390
|
+
]),
|
|
363
391
|
]
|
|
364
392
|
: [
|
|
365
393
|
__classPrivateFieldGet(this, _AssetsController_rpcDataSource, "f"),
|
|
@@ -367,7 +395,12 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
367
395
|
__classPrivateFieldGet(this, _AssetsController_detectionMiddleware, "f"),
|
|
368
396
|
];
|
|
369
397
|
const { response, durationByDataSource } = await __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_executeMiddlewares).call(this, sources, request);
|
|
370
|
-
|
|
398
|
+
// Default to 'merge' when fetching a subset of chains so we don't wipe
|
|
399
|
+
// balances from chains that weren't included in this fetch.
|
|
400
|
+
const isPartialChainFetch = options?.chainIds !== undefined &&
|
|
401
|
+
options.chainIds.length < __classPrivateFieldGet(this, _AssetsController_enabledChains, "f").size;
|
|
402
|
+
const updateMode = options?.updateMode ?? (isPartialChainFetch ? 'merge' : 'full');
|
|
403
|
+
await __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_updateState).call(this, { ...response, updateMode });
|
|
371
404
|
if (__classPrivateFieldGet(this, _AssetsController_trackMetaMetricsEvent, "f") && !__classPrivateFieldGet(this, _AssetsController_firstInitFetchReported, "f")) {
|
|
372
405
|
__classPrivateFieldSet(this, _AssetsController_firstInitFetchReported, true, "f");
|
|
373
406
|
const durationMs = Date.now() - startTime;
|
|
@@ -378,7 +411,8 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
378
411
|
});
|
|
379
412
|
}
|
|
380
413
|
}
|
|
381
|
-
|
|
414
|
+
const result = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getAssetsFromState).call(this, accounts, chainIds, assetTypes);
|
|
415
|
+
return result;
|
|
382
416
|
}
|
|
383
417
|
async getAssetsBalance(accounts, options) {
|
|
384
418
|
// Reuse getAssets with dataTypes: ['balance'] only
|
|
@@ -429,10 +463,15 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
429
463
|
* Custom assets are included in subscription and fetch operations.
|
|
430
464
|
* Adding a custom asset also unhides it if it was previously hidden.
|
|
431
465
|
*
|
|
466
|
+
* When `pendingMetadata` is provided (e.g. from the extension's pending-tokens
|
|
467
|
+
* flow), the token metadata is persisted immediately into `assetsInfo` so the
|
|
468
|
+
* UI can render it without waiting for the next pipeline fetch.
|
|
469
|
+
*
|
|
432
470
|
* @param accountId - The account ID to add the custom asset for.
|
|
433
471
|
* @param assetId - The CAIP-19 asset ID to add.
|
|
472
|
+
* @param pendingMetadata - Optional token metadata from the UI (pendingTokens format).
|
|
434
473
|
*/
|
|
435
|
-
async addCustomAsset(accountId, assetId) {
|
|
474
|
+
async addCustomAsset(accountId, assetId, pendingMetadata) {
|
|
436
475
|
const normalizedAssetId = (0, utils_2.normalizeAssetId)(assetId);
|
|
437
476
|
log('Adding custom asset', { accountId, assetId: normalizedAssetId });
|
|
438
477
|
this.update((state) => {
|
|
@@ -452,14 +491,37 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
452
491
|
delete state.assetPreferences[normalizedAssetId];
|
|
453
492
|
}
|
|
454
493
|
}
|
|
494
|
+
// Persist metadata from the UI so the token is immediately renderable
|
|
495
|
+
if (pendingMetadata) {
|
|
496
|
+
const parsed = (0, utils_1.parseCaipAssetType)(normalizedAssetId);
|
|
497
|
+
let tokenType = 'erc20';
|
|
498
|
+
if (parsed.assetNamespace === 'slip44') {
|
|
499
|
+
tokenType = 'native';
|
|
500
|
+
}
|
|
501
|
+
else if (parsed.assetNamespace === 'spl') {
|
|
502
|
+
tokenType = 'spl';
|
|
503
|
+
}
|
|
504
|
+
const assetMetadata = {
|
|
505
|
+
type: tokenType,
|
|
506
|
+
symbol: pendingMetadata.symbol,
|
|
507
|
+
name: pendingMetadata.name,
|
|
508
|
+
decimals: pendingMetadata.decimals,
|
|
509
|
+
image: pendingMetadata.iconUrl,
|
|
510
|
+
aggregators: pendingMetadata.aggregators,
|
|
511
|
+
occurrences: pendingMetadata.occurrences,
|
|
512
|
+
};
|
|
513
|
+
state.assetsInfo[normalizedAssetId] =
|
|
514
|
+
assetMetadata;
|
|
515
|
+
}
|
|
455
516
|
});
|
|
456
|
-
// Fetch data for the newly added custom asset
|
|
517
|
+
// Fetch data for the newly added custom asset (merge to preserve other chains)
|
|
457
518
|
const account = __classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get).find((a) => a.id === accountId);
|
|
458
519
|
if (account) {
|
|
459
520
|
const chainId = extractChainId(normalizedAssetId);
|
|
460
521
|
await this.getAssets([account], {
|
|
461
522
|
chainIds: [chainId],
|
|
462
523
|
forceUpdate: true,
|
|
524
|
+
updateMode: 'merge',
|
|
463
525
|
});
|
|
464
526
|
}
|
|
465
527
|
}
|
|
@@ -530,6 +592,34 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
530
592
|
});
|
|
531
593
|
}
|
|
532
594
|
// ============================================================================
|
|
595
|
+
// CURRENT CURRENCY MANAGEMENT
|
|
596
|
+
// ============================================================================
|
|
597
|
+
/**
|
|
598
|
+
* Set the current currency.
|
|
599
|
+
*
|
|
600
|
+
* @param selectedCurrency - The ISO 4217 currency code to set.
|
|
601
|
+
*/
|
|
602
|
+
setSelectedCurrency(selectedCurrency) {
|
|
603
|
+
const previousCurrency = this.state.selectedCurrency;
|
|
604
|
+
if (previousCurrency === selectedCurrency) {
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
this.update((state) => {
|
|
608
|
+
state.selectedCurrency = selectedCurrency;
|
|
609
|
+
});
|
|
610
|
+
log('Current currency changed', {
|
|
611
|
+
previousCurrency,
|
|
612
|
+
selectedCurrency,
|
|
613
|
+
});
|
|
614
|
+
this.getAssets(__classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get), {
|
|
615
|
+
forceUpdate: true,
|
|
616
|
+
dataTypes: ['price'],
|
|
617
|
+
assetsForPriceUpdate: Object.values(this.state.assetsBalance).flatMap((balances) => Object.keys(balances)),
|
|
618
|
+
}).catch((error) => {
|
|
619
|
+
log('Failed to fetch asset prices after current currency change', error);
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
// ============================================================================
|
|
533
623
|
// SUBSCRIPTIONS
|
|
534
624
|
// ============================================================================
|
|
535
625
|
/**
|
|
@@ -607,9 +697,15 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
607
697
|
hasBalance: Boolean(response.assetsBalance),
|
|
608
698
|
hasPrice: Boolean(response.assetsPrice),
|
|
609
699
|
});
|
|
610
|
-
// Run through enrichment middlewares (
|
|
700
|
+
// Run through enrichment middlewares (Detection, then Token + Price in parallel)
|
|
611
701
|
// Include 'metadata' in dataTypes so TokenDataSource runs to enrich detected assets
|
|
612
|
-
const { response: enrichedResponse } = await __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_executeMiddlewares).call(this, [
|
|
702
|
+
const { response: enrichedResponse } = await __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_executeMiddlewares).call(this, [
|
|
703
|
+
__classPrivateFieldGet(this, _AssetsController_detectionMiddleware, "f"),
|
|
704
|
+
(0, ParallelMiddleware_1.createParallelMiddleware)([
|
|
705
|
+
__classPrivateFieldGet(this, _AssetsController_tokenDataSource, "f"),
|
|
706
|
+
__classPrivateFieldGet(this, _AssetsController_priceDataSource, "f"),
|
|
707
|
+
]),
|
|
708
|
+
], request ?? {
|
|
613
709
|
accountsWithSupportedChains: [],
|
|
614
710
|
chainIds: [],
|
|
615
711
|
dataTypes: ['balance', 'metadata', 'price'],
|
|
@@ -649,7 +745,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
649
745
|
}
|
|
650
746
|
}
|
|
651
747
|
exports.AssetsController = AssetsController;
|
|
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() {
|
|
748
|
+
_AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctionality = new WeakMap(), _AssetsController_defaultUpdateInterval = new WeakMap(), _AssetsController_trackMetaMetricsEvent = new WeakMap(), _AssetsController_firstInitFetchReported = new WeakMap(), _AssetsController_uiOpen = new WeakMap(), _AssetsController_keyringUnlocked = 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() {
|
|
653
749
|
return this.messenger.call('AccountTreeController:getAccountsFromSelectedAccountGroup');
|
|
654
750
|
}, _AssetsController_allBalanceDataSources_get = function _AssetsController_allBalanceDataSources_get() {
|
|
655
751
|
return [
|
|
@@ -699,9 +795,27 @@ _AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctional
|
|
|
699
795
|
this.messenger.subscribe('NetworkEnablementController:stateChange', ({ enabledNetworkMap }) => {
|
|
700
796
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_handleEnabledNetworksChanged).call(this, enabledNetworkMap).catch(console.error);
|
|
701
797
|
});
|
|
702
|
-
// Keyring lifecycle:
|
|
703
|
-
this.messenger.subscribe('
|
|
704
|
-
|
|
798
|
+
// Client + Keyring lifecycle: only run when UI is open AND keyring is unlocked
|
|
799
|
+
this.messenger.subscribe('ClientController:stateChange', (isUiOpen) => {
|
|
800
|
+
__classPrivateFieldSet(this, _AssetsController_uiOpen, isUiOpen, "f");
|
|
801
|
+
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_updateActive).call(this);
|
|
802
|
+
}, client_controller_1.clientControllerSelectors.selectIsUiOpen);
|
|
803
|
+
this.messenger.subscribe('KeyringController:unlock', () => {
|
|
804
|
+
__classPrivateFieldSet(this, _AssetsController_keyringUnlocked, true, "f");
|
|
805
|
+
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_updateActive).call(this);
|
|
806
|
+
});
|
|
807
|
+
this.messenger.subscribe('KeyringController:lock', () => {
|
|
808
|
+
__classPrivateFieldSet(this, _AssetsController_keyringUnlocked, false, "f");
|
|
809
|
+
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_updateActive).call(this);
|
|
810
|
+
});
|
|
811
|
+
}, _AssetsController_updateActive = function _AssetsController_updateActive() {
|
|
812
|
+
const shouldRun = __classPrivateFieldGet(this, _AssetsController_uiOpen, "f") && __classPrivateFieldGet(this, _AssetsController_keyringUnlocked, "f");
|
|
813
|
+
if (shouldRun) {
|
|
814
|
+
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_start).call(this);
|
|
815
|
+
}
|
|
816
|
+
else {
|
|
817
|
+
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_stop).call(this);
|
|
818
|
+
}
|
|
705
819
|
}, _AssetsController_registerActionHandlers = function _AssetsController_registerActionHandlers() {
|
|
706
820
|
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
707
821
|
}, _AssetsController_executeMiddlewares =
|
|
@@ -754,13 +868,46 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
754
868
|
}
|
|
755
869
|
}
|
|
756
870
|
return { response: result.response, durationByDataSource };
|
|
757
|
-
},
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
871
|
+
}, _AssetsController_resolveNativeAssetIds = function _AssetsController_resolveNativeAssetIds(chains) {
|
|
872
|
+
const { nativeAssetIdentifiers } = this.messenger.call('NetworkEnablementController:getState');
|
|
873
|
+
const ids = [];
|
|
874
|
+
for (const chainId of chains) {
|
|
875
|
+
const nativeId = nativeAssetIdentifiers?.[chainId];
|
|
876
|
+
if (nativeId) {
|
|
877
|
+
ids.push(nativeId);
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
return ids;
|
|
881
|
+
}, _AssetsController_getNativeAssetIdsForEnabledChains = function _AssetsController_getNativeAssetIdsForEnabledChains() {
|
|
882
|
+
return __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_resolveNativeAssetIds).call(this, __classPrivateFieldGet(this, _AssetsController_enabledChains, "f"));
|
|
883
|
+
}, _AssetsController_getNativeAssetIdsForAccount = function _AssetsController_getNativeAssetIdsForAccount(account) {
|
|
884
|
+
return __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_resolveNativeAssetIds).call(this, __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getEnabledChainsForAccount).call(this, account));
|
|
885
|
+
}, _AssetsController_ensureNativeBalancesDefaultZero = function _AssetsController_ensureNativeBalancesDefaultZero() {
|
|
886
|
+
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get);
|
|
887
|
+
if (accounts.length === 0) {
|
|
888
|
+
return;
|
|
889
|
+
}
|
|
890
|
+
this.update((state) => {
|
|
891
|
+
const balances = state.assetsBalance;
|
|
892
|
+
for (const account of accounts) {
|
|
893
|
+
const accountId = account.id;
|
|
894
|
+
const nativeAssetIds = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getNativeAssetIdsForAccount).call(this, account);
|
|
895
|
+
if (nativeAssetIds.length === 0) {
|
|
896
|
+
continue;
|
|
897
|
+
}
|
|
898
|
+
if (!balances[accountId]) {
|
|
899
|
+
balances[accountId] = {};
|
|
900
|
+
}
|
|
901
|
+
for (const nativeAssetId of nativeAssetIds) {
|
|
902
|
+
if (!(nativeAssetId in balances[accountId])) {
|
|
903
|
+
balances[accountId][nativeAssetId] = { amount: '0' };
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
});
|
|
908
|
+
}, _AssetsController_updateState = async function _AssetsController_updateState(response) {
|
|
763
909
|
const normalizedResponse = normalizeResponse(response);
|
|
910
|
+
const mode = normalizedResponse.updateMode ?? 'merge';
|
|
764
911
|
const releaseLock = await __classPrivateFieldGet(this, _AssetsController_controllerMutex, "f").acquire();
|
|
765
912
|
try {
|
|
766
913
|
const previousState = this.state;
|
|
@@ -786,16 +933,43 @@ async function _AssetsController_updateState(response) {
|
|
|
786
933
|
if (normalizedResponse.assetsBalance) {
|
|
787
934
|
for (const [accountId, accountBalances] of Object.entries(normalizedResponse.assetsBalance)) {
|
|
788
935
|
const previousBalances = previousState.assetsBalance[accountId] ?? {};
|
|
789
|
-
|
|
790
|
-
|
|
936
|
+
const customAssetIds = state.customAssets[accountId] ?? [];
|
|
937
|
+
// Full: response is authoritative; preserve custom assets not in response.
|
|
938
|
+
// Merge: response overlays previous balances.
|
|
939
|
+
// Callers that fetch partial data (e.g. newly added chains) must set updateMode: 'merge'.
|
|
940
|
+
const effective = mode === 'merge'
|
|
941
|
+
? { ...previousBalances, ...accountBalances }
|
|
942
|
+
: (() => {
|
|
943
|
+
const next = {
|
|
944
|
+
...accountBalances,
|
|
945
|
+
};
|
|
946
|
+
for (const customId of customAssetIds) {
|
|
947
|
+
if (!(customId in next)) {
|
|
948
|
+
const prev = previousBalances[customId];
|
|
949
|
+
next[customId] =
|
|
950
|
+
prev ?? { amount: '0' };
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
return next;
|
|
954
|
+
})();
|
|
955
|
+
// Ensure native tokens have an entry (0 if missing) for chains this account supports
|
|
956
|
+
const account = __classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get).find((a) => a.id === accountId);
|
|
957
|
+
const nativeAssetIdsForAccount = account
|
|
958
|
+
? __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getNativeAssetIdsForAccount).call(this, account)
|
|
959
|
+
: __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getNativeAssetIdsForEnabledChains).call(this);
|
|
960
|
+
for (const nativeAssetId of nativeAssetIdsForAccount) {
|
|
961
|
+
if (!(nativeAssetId in effective)) {
|
|
962
|
+
effective[nativeAssetId] = { amount: '0' };
|
|
963
|
+
}
|
|
791
964
|
}
|
|
792
|
-
for (const [assetId, balance] of Object.entries(
|
|
965
|
+
for (const [assetId, balance] of Object.entries(effective)) {
|
|
793
966
|
const previousBalance = previousBalances[assetId];
|
|
794
|
-
const
|
|
795
|
-
const newAmount = balanceData.amount;
|
|
967
|
+
const newAmount = balance.amount;
|
|
796
968
|
const oldAmount = previousBalance?.amount;
|
|
797
|
-
|
|
798
|
-
|
|
969
|
+
const isNewDefaultNativeZero = oldAmount === undefined &&
|
|
970
|
+
newAmount === '0' &&
|
|
971
|
+
nativeAssetIdsForAccount.includes(assetId);
|
|
972
|
+
if (oldAmount !== newAmount && !isNewDefaultNativeZero) {
|
|
799
973
|
changedBalances.push({
|
|
800
974
|
accountId,
|
|
801
975
|
assetId,
|
|
@@ -804,7 +978,7 @@ async function _AssetsController_updateState(response) {
|
|
|
804
978
|
});
|
|
805
979
|
}
|
|
806
980
|
}
|
|
807
|
-
|
|
981
|
+
balances[accountId] = effective;
|
|
808
982
|
}
|
|
809
983
|
}
|
|
810
984
|
// Update prices in state
|
|
@@ -948,6 +1122,7 @@ async function _AssetsController_updateState(response) {
|
|
|
948
1122
|
enabledChainCount: __classPrivateFieldGet(this, _AssetsController_enabledChains, "f").size,
|
|
949
1123
|
});
|
|
950
1124
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeAssets).call(this);
|
|
1125
|
+
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_ensureNativeBalancesDefaultZero).call(this);
|
|
951
1126
|
this.getAssets(__classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get), {
|
|
952
1127
|
chainIds: [...__classPrivateFieldGet(this, _AssetsController_enabledChains, "f")],
|
|
953
1128
|
forceUpdate: true,
|
|
@@ -982,7 +1157,7 @@ async function _AssetsController_updateState(response) {
|
|
|
982
1157
|
}
|
|
983
1158
|
__classPrivateFieldGet(this, _AssetsController_activeSubscriptions, "f").clear();
|
|
984
1159
|
}, _AssetsController_subscribeAssets = function _AssetsController_subscribeAssets() {
|
|
985
|
-
if (__classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get).length === 0) {
|
|
1160
|
+
if (__classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get).length === 0 || __classPrivateFieldGet(this, _AssetsController_enabledChains, "f").size === 0) {
|
|
986
1161
|
return;
|
|
987
1162
|
}
|
|
988
1163
|
// Subscribe to balance updates (batched by data source)
|
|
@@ -1155,6 +1330,7 @@ async function _AssetsController_handleAccountGroupChanged() {
|
|
|
1155
1330
|
forceUpdate: true,
|
|
1156
1331
|
});
|
|
1157
1332
|
}
|
|
1333
|
+
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_ensureNativeBalancesDefaultZero).call(this);
|
|
1158
1334
|
}, _AssetsController_handleEnabledNetworksChanged = async function _AssetsController_handleEnabledNetworksChanged(enabledNetworkMap) {
|
|
1159
1335
|
const previousChains = __classPrivateFieldGet(this, _AssetsController_enabledChains, "f");
|
|
1160
1336
|
__classPrivateFieldSet(this, _AssetsController_enabledChains, __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_extractEnabledChains).call(this, enabledNetworkMap), "f");
|
|
@@ -1183,12 +1359,14 @@ async function _AssetsController_handleAccountGroupChanged() {
|
|
|
1183
1359
|
// The data will simply not be updated until the network is re-enabled.
|
|
1184
1360
|
// Refresh subscriptions for new chain set
|
|
1185
1361
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeAssets).call(this);
|
|
1186
|
-
// Do one-time fetch for newly enabled chains
|
|
1362
|
+
// Do one-time fetch for newly enabled chains; merge so we keep existing chain balances
|
|
1187
1363
|
if (addedChains.length > 0 && __classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get).length > 0) {
|
|
1188
1364
|
await this.getAssets(__classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get), {
|
|
1189
1365
|
chainIds: addedChains,
|
|
1190
1366
|
forceUpdate: true,
|
|
1367
|
+
updateMode: 'merge',
|
|
1191
1368
|
});
|
|
1192
1369
|
}
|
|
1370
|
+
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_ensureNativeBalancesDefaultZero).call(this);
|
|
1193
1371
|
};
|
|
1194
1372
|
//# sourceMappingURL=AssetsController.cjs.map
|