@metamask-previews/assets-controller 20.3.0-preview-40b7a961e → 20.3.1-preview-04cf473
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 +8 -17
- package/dist/AssetsController.d.ts +4 -7
- package/dist/AssetsController.d.ts.map +1 -1
- package/dist/AssetsController.js +59 -230
- package/dist/AssetsController.js.map +1 -1
- package/dist/data-sources/AbstractDataSource.d.ts +0 -13
- package/dist/data-sources/AbstractDataSource.d.ts.map +1 -1
- package/dist/data-sources/AbstractDataSource.js +0 -15
- package/dist/data-sources/AbstractDataSource.js.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.d.ts +0 -8
- package/dist/data-sources/AccountsApiDataSource.d.ts.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.js +1 -23
- package/dist/data-sources/AccountsApiDataSource.js.map +1 -1
- package/dist/data-sources/RpcDataSource.d.ts +0 -8
- package/dist/data-sources/RpcDataSource.d.ts.map +1 -1
- package/dist/data-sources/RpcDataSource.js +0 -9
- package/dist/data-sources/RpcDataSource.js.map +1 -1
- package/dist/data-sources/SnapDataSource.d.ts +0 -8
- package/dist/data-sources/SnapDataSource.d.ts.map +1 -1
- package/dist/data-sources/SnapDataSource.js +1 -9
- package/dist/data-sources/SnapDataSource.js.map +1 -1
- package/dist/data-sources/StakedBalanceDataSource.d.ts +0 -10
- package/dist/data-sources/StakedBalanceDataSource.d.ts.map +1 -1
- package/dist/data-sources/StakedBalanceDataSource.js +2 -5
- package/dist/data-sources/StakedBalanceDataSource.js.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -7,25 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
- Add `bootstrap()` to `AbstractDataSource` for setup that reads other controllers or makes requests ([#11351](https://github.com/MetaMask/core/pull/11351))
|
|
13
|
-
- The default implementation does nothing. `AssetsController` calls it on every balance data source the first time the UI opens.
|
|
10
|
+
## [20.3.1]
|
|
14
11
|
|
|
15
12
|
### Changed
|
|
16
13
|
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
- Enabled chains are no longer cached on the controller; they are read from `NetworkEnablementController:getState` each time they are needed, so they are correct before bootstrap too. They are empty if `NetworkEnablementController` is not registered.
|
|
23
|
-
- A controller destroyed during or after bootstrap does not start tracking assets.
|
|
24
|
-
- Clients must call `ClientController:setUiOpen(true)` when the UI opens, or assets are never loaded.
|
|
25
|
-
- **BREAKING:** `AccountsApiDataSource`, `RpcDataSource` and `SnapDataSource` no longer call other controllers or make requests in their constructors ([#11351](https://github.com/MetaMask/core/pull/11351))
|
|
26
|
-
- Call `bootstrap()` to fetch the Accounts API supported networks (and start refreshing them), read `NetworkController` state, or discover keyring snaps, respectively. `AssetsController` does this for you.
|
|
27
|
-
- `AccountsApiDataSource` ignores `RemoteFeatureFlagController:stateChange` until it has been bootstrapped.
|
|
28
|
-
- `AssetsController` treats a controller whose actions are not registered (such as `AccountTreeController`, `ClientController` or `KeyringController`) as not ready instead of throwing ([#11351](https://github.com/MetaMask/core/pull/11351))
|
|
14
|
+
- Bump `@metamask/accounts-controller` from `^40.1.0` to `^40.2.0` ([#11390](https://github.com/MetaMask/core/pull/11390))
|
|
15
|
+
- Bump `@metamask/assets-controllers` from `^113.3.0` to `^113.3.1` ([#11390](https://github.com/MetaMask/core/pull/11390))
|
|
16
|
+
- Bump `@metamask/network-controller` from `^37.1.1` to `^38.0.0` ([#11390](https://github.com/MetaMask/core/pull/11390))
|
|
17
|
+
- Bump `@metamask/network-enablement-controller` from `^7.1.0` to `^7.1.1` ([#11390](https://github.com/MetaMask/core/pull/11390))
|
|
18
|
+
- Bump `@metamask/transaction-controller` from `^73.1.1` to `^73.1.2` ([#11390](https://github.com/MetaMask/core/pull/11390))
|
|
29
19
|
|
|
30
20
|
## [20.3.0]
|
|
31
21
|
|
|
@@ -1290,7 +1280,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
1290
1280
|
- Refactor `RpcDataSource` to delegate polling to `BalanceFetcher` and `TokenDetector` services ([#7709](https://github.com/MetaMask/core/pull/7709))
|
|
1291
1281
|
- Refactor `BalanceFetcher` and `TokenDetector` to extend `StaticIntervalPollingControllerOnly` for independent polling management ([#7709](https://github.com/MetaMask/core/pull/7709))
|
|
1292
1282
|
|
|
1293
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@20.3.
|
|
1283
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@20.3.1...HEAD
|
|
1284
|
+
[20.3.1]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@20.3.0...@metamask/assets-controller@20.3.1
|
|
1294
1285
|
[20.3.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@20.2.3...@metamask/assets-controller@20.3.0
|
|
1295
1286
|
[20.2.3]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@20.2.2...@metamask/assets-controller@20.2.3
|
|
1296
1287
|
[20.2.2]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@20.2.1...@metamask/assets-controller@20.2.2
|
|
@@ -155,13 +155,10 @@ export type AssetsControllerOptions = {
|
|
|
155
155
|
* based on which chains they support. When active chains change, the controller
|
|
156
156
|
* dynamically adjusts subscriptions.
|
|
157
157
|
*
|
|
158
|
-
* 4. **Client + Keyring Lifecycle**:
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
* wallet is unlocked (KeyringController), and stops when either the UI
|
|
163
|
-
* closes or the keyring locks. See client-controller README for the
|
|
164
|
-
* combined pattern.
|
|
158
|
+
* 4. **Client + Keyring Lifecycle**: Starts subscriptions only when both the UI is
|
|
159
|
+
* open (ClientController) and the wallet is unlocked (KeyringController).
|
|
160
|
+
* Stops when either the UI closes or the keyring locks. See client-controller
|
|
161
|
+
* README for the combined pattern.
|
|
165
162
|
*
|
|
166
163
|
* ## Architecture
|
|
167
164
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetsController.d.ts","sourceRoot":"","sources":["../src/AssetsController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8DAA8D,EAC9D,qCAAqC,EACrC,wCAAwC,EACxC,oDAAoD,EACpD,uCAAuC,EACxC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,0CAA0C,EAAE,MAAM,+BAA+B,CAAC;AAChG,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EACV,8BAA8B,EAC9B,gCAAgC,EACjC,MAAM,6BAA6B,CAAC;AAErC,OAAO,KAAK,EAAE,4DAA4D,EAAE,MAAM,sCAAsC,CAAC;AACzH,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,4BAA4B,CAAC;AAC9E,OAAO,KAAK,EACV,iBAAiB,EACjB,yCAAyC,EACzC,wCAAwC,EACxC,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EACV,iCAAiC,EACjC,0BAA0B,EAC1B,4BAA4B,EAC7B,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,yDAAyD,EAAE,MAAM,8CAA8C,CAAC;AAC9H,OAAO,KAAK,EACV,2CAA2C,EAC3C,+BAA+B,EAC/B,kCAAkC,EAClC,sCAAsC,EACtC,oCAAoC,EAEpC,iCAAiC,EAClC,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EACV,yCAAyC,EAC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,EACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,IAAI,CAAC,CAYf;IAsMD,OAAO,IAAI,IAAI,CAoDd;CACF"}
|
package/dist/AssetsController.js
CHANGED
|
@@ -321,13 +321,10 @@ function effectiveAccountBalancesV6(previousBalances, updatedBalances, undeletab
|
|
|
321
321
|
* based on which chains they support. When active chains change, the controller
|
|
322
322
|
* dynamically adjusts subscriptions.
|
|
323
323
|
*
|
|
324
|
-
* 4. **Client + Keyring Lifecycle**:
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
* wallet is unlocked (KeyringController), and stops when either the UI
|
|
329
|
-
* closes or the keyring locks. See client-controller README for the
|
|
330
|
-
* combined pattern.
|
|
324
|
+
* 4. **Client + Keyring Lifecycle**: Starts subscriptions only when both the UI is
|
|
325
|
+
* open (ClientController) and the wallet is unlocked (KeyringController).
|
|
326
|
+
* Stops when either the UI closes or the keyring locks. See client-controller
|
|
327
|
+
* README for the combined pattern.
|
|
331
328
|
*
|
|
332
329
|
* ## Architecture
|
|
333
330
|
*
|
|
@@ -429,30 +426,8 @@ let AssetsController = (() => {
|
|
|
429
426
|
* its forced `getAssets()` call) runs a second time for the same accounts.
|
|
430
427
|
*/
|
|
431
428
|
#startInFlight = false;
|
|
432
|
-
/**
|
|
433
|
-
|
|
434
|
-
*
|
|
435
|
-
* Read each time they are needed rather than cached, so there is a single
|
|
436
|
-
* source of truth. Empty if NetworkEnablementController is not registered.
|
|
437
|
-
*
|
|
438
|
-
* @returns Set of CAIP-2 chain IDs for all enabled networks.
|
|
439
|
-
*/
|
|
440
|
-
#getEnabledChains() {
|
|
441
|
-
const enabledNetworkMap = this.#callIfRegistered(() => this.messenger.call('NetworkEnablementController:getState')
|
|
442
|
-
.enabledNetworkMap, undefined);
|
|
443
|
-
return enabledNetworkMap
|
|
444
|
-
? this.#extractEnabledChains(enabledNetworkMap)
|
|
445
|
-
: new Set();
|
|
446
|
-
}
|
|
447
|
-
/**
|
|
448
|
-
* Whether `#bootstrap()` has finished. Until then, event handlers only
|
|
449
|
-
* record state (such as enabled chains) and never fetch.
|
|
450
|
-
*/
|
|
451
|
-
#isBootstrapped = false;
|
|
452
|
-
/** Set by the first `#bootstrap()` call; later calls reuse it. */
|
|
453
|
-
#bootstrapPromise = null;
|
|
454
|
-
#isDestroyed = false;
|
|
455
|
-
#subscribeToBasicFunctionalityChange;
|
|
429
|
+
/** Currently enabled chains from NetworkEnablementController */
|
|
430
|
+
#enabledChains = new Set();
|
|
456
431
|
/**
|
|
457
432
|
* Get the currently selected accounts from AccountTreeController.
|
|
458
433
|
* This includes all accounts in the same group as the selected account
|
|
@@ -461,44 +436,23 @@ let AssetsController = (() => {
|
|
|
461
436
|
* @returns Array of InternalAccount objects from the selected account group.
|
|
462
437
|
*/
|
|
463
438
|
#getSelectedAccounts() {
|
|
464
|
-
const accounts = this
|
|
439
|
+
const accounts = this.messenger.call('AccountTreeController:getAccountsFromSelectedAccountGroup');
|
|
465
440
|
if (accounts.length > 0) {
|
|
466
441
|
return accounts;
|
|
467
442
|
}
|
|
468
|
-
const selectedAccount = this
|
|
443
|
+
const selectedAccount = this.messenger.call('AccountsController:getSelectedAccount');
|
|
469
444
|
if (selectedAccount) {
|
|
470
445
|
return [selectedAccount];
|
|
471
446
|
}
|
|
472
447
|
return [];
|
|
473
448
|
}
|
|
474
|
-
/**
|
|
475
|
-
* Run a messenger call, returning `fallback` if it throws.
|
|
476
|
-
*
|
|
477
|
-
* The wallet may construct this controller before (or without) the
|
|
478
|
-
* controllers it reads from. A missing handler means that controller is not
|
|
479
|
-
* ready, which is treated the same as "not initialized" rather than crashing
|
|
480
|
-
* the caller.
|
|
481
|
-
*
|
|
482
|
-
* @param call - The messenger call to run.
|
|
483
|
-
* @param fallback - The value to return if the call throws.
|
|
484
|
-
* @returns The call's result, or `fallback`.
|
|
485
|
-
*/
|
|
486
|
-
#callIfRegistered(call, fallback) {
|
|
487
|
-
try {
|
|
488
|
-
return call();
|
|
489
|
-
}
|
|
490
|
-
catch (error) {
|
|
491
|
-
log('Messenger call failed; treating dependency as not ready', error);
|
|
492
|
-
return fallback;
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
449
|
/**
|
|
496
450
|
* Whether `AccountTreeController.init()` has completed and the tree is ready.
|
|
497
451
|
*
|
|
498
452
|
* @returns True when the account tree has been initialized.
|
|
499
453
|
*/
|
|
500
454
|
#isAccountTreeInitialized() {
|
|
501
|
-
return this
|
|
455
|
+
return this.messenger.call('AccountTreeController:isInitialized');
|
|
502
456
|
}
|
|
503
457
|
/**
|
|
504
458
|
* Whether the client (UI) is open, read from ClientController state.
|
|
@@ -506,7 +460,7 @@ let AssetsController = (() => {
|
|
|
506
460
|
* @returns True when the UI is open.
|
|
507
461
|
*/
|
|
508
462
|
#isUiOpen() {
|
|
509
|
-
return
|
|
463
|
+
return clientControllerSelectors.selectIsUiOpen(this.messenger.call('ClientController:getState'));
|
|
510
464
|
}
|
|
511
465
|
/**
|
|
512
466
|
* Whether the keyring is unlocked, read from KeyringController.
|
|
@@ -514,7 +468,7 @@ let AssetsController = (() => {
|
|
|
514
468
|
* @returns True when the wallet vault is unlocked.
|
|
515
469
|
*/
|
|
516
470
|
#isKeyringUnlocked() {
|
|
517
|
-
return this
|
|
471
|
+
return this.messenger.call('KeyringController:isUnlocked');
|
|
518
472
|
}
|
|
519
473
|
#accountActivityDataSource;
|
|
520
474
|
#accountsApiDataSource;
|
|
@@ -569,9 +523,7 @@ let AssetsController = (() => {
|
|
|
569
523
|
captureException,
|
|
570
524
|
}));
|
|
571
525
|
}
|
|
572
|
-
this.#
|
|
573
|
-
this.#subscribeToBasicFunctionalityChange =
|
|
574
|
-
subscribeToBasicFunctionalityChange;
|
|
526
|
+
this.#initializeNativeAssetsMap(queryApiClient);
|
|
575
527
|
this.#onActiveChainsUpdated = (dataSourceName, chains, previousChains) => {
|
|
576
528
|
try {
|
|
577
529
|
this.#handleActiveChainsUpdate(dataSourceName, chains, previousChains);
|
|
@@ -656,23 +608,24 @@ let AssetsController = (() => {
|
|
|
656
608
|
log('Initializing AssetsController', {
|
|
657
609
|
defaultUpdateInterval: this.#defaultUpdateInterval,
|
|
658
610
|
});
|
|
659
|
-
|
|
660
|
-
// handlers. It never calls other controllers, so it does not depend on
|
|
661
|
-
// the order in which the wallet constructs them. Everything that reads
|
|
662
|
-
// other controllers or makes requests happens in `#bootstrap()`, the first
|
|
663
|
-
// time the UI opens.
|
|
611
|
+
this.#initializeState();
|
|
664
612
|
this.#subscribeToEvents();
|
|
665
613
|
this.#registerActionHandlers();
|
|
614
|
+
// Subscriptions start only when both UI is open and keyring unlocked -> #updateActive().
|
|
615
|
+
// Subscribe to basic-functionality changes after construction so a synchronous
|
|
616
|
+
// onChange during subscribe cannot run before data sources are initialized.
|
|
617
|
+
if (subscribeToBasicFunctionalityChange) {
|
|
618
|
+
const unsubscribe = subscribeToBasicFunctionalityChange((isBasic) => this.handleBasicFunctionalityChange(isBasic));
|
|
619
|
+
if (typeof unsubscribe === 'function') {
|
|
620
|
+
this.#unsubscribeBasicFunctionality = unsubscribe;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
666
623
|
}
|
|
667
624
|
// ============================================================================
|
|
668
625
|
// INITIALIZATION
|
|
669
626
|
// ============================================================================
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
* written by {@link AssetsController.#seedNativeAssetsMap}.
|
|
673
|
-
*/
|
|
674
|
-
#fetchNativeAssetsMap() {
|
|
675
|
-
this.#queryApiClient.queryClient
|
|
627
|
+
#initializeNativeAssetsMap(queryApiClient) {
|
|
628
|
+
queryApiClient.queryClient
|
|
676
629
|
.fetchQuery({
|
|
677
630
|
queryKey: NATIVE_ASSETS_QUERY_KEY,
|
|
678
631
|
queryFn: buildNativeAssetsFromApi,
|
|
@@ -684,13 +637,6 @@ let AssetsController = (() => {
|
|
|
684
637
|
// #isNativeAsset falls back to the seed data from buildNativeAssetsFromConstant.
|
|
685
638
|
log('Failed to populate native asset cache, falling back to seed data', error);
|
|
686
639
|
});
|
|
687
|
-
}
|
|
688
|
-
/**
|
|
689
|
-
* Seed the native asset map in the query cache from constants.
|
|
690
|
-
*
|
|
691
|
-
* @param queryApiClient - The API client whose cache to seed.
|
|
692
|
-
*/
|
|
693
|
-
#seedNativeAssetsMap(queryApiClient) {
|
|
694
640
|
// Seed the cache synchronously so that synchronous consumers (e.g.
|
|
695
641
|
// #isNativeAsset, #resolveNativeAssetIds) have data available immediately.
|
|
696
642
|
// When fetchQuery resolves (currently instant, future: API), it overwrites
|
|
@@ -698,89 +644,12 @@ let AssetsController = (() => {
|
|
|
698
644
|
const initialNativeAssetMap = buildNativeAssetsFromConstant();
|
|
699
645
|
queryApiClient.setCachedData(NATIVE_ASSETS_QUERY_KEY, initialNativeAssetMap);
|
|
700
646
|
}
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
* which time the wallet has constructed every controller. Only the first
|
|
708
|
-
* call does the work; later calls return the same promise.
|
|
709
|
-
*
|
|
710
|
-
* @returns A promise that resolves once bootstrapping has finished.
|
|
711
|
-
*/
|
|
712
|
-
async #bootstrap() {
|
|
713
|
-
this.#bootstrapPromise ??= this.#runBootstrap();
|
|
714
|
-
return this.#bootstrapPromise;
|
|
715
|
-
}
|
|
716
|
-
async #runBootstrap() {
|
|
717
|
-
log('Bootstrapping AssetsController');
|
|
718
|
-
this.#fetchNativeAssetsMap();
|
|
719
|
-
// Data sources report their active chains through `#onActiveChainsUpdated`
|
|
720
|
-
// while bootstrapping. Those reports are ignored until `#isBootstrapped`
|
|
721
|
-
// is set; `#updateActive()` below subscribes with the final chains.
|
|
722
|
-
await Promise.allSettled([...this.#allBalanceDataSources, this.#stakedBalanceDataSource].map(async (source) => source.bootstrap()));
|
|
723
|
-
if (this.#isDestroyed) {
|
|
724
|
-
return;
|
|
725
|
-
}
|
|
726
|
-
// Subscribe before marking the controller bootstrapped, so a listener the
|
|
727
|
-
// client calls synchronously is ignored by `handleBasicFunctionalityChange`
|
|
728
|
-
// instead of subscribing early and making `#start()` skip the forced
|
|
729
|
-
// startup fetch. Nothing is lost: `#updateActive()` below reads the
|
|
730
|
-
// current value through `isBasicFunctionality`.
|
|
731
|
-
this.#subscribeToBasicFunctionality();
|
|
732
|
-
// Subscribed here rather than in the constructor: by now the wallet has
|
|
733
|
-
// constructed NetworkEnablementController, so the selector starts from its
|
|
734
|
-
// current state and each change is diffed against the previous one.
|
|
735
|
-
this.messenger.subscribe('NetworkEnablementController:stateChange', (enabledNetworkMap, previousEnabledNetworkMap) => {
|
|
736
|
-
this.#handleEnabledNetworksChanged(enabledNetworkMap, previousEnabledNetworkMap).catch(console.error);
|
|
737
|
-
}, ({ enabledNetworkMap }) => enabledNetworkMap);
|
|
738
|
-
this.#isBootstrapped = true;
|
|
739
|
-
// `KeyringController:unlock` handlers skip their work before bootstrap,
|
|
740
|
-
// so run it now if the wallet was unlocked before the UI opened.
|
|
741
|
-
if (this.#isKeyringUnlocked()) {
|
|
742
|
-
await this.#runUnlockCleanups();
|
|
743
|
-
}
|
|
744
|
-
// `destroy()` may have run while the cleanups were awaited.
|
|
745
|
-
if (this.#isDestroyed) {
|
|
746
|
-
return;
|
|
747
|
-
}
|
|
748
|
-
this.#updateActive();
|
|
749
|
-
}
|
|
750
|
-
/**
|
|
751
|
-
* Call the client's `subscribeToBasicFunctionalityChange`, keeping the
|
|
752
|
-
* unsubscribe function it returns. If it throws, the error is logged and
|
|
753
|
-
* reported, and bootstrapping carries on without the subscription, so
|
|
754
|
-
* asset tracking still starts.
|
|
755
|
-
*/
|
|
756
|
-
#subscribeToBasicFunctionality() {
|
|
757
|
-
if (!this.#subscribeToBasicFunctionalityChange) {
|
|
758
|
-
return;
|
|
759
|
-
}
|
|
760
|
-
try {
|
|
761
|
-
const unsubscribe = this.#subscribeToBasicFunctionalityChange((isBasic) => this.handleBasicFunctionalityChange(isBasic));
|
|
762
|
-
if (typeof unsubscribe === 'function') {
|
|
763
|
-
this.#unsubscribeBasicFunctionality = unsubscribe;
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
catch (error) {
|
|
767
|
-
log('Failed to subscribe to basic functionality changes', error);
|
|
768
|
-
this.#captureException?.(error instanceof Error ? error : new Error(String(error)));
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
/**
|
|
772
|
-
* Remove balances outside the current scope and spam tokens. Runs on
|
|
773
|
-
* unlock, and at bootstrap when the wallet was already unlocked.
|
|
774
|
-
*/
|
|
775
|
-
async #runUnlockCleanups() {
|
|
776
|
-
try {
|
|
777
|
-
this.#runOutOfScopeBalanceCleanup();
|
|
778
|
-
}
|
|
779
|
-
catch {
|
|
780
|
-
/* Do nothing */
|
|
781
|
-
}
|
|
782
|
-
await this.#runSpamCleanup().catch(() => {
|
|
783
|
-
/* Do nothing */
|
|
647
|
+
#initializeState() {
|
|
648
|
+
const { enabledNetworkMap } = this.messenger.call('NetworkEnablementController:getState');
|
|
649
|
+
this.#enabledChains = this.#extractEnabledChains(enabledNetworkMap);
|
|
650
|
+
log('Initialized state', {
|
|
651
|
+
enabledNetworkMap,
|
|
652
|
+
enabledChains: this.#enabledChains,
|
|
784
653
|
});
|
|
785
654
|
}
|
|
786
655
|
/**
|
|
@@ -838,8 +707,10 @@ let AssetsController = (() => {
|
|
|
838
707
|
this.messenger.subscribe('AccountTreeController:uninitialized', () => {
|
|
839
708
|
this.#updateActive();
|
|
840
709
|
});
|
|
841
|
-
//
|
|
842
|
-
|
|
710
|
+
// Subscribe to network enablement changes (only enabledNetworkMap)
|
|
711
|
+
this.messenger.subscribe('NetworkEnablementController:stateChange', ({ enabledNetworkMap }) => {
|
|
712
|
+
this.#handleEnabledNetworksChanged(enabledNetworkMap).catch(console.error);
|
|
713
|
+
});
|
|
843
714
|
// When a network is added or removed from NetworkController, refresh
|
|
844
715
|
// assets across every data source so balances, prices, and metadata
|
|
845
716
|
// stay consistent. On add we also seed default tracked assets (e.g.
|
|
@@ -847,50 +718,34 @@ let AssetsController = (() => {
|
|
|
847
718
|
// entries appear immediately without waiting for it to also be
|
|
848
719
|
// enabled in NetworkEnablementController.
|
|
849
720
|
this.messenger.subscribe('NetworkController:networkAdded', (networkConfiguration) => {
|
|
850
|
-
// Seeding default tracked assets only updates state, so it runs even
|
|
851
|
-
// before bootstrap; the refresh fetches, so it waits for bootstrap.
|
|
852
721
|
this.#handleNetworkAdded(networkConfiguration.chainId);
|
|
853
|
-
if (!this.#isBootstrapped) {
|
|
854
|
-
return;
|
|
855
|
-
}
|
|
856
722
|
this.#refreshAssetsAfterNetworkAdded(networkConfiguration.chainId).catch((error) => {
|
|
857
723
|
log('Failed to refresh assets after network added', { error });
|
|
858
724
|
});
|
|
859
725
|
});
|
|
860
726
|
this.messenger.subscribe('NetworkController:networkRemoved', () => {
|
|
861
|
-
if (!this.#isBootstrapped) {
|
|
862
|
-
return;
|
|
863
|
-
}
|
|
864
727
|
this.#refreshAssetsAfterNetworkChange();
|
|
865
728
|
});
|
|
866
729
|
// Selected EVM network switch (network picker). Enablement changes are
|
|
867
730
|
// handled separately via NetworkEnablementController:stateChange.
|
|
868
731
|
this.messenger.subscribe('NetworkController:networkDidChange', (networkState) => {
|
|
869
|
-
if (!this.#isBootstrapped) {
|
|
870
|
-
return;
|
|
871
|
-
}
|
|
872
732
|
this.#handleNetworkDidChange(networkState).catch(console.error);
|
|
873
733
|
});
|
|
874
|
-
// Client + Keyring lifecycle:
|
|
875
|
-
|
|
876
|
-
this.messenger.subscribe('ClientController:stateChange', (isUiOpen) => {
|
|
877
|
-
if (!this.#isBootstrapped) {
|
|
878
|
-
if (isUiOpen) {
|
|
879
|
-
this.#bootstrap().catch((error) => {
|
|
880
|
-
log('Failed to bootstrap AssetsController', error);
|
|
881
|
-
});
|
|
882
|
-
}
|
|
883
|
-
return;
|
|
884
|
-
}
|
|
734
|
+
// Client + Keyring lifecycle: only run when UI is open AND keyring is unlocked
|
|
735
|
+
this.messenger.subscribe('ClientController:stateChange', () => {
|
|
885
736
|
this.#updateActive();
|
|
886
737
|
}, clientControllerSelectors.selectIsUiOpen);
|
|
887
738
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
888
739
|
this.messenger.subscribe('KeyringController:unlock', async () => {
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
740
|
+
try {
|
|
741
|
+
this.#runOutOfScopeBalanceCleanup();
|
|
742
|
+
}
|
|
743
|
+
catch {
|
|
744
|
+
/* Do nothing */
|
|
892
745
|
}
|
|
893
|
-
await this.#
|
|
746
|
+
await this.#runSpamCleanup().catch(() => {
|
|
747
|
+
/* Do nothing */
|
|
748
|
+
});
|
|
894
749
|
this.#updateActive();
|
|
895
750
|
});
|
|
896
751
|
this.messenger.subscribe('KeyringController:lock', () => {
|
|
@@ -900,9 +755,6 @@ let AssetsController = (() => {
|
|
|
900
755
|
// Ensures balances for the account making the transaction are updated
|
|
901
756
|
// (e.g. for gas estimations), except on AccountActivity-active chains.
|
|
902
757
|
this.messenger.subscribe('TransactionController:unapprovedTransactionAdded', (transactionMeta) => {
|
|
903
|
-
if (!this.#isBootstrapped) {
|
|
904
|
-
return;
|
|
905
|
-
}
|
|
906
758
|
this.#refreshAssetsForEVMTransaction(transactionMeta);
|
|
907
759
|
});
|
|
908
760
|
// Post-tx refresh via the full fetch pipeline (Accounts API + RPC fallback).
|
|
@@ -910,9 +762,6 @@ let AssetsController = (() => {
|
|
|
910
762
|
// RpcDataSource also listens for transactionConfirmed, but only refreshes
|
|
911
763
|
// chains it owns via an active subscription.
|
|
912
764
|
this.messenger.subscribe('TransactionController:transactionConfirmed', (transactionMeta) => {
|
|
913
|
-
if (!this.#isBootstrapped) {
|
|
914
|
-
return;
|
|
915
|
-
}
|
|
916
765
|
this.#refreshAssetsForEVMTransaction(transactionMeta);
|
|
917
766
|
});
|
|
918
767
|
// Non-EVM equivalent of the above: Snap keyrings report transaction
|
|
@@ -920,9 +769,6 @@ let AssetsController = (() => {
|
|
|
920
769
|
// not covered by AccountActivity (WebSocket down / unsupported), refresh
|
|
921
770
|
// via the Accounts API with the server cache bypassed.
|
|
922
771
|
this.messenger.subscribe('MultichainTransactionsController:transactionConfirmed', (transaction) => {
|
|
923
|
-
if (!this.#isBootstrapped) {
|
|
924
|
-
return;
|
|
925
|
-
}
|
|
926
772
|
this.#refreshAssetsForNonEvmTransaction(transaction);
|
|
927
773
|
});
|
|
928
774
|
}
|
|
@@ -1050,11 +896,6 @@ let AssetsController = (() => {
|
|
|
1050
896
|
* the keyring is unlocked, and the account tree has finished `init()`.
|
|
1051
897
|
*/
|
|
1052
898
|
#updateActive() {
|
|
1053
|
-
// Event subscriptions outlive `destroy()`, so lifecycle events can still
|
|
1054
|
-
// arrive; never start tracking on a destroyed controller.
|
|
1055
|
-
if (!this.#isBootstrapped || this.#isDestroyed) {
|
|
1056
|
-
return;
|
|
1057
|
-
}
|
|
1058
899
|
const shouldRun = this.#isUiOpen() &&
|
|
1059
900
|
this.#isKeyringUnlocked() &&
|
|
1060
901
|
this.#isAccountTreeInitialized();
|
|
@@ -1074,7 +915,7 @@ let AssetsController = (() => {
|
|
|
1074
915
|
const releaseLock = await this.#accountRefreshMutex.acquire();
|
|
1075
916
|
try {
|
|
1076
917
|
await this.getAssets(accounts, {
|
|
1077
|
-
chainIds: [...this.#
|
|
918
|
+
chainIds: [...this.#enabledChains],
|
|
1078
919
|
forceUpdate: true,
|
|
1079
920
|
});
|
|
1080
921
|
// Seed before subscribe so the price poll / update fetch sees natives
|
|
@@ -1114,10 +955,7 @@ let AssetsController = (() => {
|
|
|
1114
955
|
* @param previousChains - Previous chains; used to compute added/removed.
|
|
1115
956
|
*/
|
|
1116
957
|
#handleActiveChainsUpdate(dataSourceId, activeChains, previousChains) {
|
|
1117
|
-
if (!this.#
|
|
1118
|
-
!this.#isUiOpen() ||
|
|
1119
|
-
!this.#isKeyringUnlocked() ||
|
|
1120
|
-
!this.#isEnabled()) {
|
|
958
|
+
if (!this.#isUiOpen() || !this.#isKeyringUnlocked() || !this.#isEnabled()) {
|
|
1121
959
|
return;
|
|
1122
960
|
}
|
|
1123
961
|
log('Data source active chains changed', {
|
|
@@ -1171,7 +1009,7 @@ let AssetsController = (() => {
|
|
|
1171
1009
|
// PUBLIC API: QUERY METHODS
|
|
1172
1010
|
// ============================================================================
|
|
1173
1011
|
async getAssets(accounts, options) {
|
|
1174
|
-
const chainIds = options?.chainIds ?? [...this.#
|
|
1012
|
+
const chainIds = options?.chainIds ?? [...this.#enabledChains];
|
|
1175
1013
|
const assetTypes = options?.assetTypes ?? ['fungible'];
|
|
1176
1014
|
const dataTypes = options?.dataTypes ?? ['balance', 'metadata', 'price'];
|
|
1177
1015
|
if (accounts.length === 0 || chainIds.length === 0) {
|
|
@@ -2056,7 +1894,7 @@ let AssetsController = (() => {
|
|
|
2056
1894
|
* @returns Array of native asset IDs, one per enabled chain that has a registered identifier.
|
|
2057
1895
|
*/
|
|
2058
1896
|
#getNativeAssetIdsForEnabledChains() {
|
|
2059
|
-
return this.#resolveNativeAssetIds(this.#
|
|
1897
|
+
return this.#resolveNativeAssetIds(this.#enabledChains);
|
|
2060
1898
|
}
|
|
2061
1899
|
/**
|
|
2062
1900
|
* Returns native asset IDs for the chains that this account supports
|
|
@@ -2152,7 +1990,7 @@ let AssetsController = (() => {
|
|
|
2152
1990
|
// why mUSD appears on mainnet/Linea immediately (those are normally
|
|
2153
1991
|
// enabled at startup) but only appears on Monad once the user
|
|
2154
1992
|
// turns the Monad network on.
|
|
2155
|
-
const candidateChains = chainsToSeed ?? [...this.#
|
|
1993
|
+
const candidateChains = chainsToSeed ?? [...this.#enabledChains];
|
|
2156
1994
|
const targetChains = candidateChains.filter((chainId) => CHAINS_WITH_DEFAULT_TRACKED_ASSETS.has(chainId));
|
|
2157
1995
|
if (targetChains.length === 0) {
|
|
2158
1996
|
return;
|
|
@@ -2517,7 +2355,7 @@ let AssetsController = (() => {
|
|
|
2517
2355
|
*/
|
|
2518
2356
|
#start() {
|
|
2519
2357
|
const accounts = this.#getSelectedAccounts();
|
|
2520
|
-
const chainIds = [...this.#
|
|
2358
|
+
const chainIds = [...this.#enabledChains];
|
|
2521
2359
|
if (accounts.length === 0 || chainIds.length === 0) {
|
|
2522
2360
|
return;
|
|
2523
2361
|
}
|
|
@@ -2581,9 +2419,6 @@ let AssetsController = (() => {
|
|
|
2581
2419
|
* @param _isBasic - The new value (for call-site clarity; the getter is the source of truth).
|
|
2582
2420
|
*/
|
|
2583
2421
|
handleBasicFunctionalityChange(_isBasic) {
|
|
2584
|
-
if (!this.#isBootstrapped) {
|
|
2585
|
-
return;
|
|
2586
|
-
}
|
|
2587
2422
|
this.#stop();
|
|
2588
2423
|
this.#subscribeAssets();
|
|
2589
2424
|
}
|
|
@@ -2596,7 +2431,7 @@ let AssetsController = (() => {
|
|
|
2596
2431
|
*/
|
|
2597
2432
|
#subscribeAssets(options) {
|
|
2598
2433
|
const accounts = this.#getSelectedAccounts();
|
|
2599
|
-
const enabledChains = [...this.#
|
|
2434
|
+
const enabledChains = [...this.#enabledChains];
|
|
2600
2435
|
if (accounts.length === 0 || enabledChains.length === 0) {
|
|
2601
2436
|
return;
|
|
2602
2437
|
}
|
|
@@ -2893,7 +2728,7 @@ let AssetsController = (() => {
|
|
|
2893
2728
|
// Wildcard scope (e.g., "eip155:0" means all enabled chains in that namespace)
|
|
2894
2729
|
if (reference === '0') {
|
|
2895
2730
|
// Add enabled chains
|
|
2896
|
-
for (const chain of this.#
|
|
2731
|
+
for (const chain of this.#enabledChains) {
|
|
2897
2732
|
if (isCaipChainId(chain)) {
|
|
2898
2733
|
const chainParsed = parseCaipChainId(chain);
|
|
2899
2734
|
if (chainParsed.namespace === namespace) {
|
|
@@ -2951,7 +2786,7 @@ let AssetsController = (() => {
|
|
|
2951
2786
|
this.#ensureDefaultTrackedAssetsSeeded();
|
|
2952
2787
|
if (accounts.length > 0) {
|
|
2953
2788
|
await this.getAssets(accounts, {
|
|
2954
|
-
chainIds: [...this.#
|
|
2789
|
+
chainIds: [...this.#enabledChains],
|
|
2955
2790
|
forceUpdate: true,
|
|
2956
2791
|
});
|
|
2957
2792
|
}
|
|
@@ -2961,17 +2796,12 @@ let AssetsController = (() => {
|
|
|
2961
2796
|
releaseLock();
|
|
2962
2797
|
}
|
|
2963
2798
|
}
|
|
2964
|
-
async #handleEnabledNetworksChanged(enabledNetworkMap
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
// extra fetch, never a missed one.
|
|
2968
|
-
const previousChains = previousEnabledNetworkMap
|
|
2969
|
-
? this.#extractEnabledChains(previousEnabledNetworkMap)
|
|
2970
|
-
: new Set();
|
|
2971
|
-
const enabledChains = this.#extractEnabledChains(enabledNetworkMap);
|
|
2799
|
+
async #handleEnabledNetworksChanged(enabledNetworkMap) {
|
|
2800
|
+
const previousChains = this.#enabledChains;
|
|
2801
|
+
this.#enabledChains = this.#extractEnabledChains(enabledNetworkMap);
|
|
2972
2802
|
// Find newly enabled chains (in new set but not in previous)
|
|
2973
2803
|
const addedChains = [];
|
|
2974
|
-
for (const chain of enabledChains) {
|
|
2804
|
+
for (const chain of this.#enabledChains) {
|
|
2975
2805
|
if (!previousChains.has(chain)) {
|
|
2976
2806
|
addedChains.push(chain);
|
|
2977
2807
|
}
|
|
@@ -2979,13 +2809,13 @@ let AssetsController = (() => {
|
|
|
2979
2809
|
// Find disabled chains to clean up (in previous but not in new)
|
|
2980
2810
|
const removedChains = [];
|
|
2981
2811
|
for (const chain of previousChains) {
|
|
2982
|
-
if (!enabledChains.has(chain)) {
|
|
2812
|
+
if (!this.#enabledChains.has(chain)) {
|
|
2983
2813
|
removedChains.push(chain);
|
|
2984
2814
|
}
|
|
2985
2815
|
}
|
|
2986
2816
|
log('Enabled networks changed', {
|
|
2987
2817
|
previousCount: previousChains.size,
|
|
2988
|
-
newCount: enabledChains.size,
|
|
2818
|
+
newCount: this.#enabledChains.size,
|
|
2989
2819
|
addedChains,
|
|
2990
2820
|
removedChains,
|
|
2991
2821
|
});
|
|
@@ -3306,7 +3136,6 @@ let AssetsController = (() => {
|
|
|
3306
3136
|
// CLEANUP
|
|
3307
3137
|
// ============================================================================
|
|
3308
3138
|
destroy() {
|
|
3309
|
-
this.#isDestroyed = true;
|
|
3310
3139
|
log('Destroying AssetsController', {
|
|
3311
3140
|
dataSourceCount: this.#allBalanceDataSources.length,
|
|
3312
3141
|
subscriptionCount: this.#activeSubscriptions.size,
|