@metamask-previews/assets-controller 5.0.0-preview-aa31fa3 → 5.0.0-preview-61580fcee
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/dist/AssetsController.cjs +74 -28
- package/dist/AssetsController.cjs.map +1 -1
- package/dist/AssetsController.d.cts +2 -1
- package/dist/AssetsController.d.cts.map +1 -1
- package/dist/AssetsController.d.mts +2 -1
- package/dist/AssetsController.d.mts.map +1 -1
- package/dist/AssetsController.mjs +74 -28
- package/dist/AssetsController.mjs.map +1 -1
- package/dist/data-sources/BackendWebsocketDataSource.cjs +45 -29
- 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 +45 -29
- package/dist/data-sources/BackendWebsocketDataSource.mjs.map +1 -1
- package/dist/data-sources/TokenDataSource.cjs +12 -3
- 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 +12 -3
- package/dist/data-sources/TokenDataSource.mjs.map +1 -1
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Fixed
|
|
11
11
|
|
|
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.
|
|
12
21
|
- `AssetsController` no longer silently skips asset fetching on startup for returning users ([#8412](https://github.com/MetaMask/core/pull/8412))
|
|
13
22
|
- 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.
|
|
14
23
|
- 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_lastKnownAccountIds, _AssetsController_getSelectedAccounts, _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_handleAccountTreeStateChange, _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,6 +247,12 @@ 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());
|
|
250
256
|
_AssetsController_backendWebsocketDataSource.set(this, void 0);
|
|
251
257
|
_AssetsController_accountsApiDataSource.set(this, void 0);
|
|
252
258
|
_AssetsController_snapDataSource.set(this, void 0);
|
|
@@ -508,7 +514,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
508
514
|
* @returns Legacy-compatible state for transaction-pay-controller.
|
|
509
515
|
*/
|
|
510
516
|
getStateForTransactionPay() {
|
|
511
|
-
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "
|
|
517
|
+
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this);
|
|
512
518
|
const { nativeAssetIdentifiers } = this.messenger.call('NetworkEnablementController:getState');
|
|
513
519
|
const { networkConfigurationsByChainId } = this.messenger.call('NetworkController:getState');
|
|
514
520
|
return (0, utils_2.formatStateForTransactionPay)({
|
|
@@ -581,7 +587,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
581
587
|
}
|
|
582
588
|
});
|
|
583
589
|
// Fetch data for the newly added custom asset (merge to preserve other chains)
|
|
584
|
-
const account = __classPrivateFieldGet(this, _AssetsController_instances, "
|
|
590
|
+
const account = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this).find((a) => a.id === accountId);
|
|
585
591
|
if (account) {
|
|
586
592
|
const chainId = extractChainId(normalizedAssetId);
|
|
587
593
|
await this.getAssets([account], {
|
|
@@ -680,7 +686,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
680
686
|
if (!__classPrivateFieldGet(this, _AssetsController_isBasicFunctionality, "f").call(this)) {
|
|
681
687
|
return;
|
|
682
688
|
}
|
|
683
|
-
this.getAssets(__classPrivateFieldGet(this, _AssetsController_instances, "
|
|
689
|
+
this.getAssets(__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this), {
|
|
684
690
|
forceUpdate: true,
|
|
685
691
|
dataTypes: ['price'],
|
|
686
692
|
assetsForPriceUpdate: Object.values(this.state.assetsBalance).flatMap((balances) => Object.keys(balances)),
|
|
@@ -705,10 +711,11 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
705
711
|
const subscriptionKey = 'ds:PriceDataSource';
|
|
706
712
|
const existingSubscription = __classPrivateFieldGet(this, _AssetsController_activeSubscriptions, "f").get(subscriptionKey);
|
|
707
713
|
const isUpdate = existingSubscription !== undefined;
|
|
714
|
+
const request = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_buildDataRequest).call(this, accounts, chainIds, {
|
|
715
|
+
dataTypes: ['price'],
|
|
716
|
+
});
|
|
708
717
|
const subscribeReq = {
|
|
709
|
-
request
|
|
710
|
-
dataTypes: ['price'],
|
|
711
|
-
}),
|
|
718
|
+
request,
|
|
712
719
|
subscriptionId: subscriptionKey,
|
|
713
720
|
isUpdate,
|
|
714
721
|
onAssetsUpdate: (response) => this.handleAssetsUpdate(response, 'PriceDataSource'),
|
|
@@ -836,7 +843,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
836
843
|
}
|
|
837
844
|
}
|
|
838
845
|
exports.AssetsController = AssetsController;
|
|
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 = {
|
|
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(), _AssetsController_lastKnownAccountIds = 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 = {
|
|
840
847
|
controller: 'AssetsController',
|
|
841
848
|
}) {
|
|
842
849
|
if (!__classPrivateFieldGet(this, _AssetsController_trace, "f")) {
|
|
@@ -882,8 +889,16 @@ _AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctional
|
|
|
882
889
|
price_entries: Object.keys(assetsPrice).length,
|
|
883
890
|
custom_asset_entries: customAssetEntries,
|
|
884
891
|
});
|
|
885
|
-
},
|
|
886
|
-
|
|
892
|
+
}, _AssetsController_getSelectedAccounts = function _AssetsController_getSelectedAccounts() {
|
|
893
|
+
const accounts = this.messenger.call('AccountTreeController:getAccountsFromSelectedAccountGroup');
|
|
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 [];
|
|
887
902
|
}, _AssetsController_allBalanceDataSources_get = function _AssetsController_allBalanceDataSources_get() {
|
|
888
903
|
return [
|
|
889
904
|
__classPrivateFieldGet(this, _AssetsController_backendWebsocketDataSource, "f"),
|
|
@@ -936,7 +951,7 @@ _AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctional
|
|
|
936
951
|
// when init() calls this.update(). #start() is idempotent so
|
|
937
952
|
// repeated fires are safe.
|
|
938
953
|
this.messenger.subscribe('AccountTreeController:stateChange', () => {
|
|
939
|
-
__classPrivateFieldGet(this, _AssetsController_instances, "m",
|
|
954
|
+
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_handleAccountTreeStateChange).call(this);
|
|
940
955
|
});
|
|
941
956
|
// Subscribe to network enablement changes (only enabledNetworkMap)
|
|
942
957
|
this.messenger.subscribe('NetworkEnablementController:stateChange', ({ enabledNetworkMap }) => {
|
|
@@ -963,6 +978,36 @@ _AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctional
|
|
|
963
978
|
else {
|
|
964
979
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_stop).call(this);
|
|
965
980
|
}
|
|
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
|
+
}
|
|
966
1011
|
}, _AssetsController_registerActionHandlers = function _AssetsController_registerActionHandlers() {
|
|
967
1012
|
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
968
1013
|
}, _AssetsController_handleActiveChainsUpdate = function _AssetsController_handleActiveChainsUpdate(dataSourceId, activeChains, previousChains) {
|
|
@@ -983,11 +1028,11 @@ _AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctional
|
|
|
983
1028
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeAssets).call(this);
|
|
984
1029
|
}
|
|
985
1030
|
// If chains were added and we have selected accounts, do one-time fetch
|
|
986
|
-
if (addedChains.length > 0 && __classPrivateFieldGet(this, _AssetsController_instances, "
|
|
1031
|
+
if (addedChains.length > 0 && __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this).length > 0) {
|
|
987
1032
|
const addedEnabledChains = addedChains.filter((chain) => __classPrivateFieldGet(this, _AssetsController_enabledChains, "f").has(chain));
|
|
988
1033
|
if (addedEnabledChains.length > 0) {
|
|
989
1034
|
log('Fetching balances for newly added chains', { addedEnabledChains });
|
|
990
|
-
this.getAssets(__classPrivateFieldGet(this, _AssetsController_instances, "
|
|
1035
|
+
this.getAssets(__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this), {
|
|
991
1036
|
chainIds: addedEnabledChains,
|
|
992
1037
|
forceUpdate: true,
|
|
993
1038
|
updateMode: 'merge',
|
|
@@ -1086,7 +1131,7 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1086
1131
|
}, _AssetsController_getNativeAssetIdsForAccount = function _AssetsController_getNativeAssetIdsForAccount(account) {
|
|
1087
1132
|
return __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_resolveNativeAssetIds).call(this, __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getEnabledChainsForAccount).call(this, account));
|
|
1088
1133
|
}, _AssetsController_ensureNativeBalancesDefaultZero = function _AssetsController_ensureNativeBalancesDefaultZero() {
|
|
1089
|
-
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "
|
|
1134
|
+
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this);
|
|
1090
1135
|
if (accounts.length === 0) {
|
|
1091
1136
|
return;
|
|
1092
1137
|
}
|
|
@@ -1175,7 +1220,7 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1175
1220
|
return next;
|
|
1176
1221
|
})();
|
|
1177
1222
|
// Ensure native tokens have an entry (0 if missing) for chains this account supports
|
|
1178
|
-
const account = __classPrivateFieldGet(this, _AssetsController_instances, "
|
|
1223
|
+
const account = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this).find((a) => a.id === accountId);
|
|
1179
1224
|
const nativeAssetIdsForAccount = account
|
|
1180
1225
|
? __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getNativeAssetIdsForAccount).call(this, account)
|
|
1181
1226
|
: __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getNativeAssetIdsForEnabledChains).call(this);
|
|
@@ -1353,7 +1398,7 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1353
1398
|
return 'fungible';
|
|
1354
1399
|
}
|
|
1355
1400
|
}, _AssetsController_start = function _AssetsController_start() {
|
|
1356
|
-
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "
|
|
1401
|
+
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this);
|
|
1357
1402
|
const chainIds = [...__classPrivateFieldGet(this, _AssetsController_enabledChains, "f")];
|
|
1358
1403
|
if (accounts.length === 0 || chainIds.length === 0) {
|
|
1359
1404
|
return;
|
|
@@ -1365,6 +1410,7 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1365
1410
|
selectedAccountCount: accounts.length,
|
|
1366
1411
|
enabledChainCount: chainIds.length,
|
|
1367
1412
|
});
|
|
1413
|
+
__classPrivateFieldSet(this, _AssetsController_lastKnownAccountIds, new Set(accounts.map((a) => a.id)), "f");
|
|
1368
1414
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeAssets).call(this);
|
|
1369
1415
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_ensureNativeBalancesDefaultZero).call(this);
|
|
1370
1416
|
this.getAssets(accounts, {
|
|
@@ -1380,6 +1426,7 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1380
1426
|
});
|
|
1381
1427
|
__classPrivateFieldSet(this, _AssetsController_firstInitFetchReported, false, "f");
|
|
1382
1428
|
__classPrivateFieldSet(this, _AssetsController_stateSizeReported, false, "f");
|
|
1429
|
+
__classPrivateFieldSet(this, _AssetsController_lastKnownAccountIds, new Set(), "f");
|
|
1383
1430
|
// Stop price subscription first (uses direct messenger call)
|
|
1384
1431
|
this.unsubscribeAssetsPrice();
|
|
1385
1432
|
// Stop balance subscriptions by properly notifying data sources via messenger
|
|
@@ -1402,23 +1449,21 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1402
1449
|
}
|
|
1403
1450
|
__classPrivateFieldGet(this, _AssetsController_activeSubscriptions, "f").clear();
|
|
1404
1451
|
}, _AssetsController_subscribeAssets = function _AssetsController_subscribeAssets() {
|
|
1405
|
-
|
|
1452
|
+
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this);
|
|
1453
|
+
const enabledChains = [...__classPrivateFieldGet(this, _AssetsController_enabledChains, "f")];
|
|
1454
|
+
if (accounts.length === 0 || enabledChains.length === 0) {
|
|
1406
1455
|
return;
|
|
1407
1456
|
}
|
|
1408
1457
|
// Subscribe to balance updates (batched by data source)
|
|
1409
|
-
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeAssetsBalance).call(this,
|
|
1410
|
-
...__classPrivateFieldGet(this, _AssetsController_enabledChains, "f"),
|
|
1411
|
-
]);
|
|
1458
|
+
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeAssetsBalance).call(this, accounts, enabledChains);
|
|
1412
1459
|
// Subscribe to staked balance updates (separate from regular balance chain-claiming)
|
|
1413
|
-
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeStakedBalance).call(this,
|
|
1414
|
-
...__classPrivateFieldGet(this, _AssetsController_enabledChains, "f"),
|
|
1415
|
-
]);
|
|
1460
|
+
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeStakedBalance).call(this, accounts, enabledChains);
|
|
1416
1461
|
// Subscribe to price updates for all assets held by selected accounts
|
|
1417
|
-
this.subscribeAssetsPrice(
|
|
1462
|
+
this.subscribeAssetsPrice(accounts, enabledChains);
|
|
1418
1463
|
}, _AssetsController_subscribeAssetsBalance = function _AssetsController_subscribeAssetsBalance(accounts, chainIds) {
|
|
1419
1464
|
const chainToAccounts = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_buildChainToAccountsMap).call(this, accounts, new Set(chainIds));
|
|
1420
1465
|
const remainingChains = new Set(chainToAccounts.keys());
|
|
1421
|
-
// When basic functionality is on
|
|
1466
|
+
// When basic functionality is on, use all balance data sources; when off, RPC only.
|
|
1422
1467
|
const balanceDataSources = __classPrivateFieldGet(this, _AssetsController_isBasicFunctionality, "f").call(this)
|
|
1423
1468
|
? __classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_allBalanceDataSources_get)
|
|
1424
1469
|
: [__classPrivateFieldGet(this, _AssetsController_rpcDataSource, "f")];
|
|
@@ -1566,11 +1611,12 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1566
1611
|
// EVENT HANDLERS
|
|
1567
1612
|
// ============================================================================
|
|
1568
1613
|
async function _AssetsController_handleAccountGroupChanged() {
|
|
1569
|
-
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "
|
|
1614
|
+
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this);
|
|
1570
1615
|
log('Account group changed', {
|
|
1571
1616
|
accountCount: accounts.length,
|
|
1572
1617
|
accountIds: accounts.map((a) => a.id),
|
|
1573
1618
|
});
|
|
1619
|
+
__classPrivateFieldSet(this, _AssetsController_lastKnownAccountIds, new Set(accounts.map((a) => a.id)), "f");
|
|
1574
1620
|
// Subscribe and fetch for the new account group
|
|
1575
1621
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeAssets).call(this);
|
|
1576
1622
|
if (accounts.length > 0) {
|
|
@@ -1609,8 +1655,8 @@ async function _AssetsController_handleAccountGroupChanged() {
|
|
|
1609
1655
|
// Refresh subscriptions for new chain set
|
|
1610
1656
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeAssets).call(this);
|
|
1611
1657
|
// Do one-time fetch for newly enabled chains; merge so we keep existing chain balances
|
|
1612
|
-
if (addedChains.length > 0 && __classPrivateFieldGet(this, _AssetsController_instances, "
|
|
1613
|
-
await this.getAssets(__classPrivateFieldGet(this, _AssetsController_instances, "
|
|
1658
|
+
if (addedChains.length > 0 && __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this).length > 0) {
|
|
1659
|
+
await this.getAssets(__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this), {
|
|
1614
1660
|
chainIds: addedChains,
|
|
1615
1661
|
forceUpdate: true,
|
|
1616
1662
|
updateMode: 'merge',
|