@metamask-previews/assets-controller 5.0.0-preview-61580fcee → 5.0.0-preview-5e1e04b55
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 +4 -9
- package/dist/AssetsController.cjs +28 -74
- package/dist/AssetsController.cjs.map +1 -1
- package/dist/AssetsController.d.cts +1 -2
- package/dist/AssetsController.d.cts.map +1 -1
- package/dist/AssetsController.d.mts +1 -2
- package/dist/AssetsController.d.mts.map +1 -1
- package/dist/AssetsController.mjs +28 -74
- package/dist/AssetsController.mjs.map +1 -1
- package/dist/data-sources/BackendWebsocketDataSource.cjs +29 -45
- 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 +29 -45
- package/dist/data-sources/BackendWebsocketDataSource.mjs.map +1 -1
- package/dist/data-sources/TokenDataSource.cjs +3 -12
- 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 +3 -12
- package/dist/data-sources/TokenDataSource.mjs.map +1 -1
- package/package.json +2 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,17 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Bump `@metamask/transaction-controller` from `^64.0.0` to `^64.1.0` ([#8432](https://github.com/MetaMask/core/pull/8432))
|
|
13
|
+
|
|
10
14
|
### Fixed
|
|
11
15
|
|
|
12
|
-
- `AssetsController` now re-subscribes to all data sources when `AccountTreeController` state changes after initial startup, ensuring snap accounts and their chains are included ([#8430](https://github.com/MetaMask/core/pull/8430))
|
|
13
|
-
- Previously, `#start()` would create subscriptions before snap accounts were available, and its idempotency guard prevented re-subscription when the full account list arrived.
|
|
14
|
-
- Added `#handleAccountTreeStateChange()` which forces a full re-subscription and re-fetch when the account tree updates, picking up all accounts including snaps.
|
|
15
|
-
- Added `AccountsController:getSelectedAccount` as a fallback in `#getSelectedAccounts()` for when the account tree is not yet initialized.
|
|
16
|
-
- `TokenDataSource` no longer filters out user-imported custom assets with the `MIN_TOKEN_OCCURRENCES` spam filter or Blockaid bulk scan ([#8430](https://github.com/MetaMask/core/pull/8430))
|
|
17
|
-
- Tokens present in `customAssets` state now bypass the EVM occurrence threshold and non-EVM Blockaid scan, ensuring manually imported assets always appear.
|
|
18
|
-
- `BackendWebsocketDataSource` now properly releases chains to `AccountsApiDataSource` when the websocket is disconnected or disabled ([#8430](https://github.com/MetaMask/core/pull/8430))
|
|
19
|
-
- Previously, `BackendWebsocketDataSource` eagerly claimed all supported chains on initialization regardless of connection state, preventing `AccountsApiDataSource` from polling.
|
|
20
|
-
- Chains are now only claimed when the websocket is connected. On disconnect, chains are released so the chain-claiming loop assigns them to `AccountsApiDataSource` for polling fallback. On reconnect, chains are reclaimed.
|
|
21
16
|
- `AssetsController` no longer silently skips asset fetching on startup for returning users ([#8412](https://github.com/MetaMask/core/pull/8412))
|
|
22
17
|
- Previously, `#start()` was called at keyring unlock before `AccountTreeController.init()` had built the account tree, causing `#selectedAccounts` to return an empty array and all subscriptions and fetches to be skipped. `selectedAccountGroupChange` does not fire when the persisted selected group is unchanged, leaving the controller idle.
|
|
23
18
|
- Now subscribes to `AccountTreeController:stateChange` (the base-controller event guaranteed to fire when `init()` calls `this.update()`), so the controller re-evaluates its active state once accounts are available.
|
|
@@ -13,7 +13,7 @@ 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_trace, _AssetsController_firstInitFetchReported, _AssetsController_stateSizeReported, _AssetsController_emitTrace, _AssetsController_emitStateSizeTrace, _AssetsController_uiOpen, _AssetsController_keyringUnlocked, _AssetsController_controllerMutex, _AssetsController_activeSubscriptions, _AssetsController_enabledChains,
|
|
16
|
+
var _AssetsController_instances, _AssetsController_isEnabled, _AssetsController_isBasicFunctionality, _AssetsController_defaultUpdateInterval, _AssetsController_trace, _AssetsController_firstInitFetchReported, _AssetsController_stateSizeReported, _AssetsController_emitTrace, _AssetsController_emitStateSizeTrace, _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_onActiveChainsUpdated, _AssetsController_initializeState, _AssetsController_extractEnabledChains, _AssetsController_normalizeChainReference, _AssetsController_subscribeToEvents, _AssetsController_updateActive, _AssetsController_registerActionHandlers, _AssetsController_handleActiveChainsUpdate, _AssetsController_executeMiddlewares, _AssetsController_resolveNativeAssetIds, _AssetsController_getNativeAssetIdsForEnabledChains, _AssetsController_getNativeAssetIdsForAccount, _AssetsController_ensureNativeBalancesDefaultZero, _AssetsController_updateState, _AssetsController_getAssetsFromState, _AssetsController_shouldHideNativeToken, _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");
|
|
@@ -247,12 +247,6 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
247
247
|
_AssetsController_activeSubscriptions.set(this, new Map());
|
|
248
248
|
/** Currently enabled chains from NetworkEnablementController */
|
|
249
249
|
_AssetsController_enabledChains.set(this, new Set());
|
|
250
|
-
/**
|
|
251
|
-
* Snapshot of account IDs that were active when the last subscription/fetch
|
|
252
|
-
* cycle ran. Used by #handleAccountTreeStateChange to skip redundant
|
|
253
|
-
* re-subscriptions when the account set hasn't actually changed.
|
|
254
|
-
*/
|
|
255
|
-
_AssetsController_lastKnownAccountIds.set(this, new Set());
|
|
256
250
|
_AssetsController_backendWebsocketDataSource.set(this, void 0);
|
|
257
251
|
_AssetsController_accountsApiDataSource.set(this, void 0);
|
|
258
252
|
_AssetsController_snapDataSource.set(this, void 0);
|
|
@@ -514,7 +508,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
514
508
|
* @returns Legacy-compatible state for transaction-pay-controller.
|
|
515
509
|
*/
|
|
516
510
|
getStateForTransactionPay() {
|
|
517
|
-
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "
|
|
511
|
+
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get);
|
|
518
512
|
const { nativeAssetIdentifiers } = this.messenger.call('NetworkEnablementController:getState');
|
|
519
513
|
const { networkConfigurationsByChainId } = this.messenger.call('NetworkController:getState');
|
|
520
514
|
return (0, utils_2.formatStateForTransactionPay)({
|
|
@@ -587,7 +581,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
587
581
|
}
|
|
588
582
|
});
|
|
589
583
|
// Fetch data for the newly added custom asset (merge to preserve other chains)
|
|
590
|
-
const account = __classPrivateFieldGet(this, _AssetsController_instances, "
|
|
584
|
+
const account = __classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get).find((a) => a.id === accountId);
|
|
591
585
|
if (account) {
|
|
592
586
|
const chainId = extractChainId(normalizedAssetId);
|
|
593
587
|
await this.getAssets([account], {
|
|
@@ -686,7 +680,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
686
680
|
if (!__classPrivateFieldGet(this, _AssetsController_isBasicFunctionality, "f").call(this)) {
|
|
687
681
|
return;
|
|
688
682
|
}
|
|
689
|
-
this.getAssets(__classPrivateFieldGet(this, _AssetsController_instances, "
|
|
683
|
+
this.getAssets(__classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get), {
|
|
690
684
|
forceUpdate: true,
|
|
691
685
|
dataTypes: ['price'],
|
|
692
686
|
assetsForPriceUpdate: Object.values(this.state.assetsBalance).flatMap((balances) => Object.keys(balances)),
|
|
@@ -711,11 +705,10 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
711
705
|
const subscriptionKey = 'ds:PriceDataSource';
|
|
712
706
|
const existingSubscription = __classPrivateFieldGet(this, _AssetsController_activeSubscriptions, "f").get(subscriptionKey);
|
|
713
707
|
const isUpdate = existingSubscription !== undefined;
|
|
714
|
-
const request = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_buildDataRequest).call(this, accounts, chainIds, {
|
|
715
|
-
dataTypes: ['price'],
|
|
716
|
-
});
|
|
717
708
|
const subscribeReq = {
|
|
718
|
-
request,
|
|
709
|
+
request: __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_buildDataRequest).call(this, accounts, chainIds, {
|
|
710
|
+
dataTypes: ['price'],
|
|
711
|
+
}),
|
|
719
712
|
subscriptionId: subscriptionKey,
|
|
720
713
|
isUpdate,
|
|
721
714
|
onAssetsUpdate: (response) => this.handleAssetsUpdate(response, 'PriceDataSource'),
|
|
@@ -843,7 +836,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
843
836
|
}
|
|
844
837
|
}
|
|
845
838
|
exports.AssetsController = AssetsController;
|
|
846
|
-
_AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctionality = new WeakMap(), _AssetsController_defaultUpdateInterval = new WeakMap(), _AssetsController_trace = new WeakMap(), _AssetsController_firstInitFetchReported = new WeakMap(), _AssetsController_stateSizeReported = new WeakMap(), _AssetsController_uiOpen = new WeakMap(), _AssetsController_keyringUnlocked = new WeakMap(), _AssetsController_controllerMutex = new WeakMap(), _AssetsController_activeSubscriptions = new WeakMap(), _AssetsController_enabledChains = new WeakMap(),
|
|
839
|
+
_AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctionality = new WeakMap(), _AssetsController_defaultUpdateInterval = new WeakMap(), _AssetsController_trace = new WeakMap(), _AssetsController_firstInitFetchReported = new WeakMap(), _AssetsController_stateSizeReported = 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_onActiveChainsUpdated = new WeakMap(), _AssetsController_instances = new WeakSet(), _AssetsController_emitTrace = function _AssetsController_emitTrace(name, data, tags = {
|
|
847
840
|
controller: 'AssetsController',
|
|
848
841
|
}) {
|
|
849
842
|
if (!__classPrivateFieldGet(this, _AssetsController_trace, "f")) {
|
|
@@ -889,16 +882,8 @@ _AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctional
|
|
|
889
882
|
price_entries: Object.keys(assetsPrice).length,
|
|
890
883
|
custom_asset_entries: customAssetEntries,
|
|
891
884
|
});
|
|
892
|
-
},
|
|
893
|
-
|
|
894
|
-
if (accounts.length > 0) {
|
|
895
|
-
return accounts;
|
|
896
|
-
}
|
|
897
|
-
const selectedAccount = this.messenger.call('AccountsController:getSelectedAccount');
|
|
898
|
-
if (selectedAccount) {
|
|
899
|
-
return [selectedAccount];
|
|
900
|
-
}
|
|
901
|
-
return [];
|
|
885
|
+
}, _AssetsController_selectedAccounts_get = function _AssetsController_selectedAccounts_get() {
|
|
886
|
+
return this.messenger.call('AccountTreeController:getAccountsFromSelectedAccountGroup');
|
|
902
887
|
}, _AssetsController_allBalanceDataSources_get = function _AssetsController_allBalanceDataSources_get() {
|
|
903
888
|
return [
|
|
904
889
|
__classPrivateFieldGet(this, _AssetsController_backendWebsocketDataSource, "f"),
|
|
@@ -951,7 +936,7 @@ _AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctional
|
|
|
951
936
|
// when init() calls this.update(). #start() is idempotent so
|
|
952
937
|
// repeated fires are safe.
|
|
953
938
|
this.messenger.subscribe('AccountTreeController:stateChange', () => {
|
|
954
|
-
__classPrivateFieldGet(this, _AssetsController_instances, "m",
|
|
939
|
+
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_updateActive).call(this);
|
|
955
940
|
});
|
|
956
941
|
// Subscribe to network enablement changes (only enabledNetworkMap)
|
|
957
942
|
this.messenger.subscribe('NetworkEnablementController:stateChange', ({ enabledNetworkMap }) => {
|
|
@@ -978,36 +963,6 @@ _AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctional
|
|
|
978
963
|
else {
|
|
979
964
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_stop).call(this);
|
|
980
965
|
}
|
|
981
|
-
}, _AssetsController_handleAccountTreeStateChange = function _AssetsController_handleAccountTreeStateChange() {
|
|
982
|
-
const shouldRun = __classPrivateFieldGet(this, _AssetsController_uiOpen, "f") && __classPrivateFieldGet(this, _AssetsController_keyringUnlocked, "f");
|
|
983
|
-
if (!shouldRun) {
|
|
984
|
-
return;
|
|
985
|
-
}
|
|
986
|
-
if (__classPrivateFieldGet(this, _AssetsController_activeSubscriptions, "f").size > 0) {
|
|
987
|
-
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this);
|
|
988
|
-
const currentIds = new Set(accounts.map((a) => a.id));
|
|
989
|
-
const accountsChanged = currentIds.size !== __classPrivateFieldGet(this, _AssetsController_lastKnownAccountIds, "f").size ||
|
|
990
|
-
[...currentIds].some((id) => !__classPrivateFieldGet(this, _AssetsController_lastKnownAccountIds, "f").has(id));
|
|
991
|
-
if (!accountsChanged) {
|
|
992
|
-
return;
|
|
993
|
-
}
|
|
994
|
-
log('Account tree changed with new accounts, re-subscribing', {
|
|
995
|
-
previousCount: __classPrivateFieldGet(this, _AssetsController_lastKnownAccountIds, "f").size,
|
|
996
|
-
currentCount: currentIds.size,
|
|
997
|
-
});
|
|
998
|
-
__classPrivateFieldSet(this, _AssetsController_lastKnownAccountIds, currentIds, "f");
|
|
999
|
-
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeAssets).call(this);
|
|
1000
|
-
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_ensureNativeBalancesDefaultZero).call(this);
|
|
1001
|
-
this.getAssets(accounts, {
|
|
1002
|
-
chainIds: [...__classPrivateFieldGet(this, _AssetsController_enabledChains, "f")],
|
|
1003
|
-
forceUpdate: true,
|
|
1004
|
-
}).catch((error) => {
|
|
1005
|
-
log('Failed to fetch assets after tree change', error);
|
|
1006
|
-
});
|
|
1007
|
-
}
|
|
1008
|
-
else {
|
|
1009
|
-
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_start).call(this);
|
|
1010
|
-
}
|
|
1011
966
|
}, _AssetsController_registerActionHandlers = function _AssetsController_registerActionHandlers() {
|
|
1012
967
|
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
1013
968
|
}, _AssetsController_handleActiveChainsUpdate = function _AssetsController_handleActiveChainsUpdate(dataSourceId, activeChains, previousChains) {
|
|
@@ -1028,11 +983,11 @@ _AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctional
|
|
|
1028
983
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeAssets).call(this);
|
|
1029
984
|
}
|
|
1030
985
|
// If chains were added and we have selected accounts, do one-time fetch
|
|
1031
|
-
if (addedChains.length > 0 && __classPrivateFieldGet(this, _AssetsController_instances, "
|
|
986
|
+
if (addedChains.length > 0 && __classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get).length > 0) {
|
|
1032
987
|
const addedEnabledChains = addedChains.filter((chain) => __classPrivateFieldGet(this, _AssetsController_enabledChains, "f").has(chain));
|
|
1033
988
|
if (addedEnabledChains.length > 0) {
|
|
1034
989
|
log('Fetching balances for newly added chains', { addedEnabledChains });
|
|
1035
|
-
this.getAssets(__classPrivateFieldGet(this, _AssetsController_instances, "
|
|
990
|
+
this.getAssets(__classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get), {
|
|
1036
991
|
chainIds: addedEnabledChains,
|
|
1037
992
|
forceUpdate: true,
|
|
1038
993
|
updateMode: 'merge',
|
|
@@ -1131,7 +1086,7 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1131
1086
|
}, _AssetsController_getNativeAssetIdsForAccount = function _AssetsController_getNativeAssetIdsForAccount(account) {
|
|
1132
1087
|
return __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_resolveNativeAssetIds).call(this, __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getEnabledChainsForAccount).call(this, account));
|
|
1133
1088
|
}, _AssetsController_ensureNativeBalancesDefaultZero = function _AssetsController_ensureNativeBalancesDefaultZero() {
|
|
1134
|
-
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "
|
|
1089
|
+
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get);
|
|
1135
1090
|
if (accounts.length === 0) {
|
|
1136
1091
|
return;
|
|
1137
1092
|
}
|
|
@@ -1220,7 +1175,7 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1220
1175
|
return next;
|
|
1221
1176
|
})();
|
|
1222
1177
|
// Ensure native tokens have an entry (0 if missing) for chains this account supports
|
|
1223
|
-
const account = __classPrivateFieldGet(this, _AssetsController_instances, "
|
|
1178
|
+
const account = __classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get).find((a) => a.id === accountId);
|
|
1224
1179
|
const nativeAssetIdsForAccount = account
|
|
1225
1180
|
? __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getNativeAssetIdsForAccount).call(this, account)
|
|
1226
1181
|
: __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getNativeAssetIdsForEnabledChains).call(this);
|
|
@@ -1398,7 +1353,7 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1398
1353
|
return 'fungible';
|
|
1399
1354
|
}
|
|
1400
1355
|
}, _AssetsController_start = function _AssetsController_start() {
|
|
1401
|
-
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "
|
|
1356
|
+
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get);
|
|
1402
1357
|
const chainIds = [...__classPrivateFieldGet(this, _AssetsController_enabledChains, "f")];
|
|
1403
1358
|
if (accounts.length === 0 || chainIds.length === 0) {
|
|
1404
1359
|
return;
|
|
@@ -1410,7 +1365,6 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1410
1365
|
selectedAccountCount: accounts.length,
|
|
1411
1366
|
enabledChainCount: chainIds.length,
|
|
1412
1367
|
});
|
|
1413
|
-
__classPrivateFieldSet(this, _AssetsController_lastKnownAccountIds, new Set(accounts.map((a) => a.id)), "f");
|
|
1414
1368
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeAssets).call(this);
|
|
1415
1369
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_ensureNativeBalancesDefaultZero).call(this);
|
|
1416
1370
|
this.getAssets(accounts, {
|
|
@@ -1426,7 +1380,6 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1426
1380
|
});
|
|
1427
1381
|
__classPrivateFieldSet(this, _AssetsController_firstInitFetchReported, false, "f");
|
|
1428
1382
|
__classPrivateFieldSet(this, _AssetsController_stateSizeReported, false, "f");
|
|
1429
|
-
__classPrivateFieldSet(this, _AssetsController_lastKnownAccountIds, new Set(), "f");
|
|
1430
1383
|
// Stop price subscription first (uses direct messenger call)
|
|
1431
1384
|
this.unsubscribeAssetsPrice();
|
|
1432
1385
|
// Stop balance subscriptions by properly notifying data sources via messenger
|
|
@@ -1449,21 +1402,23 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1449
1402
|
}
|
|
1450
1403
|
__classPrivateFieldGet(this, _AssetsController_activeSubscriptions, "f").clear();
|
|
1451
1404
|
}, _AssetsController_subscribeAssets = function _AssetsController_subscribeAssets() {
|
|
1452
|
-
|
|
1453
|
-
const enabledChains = [...__classPrivateFieldGet(this, _AssetsController_enabledChains, "f")];
|
|
1454
|
-
if (accounts.length === 0 || enabledChains.length === 0) {
|
|
1405
|
+
if (__classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get).length === 0 || __classPrivateFieldGet(this, _AssetsController_enabledChains, "f").size === 0) {
|
|
1455
1406
|
return;
|
|
1456
1407
|
}
|
|
1457
1408
|
// Subscribe to balance updates (batched by data source)
|
|
1458
|
-
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeAssetsBalance).call(this,
|
|
1409
|
+
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeAssetsBalance).call(this, __classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get), [
|
|
1410
|
+
...__classPrivateFieldGet(this, _AssetsController_enabledChains, "f"),
|
|
1411
|
+
]);
|
|
1459
1412
|
// Subscribe to staked balance updates (separate from regular balance chain-claiming)
|
|
1460
|
-
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeStakedBalance).call(this,
|
|
1413
|
+
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeStakedBalance).call(this, __classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get), [
|
|
1414
|
+
...__classPrivateFieldGet(this, _AssetsController_enabledChains, "f"),
|
|
1415
|
+
]);
|
|
1461
1416
|
// Subscribe to price updates for all assets held by selected accounts
|
|
1462
|
-
this.subscribeAssetsPrice(
|
|
1417
|
+
this.subscribeAssetsPrice(__classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get), [...__classPrivateFieldGet(this, _AssetsController_enabledChains, "f")]);
|
|
1463
1418
|
}, _AssetsController_subscribeAssetsBalance = function _AssetsController_subscribeAssetsBalance(accounts, chainIds) {
|
|
1464
1419
|
const chainToAccounts = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_buildChainToAccountsMap).call(this, accounts, new Set(chainIds));
|
|
1465
1420
|
const remainingChains = new Set(chainToAccounts.keys());
|
|
1466
|
-
// When basic functionality is on, use all balance data sources; when off, RPC only.
|
|
1421
|
+
// When basic functionality is on (getter true), use all balance data sources; when off (getter false), RPC only.
|
|
1467
1422
|
const balanceDataSources = __classPrivateFieldGet(this, _AssetsController_isBasicFunctionality, "f").call(this)
|
|
1468
1423
|
? __classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_allBalanceDataSources_get)
|
|
1469
1424
|
: [__classPrivateFieldGet(this, _AssetsController_rpcDataSource, "f")];
|
|
@@ -1611,12 +1566,11 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1611
1566
|
// EVENT HANDLERS
|
|
1612
1567
|
// ============================================================================
|
|
1613
1568
|
async function _AssetsController_handleAccountGroupChanged() {
|
|
1614
|
-
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "
|
|
1569
|
+
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get);
|
|
1615
1570
|
log('Account group changed', {
|
|
1616
1571
|
accountCount: accounts.length,
|
|
1617
1572
|
accountIds: accounts.map((a) => a.id),
|
|
1618
1573
|
});
|
|
1619
|
-
__classPrivateFieldSet(this, _AssetsController_lastKnownAccountIds, new Set(accounts.map((a) => a.id)), "f");
|
|
1620
1574
|
// Subscribe and fetch for the new account group
|
|
1621
1575
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeAssets).call(this);
|
|
1622
1576
|
if (accounts.length > 0) {
|
|
@@ -1655,8 +1609,8 @@ async function _AssetsController_handleAccountGroupChanged() {
|
|
|
1655
1609
|
// Refresh subscriptions for new chain set
|
|
1656
1610
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeAssets).call(this);
|
|
1657
1611
|
// Do one-time fetch for newly enabled chains; merge so we keep existing chain balances
|
|
1658
|
-
if (addedChains.length > 0 && __classPrivateFieldGet(this, _AssetsController_instances, "
|
|
1659
|
-
await this.getAssets(__classPrivateFieldGet(this, _AssetsController_instances, "
|
|
1612
|
+
if (addedChains.length > 0 && __classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get).length > 0) {
|
|
1613
|
+
await this.getAssets(__classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_selectedAccounts_get), {
|
|
1660
1614
|
chainIds: addedChains,
|
|
1661
1615
|
forceUpdate: true,
|
|
1662
1616
|
updateMode: 'merge',
|