@metamask-previews/assets-controller 5.0.1-preview-d6985be → 6.0.0-preview-9c8c0a0
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 +33 -1
- package/dist/AssetsController.cjs +118 -31
- package/dist/AssetsController.cjs.map +1 -1
- package/dist/AssetsController.d.cts +12 -4
- package/dist/AssetsController.d.cts.map +1 -1
- package/dist/AssetsController.d.mts +12 -4
- package/dist/AssetsController.d.mts.map +1 -1
- package/dist/AssetsController.mjs +118 -31
- 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/RpcDataSource.cjs +12 -2
- package/dist/data-sources/RpcDataSource.cjs.map +1 -1
- package/dist/data-sources/RpcDataSource.d.cts +4 -0
- package/dist/data-sources/RpcDataSource.d.cts.map +1 -1
- package/dist/data-sources/RpcDataSource.d.mts +4 -0
- package/dist/data-sources/RpcDataSource.d.mts.map +1 -1
- package/dist/data-sources/RpcDataSource.mjs +12 -2
- package/dist/data-sources/RpcDataSource.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 +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,28 @@ 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.2.0` to `^64.3.0` ([#8482](https://github.com/MetaMask/core/pull/8482))
|
|
13
|
+
|
|
14
|
+
## [6.0.0]
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- **BREAKING:** `AssetsControllerMessenger` now requires the `AccountsControllerGetSelectedAccountAction` allowed action ([#8430](https://github.com/MetaMask/core/pull/8430))
|
|
19
|
+
- Used as a fallback in `#getSelectedAccounts()` when `AccountTreeController` has not yet initialized.
|
|
20
|
+
- Consumers must register `AccountsController:getSelectedAccount` on the messenger.
|
|
21
|
+
- **BREAKING:** `AssetsControllerMessenger` now requires the `TransactionControllerUnapprovedTransactionAddedEvent` allowed event ([#8430](https://github.com/MetaMask/core/pull/8430))
|
|
22
|
+
- `AssetsController` subscribes to `TransactionController:unapprovedTransactionAdded` to refresh balances for the account initiating a transaction (e.g. for gas estimations).
|
|
23
|
+
- Consumers must allow `TransactionController:unapprovedTransactionAdded` on the messenger.
|
|
24
|
+
- Added `isOnboarded` option to `AssetsControllerOptions` and `RpcDataSourceConfig` ([#8430](https://github.com/MetaMask/core/pull/8430))
|
|
25
|
+
- When `isOnboarded` returns `false`, `RpcDataSource` skips `fetch` and `subscribe` calls, preventing on-chain RPC calls before onboarding is complete.
|
|
26
|
+
- Defaults to `() => true` so existing consumers are unaffected.
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
|
|
30
|
+
- Bump `@metamask/account-tree-controller` from `^7.0.0` to `^7.1.0` ([#8472](https://github.com/MetaMask/core/pull/8472))
|
|
31
|
+
|
|
10
32
|
## [5.0.1]
|
|
11
33
|
|
|
12
34
|
### Changed
|
|
@@ -17,6 +39,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
17
39
|
|
|
18
40
|
### Fixed
|
|
19
41
|
|
|
42
|
+
- `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))
|
|
43
|
+
- Previously, `#start()` would create subscriptions before snap accounts were available, and its idempotency guard prevented re-subscription when the full account list arrived.
|
|
44
|
+
- Added `#handleAccountTreeStateChange()` which forces a full re-subscription and re-fetch when the account tree updates, picking up all accounts including snaps.
|
|
45
|
+
- Added `AccountsController:getSelectedAccount` as a fallback in `#getSelectedAccounts()` for when the account tree is not yet initialized.
|
|
46
|
+
- `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))
|
|
47
|
+
- Tokens present in `customAssets` state now bypass the EVM occurrence threshold and non-EVM Blockaid scan, ensuring manually imported assets always appear.
|
|
48
|
+
- `BackendWebsocketDataSource` now properly releases chains to `AccountsApiDataSource` when the websocket is disconnected or disabled ([#8430](https://github.com/MetaMask/core/pull/8430))
|
|
49
|
+
- Previously, `BackendWebsocketDataSource` eagerly claimed all supported chains on initialization regardless of connection state, preventing `AccountsApiDataSource` from polling.
|
|
50
|
+
- 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.
|
|
20
51
|
- `AssetsController` no longer silently skips asset fetching on startup for returning users ([#8412](https://github.com/MetaMask/core/pull/8412))
|
|
21
52
|
- 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.
|
|
22
53
|
- 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.
|
|
@@ -302,7 +333,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
302
333
|
- Refactor `RpcDataSource` to delegate polling to `BalanceFetcher` and `TokenDetector` services ([#7709](https://github.com/MetaMask/core/pull/7709))
|
|
303
334
|
- Refactor `BalanceFetcher` and `TokenDetector` to extend `StaticIntervalPollingControllerOnly` for independent polling management ([#7709](https://github.com/MetaMask/core/pull/7709))
|
|
304
335
|
|
|
305
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@
|
|
336
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@6.0.0...HEAD
|
|
337
|
+
[6.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@5.0.1...@metamask/assets-controller@6.0.0
|
|
306
338
|
[5.0.1]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@5.0.0...@metamask/assets-controller@5.0.1
|
|
307
339
|
[5.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@4.0.0...@metamask/assets-controller@5.0.0
|
|
308
340
|
[4.0.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@3.3.0...@metamask/assets-controller@4.0.0
|
|
@@ -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_onUnapprovedTransactionAdded, _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");
|
|
@@ -210,7 +210,7 @@ function normalizeResponse(response) {
|
|
|
210
210
|
* - The controller does NOT manage polling - it simply receives pushed updates
|
|
211
211
|
*/
|
|
212
212
|
class AssetsController extends base_controller_1.BaseController {
|
|
213
|
-
constructor({ messenger, state = {}, defaultUpdateInterval = DEFAULT_POLLING_INTERVAL_MS, isEnabled = () => true, isBasicFunctionality, subscribeToBasicFunctionalityChange, queryApiClient, rpcDataSourceConfig, trace, accountsApiDataSourceConfig, priceDataSourceConfig, stakedBalanceDataSourceConfig, }) {
|
|
213
|
+
constructor({ messenger, state = {}, defaultUpdateInterval = DEFAULT_POLLING_INTERVAL_MS, isEnabled = () => true, isBasicFunctionality, subscribeToBasicFunctionalityChange, queryApiClient, rpcDataSourceConfig, trace, accountsApiDataSourceConfig, priceDataSourceConfig, stakedBalanceDataSourceConfig, isOnboarded, }) {
|
|
214
214
|
super({
|
|
215
215
|
name: CONTROLLER_NAME,
|
|
216
216
|
messenger,
|
|
@@ -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);
|
|
@@ -291,6 +297,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
291
297
|
messenger: this.messenger,
|
|
292
298
|
onActiveChainsUpdated: __classPrivateFieldGet(this, _AssetsController_onActiveChainsUpdated, "f"),
|
|
293
299
|
...rpcConfig,
|
|
300
|
+
isOnboarded: rpcConfig.isOnboarded ?? isOnboarded,
|
|
294
301
|
}), "f");
|
|
295
302
|
__classPrivateFieldSet(this, _AssetsController_stakedBalanceDataSource, new StakedBalanceDataSource_1.StakedBalanceDataSource({
|
|
296
303
|
messenger: this.messenger,
|
|
@@ -508,7 +515,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
508
515
|
* @returns Legacy-compatible state for transaction-pay-controller.
|
|
509
516
|
*/
|
|
510
517
|
getStateForTransactionPay() {
|
|
511
|
-
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "
|
|
518
|
+
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this);
|
|
512
519
|
const { nativeAssetIdentifiers } = this.messenger.call('NetworkEnablementController:getState');
|
|
513
520
|
const { networkConfigurationsByChainId } = this.messenger.call('NetworkController:getState');
|
|
514
521
|
return (0, utils_2.formatStateForTransactionPay)({
|
|
@@ -581,7 +588,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
581
588
|
}
|
|
582
589
|
});
|
|
583
590
|
// Fetch data for the newly added custom asset (merge to preserve other chains)
|
|
584
|
-
const account = __classPrivateFieldGet(this, _AssetsController_instances, "
|
|
591
|
+
const account = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this).find((a) => a.id === accountId);
|
|
585
592
|
if (account) {
|
|
586
593
|
const chainId = extractChainId(normalizedAssetId);
|
|
587
594
|
await this.getAssets([account], {
|
|
@@ -680,7 +687,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
680
687
|
if (!__classPrivateFieldGet(this, _AssetsController_isBasicFunctionality, "f").call(this)) {
|
|
681
688
|
return;
|
|
682
689
|
}
|
|
683
|
-
this.getAssets(__classPrivateFieldGet(this, _AssetsController_instances, "
|
|
690
|
+
this.getAssets(__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this), {
|
|
684
691
|
forceUpdate: true,
|
|
685
692
|
dataTypes: ['price'],
|
|
686
693
|
assetsForPriceUpdate: Object.values(this.state.assetsBalance).flatMap((balances) => Object.keys(balances)),
|
|
@@ -705,10 +712,11 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
705
712
|
const subscriptionKey = 'ds:PriceDataSource';
|
|
706
713
|
const existingSubscription = __classPrivateFieldGet(this, _AssetsController_activeSubscriptions, "f").get(subscriptionKey);
|
|
707
714
|
const isUpdate = existingSubscription !== undefined;
|
|
715
|
+
const request = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_buildDataRequest).call(this, accounts, chainIds, {
|
|
716
|
+
dataTypes: ['price'],
|
|
717
|
+
});
|
|
708
718
|
const subscribeReq = {
|
|
709
|
-
request
|
|
710
|
-
dataTypes: ['price'],
|
|
711
|
-
}),
|
|
719
|
+
request,
|
|
712
720
|
subscriptionId: subscriptionKey,
|
|
713
721
|
isUpdate,
|
|
714
722
|
onAssetsUpdate: (response) => this.handleAssetsUpdate(response, 'PriceDataSource'),
|
|
@@ -836,7 +844,7 @@ class AssetsController extends base_controller_1.BaseController {
|
|
|
836
844
|
}
|
|
837
845
|
}
|
|
838
846
|
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 = {
|
|
847
|
+
_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
848
|
controller: 'AssetsController',
|
|
841
849
|
}) {
|
|
842
850
|
if (!__classPrivateFieldGet(this, _AssetsController_trace, "f")) {
|
|
@@ -882,8 +890,16 @@ _AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctional
|
|
|
882
890
|
price_entries: Object.keys(assetsPrice).length,
|
|
883
891
|
custom_asset_entries: customAssetEntries,
|
|
884
892
|
});
|
|
885
|
-
},
|
|
886
|
-
|
|
893
|
+
}, _AssetsController_getSelectedAccounts = function _AssetsController_getSelectedAccounts() {
|
|
894
|
+
const accounts = this.messenger.call('AccountTreeController:getAccountsFromSelectedAccountGroup');
|
|
895
|
+
if (accounts.length > 0) {
|
|
896
|
+
return accounts;
|
|
897
|
+
}
|
|
898
|
+
const selectedAccount = this.messenger.call('AccountsController:getSelectedAccount');
|
|
899
|
+
if (selectedAccount) {
|
|
900
|
+
return [selectedAccount];
|
|
901
|
+
}
|
|
902
|
+
return [];
|
|
887
903
|
}, _AssetsController_allBalanceDataSources_get = function _AssetsController_allBalanceDataSources_get() {
|
|
888
904
|
return [
|
|
889
905
|
__classPrivateFieldGet(this, _AssetsController_backendWebsocketDataSource, "f"),
|
|
@@ -936,7 +952,7 @@ _AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctional
|
|
|
936
952
|
// when init() calls this.update(). #start() is idempotent so
|
|
937
953
|
// repeated fires are safe.
|
|
938
954
|
this.messenger.subscribe('AccountTreeController:stateChange', () => {
|
|
939
|
-
__classPrivateFieldGet(this, _AssetsController_instances, "m",
|
|
955
|
+
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_handleAccountTreeStateChange).call(this);
|
|
940
956
|
});
|
|
941
957
|
// Subscribe to network enablement changes (only enabledNetworkMap)
|
|
942
958
|
this.messenger.subscribe('NetworkEnablementController:stateChange', ({ enabledNetworkMap }) => {
|
|
@@ -955,6 +971,33 @@ _AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctional
|
|
|
955
971
|
__classPrivateFieldSet(this, _AssetsController_keyringUnlocked, false, "f");
|
|
956
972
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_updateActive).call(this);
|
|
957
973
|
});
|
|
974
|
+
// Subscribe to unapproved transactions - TXs that need confirmation
|
|
975
|
+
// Ensures that balances for the account making transaction are updated (e.g. for gas estimations)
|
|
976
|
+
this.messenger.subscribe('TransactionController:unapprovedTransactionAdded', (transactionMeta) => {
|
|
977
|
+
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_onUnapprovedTransactionAdded).call(this, transactionMeta);
|
|
978
|
+
});
|
|
979
|
+
}, _AssetsController_onUnapprovedTransactionAdded = function _AssetsController_onUnapprovedTransactionAdded(transactionMeta) {
|
|
980
|
+
const hexChainId = transactionMeta.chainId;
|
|
981
|
+
if (!hexChainId) {
|
|
982
|
+
return;
|
|
983
|
+
}
|
|
984
|
+
const caipChainId = `eip155:${parseInt(hexChainId, 16)}`;
|
|
985
|
+
const fromAddress = transactionMeta.txParams.from?.toLowerCase();
|
|
986
|
+
if (!fromAddress) {
|
|
987
|
+
return;
|
|
988
|
+
}
|
|
989
|
+
const matchedAccount = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this).find((account) => account.address.toLowerCase() === fromAddress);
|
|
990
|
+
if (!matchedAccount) {
|
|
991
|
+
return;
|
|
992
|
+
}
|
|
993
|
+
this.getAssets([matchedAccount], {
|
|
994
|
+
chainIds: [caipChainId],
|
|
995
|
+
forceUpdate: true,
|
|
996
|
+
}).catch((error) => {
|
|
997
|
+
log('Failed to refresh assets after unapproved transaction added', {
|
|
998
|
+
error,
|
|
999
|
+
});
|
|
1000
|
+
});
|
|
958
1001
|
}, _AssetsController_updateActive = function _AssetsController_updateActive() {
|
|
959
1002
|
const shouldRun = __classPrivateFieldGet(this, _AssetsController_uiOpen, "f") && __classPrivateFieldGet(this, _AssetsController_keyringUnlocked, "f");
|
|
960
1003
|
if (shouldRun) {
|
|
@@ -963,6 +1006,36 @@ _AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctional
|
|
|
963
1006
|
else {
|
|
964
1007
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_stop).call(this);
|
|
965
1008
|
}
|
|
1009
|
+
}, _AssetsController_handleAccountTreeStateChange = function _AssetsController_handleAccountTreeStateChange() {
|
|
1010
|
+
const shouldRun = __classPrivateFieldGet(this, _AssetsController_uiOpen, "f") && __classPrivateFieldGet(this, _AssetsController_keyringUnlocked, "f");
|
|
1011
|
+
if (!shouldRun) {
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
if (__classPrivateFieldGet(this, _AssetsController_activeSubscriptions, "f").size > 0) {
|
|
1015
|
+
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this);
|
|
1016
|
+
const currentIds = new Set(accounts.map((a) => a.id));
|
|
1017
|
+
const accountsChanged = currentIds.size !== __classPrivateFieldGet(this, _AssetsController_lastKnownAccountIds, "f").size ||
|
|
1018
|
+
[...currentIds].some((id) => !__classPrivateFieldGet(this, _AssetsController_lastKnownAccountIds, "f").has(id));
|
|
1019
|
+
if (!accountsChanged) {
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
log('Account tree changed with new accounts, re-subscribing', {
|
|
1023
|
+
previousCount: __classPrivateFieldGet(this, _AssetsController_lastKnownAccountIds, "f").size,
|
|
1024
|
+
currentCount: currentIds.size,
|
|
1025
|
+
});
|
|
1026
|
+
__classPrivateFieldSet(this, _AssetsController_lastKnownAccountIds, currentIds, "f");
|
|
1027
|
+
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeAssets).call(this);
|
|
1028
|
+
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_ensureNativeBalancesDefaultZero).call(this);
|
|
1029
|
+
this.getAssets(accounts, {
|
|
1030
|
+
chainIds: [...__classPrivateFieldGet(this, _AssetsController_enabledChains, "f")],
|
|
1031
|
+
forceUpdate: true,
|
|
1032
|
+
}).catch((error) => {
|
|
1033
|
+
log('Failed to fetch assets after tree change', error);
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
1036
|
+
else {
|
|
1037
|
+
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_start).call(this);
|
|
1038
|
+
}
|
|
966
1039
|
}, _AssetsController_registerActionHandlers = function _AssetsController_registerActionHandlers() {
|
|
967
1040
|
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
968
1041
|
}, _AssetsController_handleActiveChainsUpdate = function _AssetsController_handleActiveChainsUpdate(dataSourceId, activeChains, previousChains) {
|
|
@@ -983,11 +1056,11 @@ _AssetsController_isEnabled = new WeakMap(), _AssetsController_isBasicFunctional
|
|
|
983
1056
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeAssets).call(this);
|
|
984
1057
|
}
|
|
985
1058
|
// If chains were added and we have selected accounts, do one-time fetch
|
|
986
|
-
if (addedChains.length > 0 && __classPrivateFieldGet(this, _AssetsController_instances, "
|
|
1059
|
+
if (addedChains.length > 0 && __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this).length > 0) {
|
|
987
1060
|
const addedEnabledChains = addedChains.filter((chain) => __classPrivateFieldGet(this, _AssetsController_enabledChains, "f").has(chain));
|
|
988
1061
|
if (addedEnabledChains.length > 0) {
|
|
989
1062
|
log('Fetching balances for newly added chains', { addedEnabledChains });
|
|
990
|
-
this.getAssets(__classPrivateFieldGet(this, _AssetsController_instances, "
|
|
1063
|
+
this.getAssets(__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this), {
|
|
991
1064
|
chainIds: addedEnabledChains,
|
|
992
1065
|
forceUpdate: true,
|
|
993
1066
|
updateMode: 'merge',
|
|
@@ -1086,7 +1159,7 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1086
1159
|
}, _AssetsController_getNativeAssetIdsForAccount = function _AssetsController_getNativeAssetIdsForAccount(account) {
|
|
1087
1160
|
return __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_resolveNativeAssetIds).call(this, __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getEnabledChainsForAccount).call(this, account));
|
|
1088
1161
|
}, _AssetsController_ensureNativeBalancesDefaultZero = function _AssetsController_ensureNativeBalancesDefaultZero() {
|
|
1089
|
-
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "
|
|
1162
|
+
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this);
|
|
1090
1163
|
if (accounts.length === 0) {
|
|
1091
1164
|
return;
|
|
1092
1165
|
}
|
|
@@ -1175,7 +1248,7 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1175
1248
|
return next;
|
|
1176
1249
|
})();
|
|
1177
1250
|
// Ensure native tokens have an entry (0 if missing) for chains this account supports
|
|
1178
|
-
const account = __classPrivateFieldGet(this, _AssetsController_instances, "
|
|
1251
|
+
const account = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this).find((a) => a.id === accountId);
|
|
1179
1252
|
const nativeAssetIdsForAccount = account
|
|
1180
1253
|
? __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getNativeAssetIdsForAccount).call(this, account)
|
|
1181
1254
|
: __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getNativeAssetIdsForEnabledChains).call(this);
|
|
@@ -1353,7 +1426,7 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1353
1426
|
return 'fungible';
|
|
1354
1427
|
}
|
|
1355
1428
|
}, _AssetsController_start = function _AssetsController_start() {
|
|
1356
|
-
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "
|
|
1429
|
+
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this);
|
|
1357
1430
|
const chainIds = [...__classPrivateFieldGet(this, _AssetsController_enabledChains, "f")];
|
|
1358
1431
|
if (accounts.length === 0 || chainIds.length === 0) {
|
|
1359
1432
|
return;
|
|
@@ -1365,6 +1438,7 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1365
1438
|
selectedAccountCount: accounts.length,
|
|
1366
1439
|
enabledChainCount: chainIds.length,
|
|
1367
1440
|
});
|
|
1441
|
+
__classPrivateFieldSet(this, _AssetsController_lastKnownAccountIds, new Set(accounts.map((a) => a.id)), "f");
|
|
1368
1442
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeAssets).call(this);
|
|
1369
1443
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_ensureNativeBalancesDefaultZero).call(this);
|
|
1370
1444
|
this.getAssets(accounts, {
|
|
@@ -1380,6 +1454,7 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1380
1454
|
});
|
|
1381
1455
|
__classPrivateFieldSet(this, _AssetsController_firstInitFetchReported, false, "f");
|
|
1382
1456
|
__classPrivateFieldSet(this, _AssetsController_stateSizeReported, false, "f");
|
|
1457
|
+
__classPrivateFieldSet(this, _AssetsController_lastKnownAccountIds, new Set(), "f");
|
|
1383
1458
|
// Stop price subscription first (uses direct messenger call)
|
|
1384
1459
|
this.unsubscribeAssetsPrice();
|
|
1385
1460
|
// Stop balance subscriptions by properly notifying data sources via messenger
|
|
@@ -1402,23 +1477,21 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1402
1477
|
}
|
|
1403
1478
|
__classPrivateFieldGet(this, _AssetsController_activeSubscriptions, "f").clear();
|
|
1404
1479
|
}, _AssetsController_subscribeAssets = function _AssetsController_subscribeAssets() {
|
|
1405
|
-
|
|
1480
|
+
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this);
|
|
1481
|
+
const enabledChains = [...__classPrivateFieldGet(this, _AssetsController_enabledChains, "f")];
|
|
1482
|
+
if (accounts.length === 0 || enabledChains.length === 0) {
|
|
1406
1483
|
return;
|
|
1407
1484
|
}
|
|
1408
1485
|
// 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
|
-
]);
|
|
1486
|
+
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeAssetsBalance).call(this, accounts, enabledChains);
|
|
1412
1487
|
// 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
|
-
]);
|
|
1488
|
+
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeStakedBalance).call(this, accounts, enabledChains);
|
|
1416
1489
|
// Subscribe to price updates for all assets held by selected accounts
|
|
1417
|
-
this.subscribeAssetsPrice(
|
|
1490
|
+
this.subscribeAssetsPrice(accounts, enabledChains);
|
|
1418
1491
|
}, _AssetsController_subscribeAssetsBalance = function _AssetsController_subscribeAssetsBalance(accounts, chainIds) {
|
|
1419
1492
|
const chainToAccounts = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_buildChainToAccountsMap).call(this, accounts, new Set(chainIds));
|
|
1420
1493
|
const remainingChains = new Set(chainToAccounts.keys());
|
|
1421
|
-
// When basic functionality is on
|
|
1494
|
+
// When basic functionality is on, use all balance data sources; when off, RPC only.
|
|
1422
1495
|
const balanceDataSources = __classPrivateFieldGet(this, _AssetsController_isBasicFunctionality, "f").call(this)
|
|
1423
1496
|
? __classPrivateFieldGet(this, _AssetsController_instances, "a", _AssetsController_allBalanceDataSources_get)
|
|
1424
1497
|
: [__classPrivateFieldGet(this, _AssetsController_rpcDataSource, "f")];
|
|
@@ -1521,16 +1594,19 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1521
1594
|
}
|
|
1522
1595
|
}, _AssetsController_buildDataRequest = function _AssetsController_buildDataRequest(accounts, chainIds, partial = {}) {
|
|
1523
1596
|
const chainIdSet = new Set(chainIds);
|
|
1597
|
+
// Force update will pass in additional chains for wildcard account scope
|
|
1598
|
+
// Enables updates for chains that are not selected (e.g. for unapproved transactions)
|
|
1599
|
+
const forceUpdateChains = partial.forceUpdate ? chainIds : undefined;
|
|
1524
1600
|
const accountsWithSupportedChains = accounts.map((account) => ({
|
|
1525
1601
|
account,
|
|
1526
|
-
supportedChains: __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getEnabledChainsForAccount).call(this, account).filter((chain) => chainIdSet.has(chain)),
|
|
1602
|
+
supportedChains: __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getEnabledChainsForAccount).call(this, account, forceUpdateChains).filter((chain) => chainIdSet.has(chain)),
|
|
1527
1603
|
}));
|
|
1528
1604
|
return {
|
|
1529
1605
|
accountsWithSupportedChains,
|
|
1530
1606
|
chainIds,
|
|
1531
1607
|
...partial,
|
|
1532
1608
|
};
|
|
1533
|
-
}, _AssetsController_getEnabledChainsForAccount = function _AssetsController_getEnabledChainsForAccount(account) {
|
|
1609
|
+
}, _AssetsController_getEnabledChainsForAccount = function _AssetsController_getEnabledChainsForAccount(account, additionalChains) {
|
|
1534
1610
|
// Account scopes are CAIP-2 chain IDs like "eip155:1", "solana:mainnet", "bip122:..."
|
|
1535
1611
|
const scopes = account.scopes ?? [];
|
|
1536
1612
|
const result = [];
|
|
@@ -1543,6 +1619,7 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1543
1619
|
const { namespace, reference } = (0, utils_1.parseCaipChainId)(scopeStr);
|
|
1544
1620
|
// Wildcard scope (e.g., "eip155:0" means all enabled chains in that namespace)
|
|
1545
1621
|
if (reference === '0') {
|
|
1622
|
+
// Add enabled chains
|
|
1546
1623
|
for (const chain of __classPrivateFieldGet(this, _AssetsController_enabledChains, "f")) {
|
|
1547
1624
|
if ((0, utils_1.isCaipChainId)(chain)) {
|
|
1548
1625
|
const chainParsed = (0, utils_1.parseCaipChainId)(chain);
|
|
@@ -1551,6 +1628,15 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1551
1628
|
}
|
|
1552
1629
|
}
|
|
1553
1630
|
}
|
|
1631
|
+
// Add additional chains
|
|
1632
|
+
for (const chain of additionalChains ?? []) {
|
|
1633
|
+
if ((0, utils_1.isCaipChainId)(chain)) {
|
|
1634
|
+
const chainParsed = (0, utils_1.parseCaipChainId)(chain);
|
|
1635
|
+
if (chainParsed.namespace === namespace) {
|
|
1636
|
+
result.push(chain);
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1554
1640
|
}
|
|
1555
1641
|
else if (namespace === 'eip155' && (0, utils_1.isStrictHexString)(reference)) {
|
|
1556
1642
|
// Normalize hex to decimal for EIP155
|
|
@@ -1566,11 +1652,12 @@ async function _AssetsController_executeMiddlewares(sources, request, initialRes
|
|
|
1566
1652
|
// EVENT HANDLERS
|
|
1567
1653
|
// ============================================================================
|
|
1568
1654
|
async function _AssetsController_handleAccountGroupChanged() {
|
|
1569
|
-
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "
|
|
1655
|
+
const accounts = __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this);
|
|
1570
1656
|
log('Account group changed', {
|
|
1571
1657
|
accountCount: accounts.length,
|
|
1572
1658
|
accountIds: accounts.map((a) => a.id),
|
|
1573
1659
|
});
|
|
1660
|
+
__classPrivateFieldSet(this, _AssetsController_lastKnownAccountIds, new Set(accounts.map((a) => a.id)), "f");
|
|
1574
1661
|
// Subscribe and fetch for the new account group
|
|
1575
1662
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeAssets).call(this);
|
|
1576
1663
|
if (accounts.length > 0) {
|
|
@@ -1609,8 +1696,8 @@ async function _AssetsController_handleAccountGroupChanged() {
|
|
|
1609
1696
|
// Refresh subscriptions for new chain set
|
|
1610
1697
|
__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_subscribeAssets).call(this);
|
|
1611
1698
|
// 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, "
|
|
1699
|
+
if (addedChains.length > 0 && __classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this).length > 0) {
|
|
1700
|
+
await this.getAssets(__classPrivateFieldGet(this, _AssetsController_instances, "m", _AssetsController_getSelectedAccounts).call(this), {
|
|
1614
1701
|
chainIds: addedChains,
|
|
1615
1702
|
forceUpdate: true,
|
|
1616
1703
|
updateMode: 'merge',
|