@metamask-previews/assets-controller 20.2.3-preview-55295a2 → 20.2.3-preview-70090cfe4
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 +17 -0
- package/dist/AssetsController.d.ts +7 -4
- package/dist/AssetsController.d.ts.map +1 -1
- package/dist/AssetsController.js +191 -40
- package/dist/AssetsController.js.map +1 -1
- package/dist/data-sources/AbstractDataSource.d.ts +13 -0
- package/dist/data-sources/AbstractDataSource.d.ts.map +1 -1
- package/dist/data-sources/AbstractDataSource.js +15 -0
- package/dist/data-sources/AbstractDataSource.js.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.d.ts +8 -0
- package/dist/data-sources/AccountsApiDataSource.d.ts.map +1 -1
- package/dist/data-sources/AccountsApiDataSource.js +23 -1
- package/dist/data-sources/AccountsApiDataSource.js.map +1 -1
- package/dist/data-sources/RpcDataSource.d.ts +8 -0
- package/dist/data-sources/RpcDataSource.d.ts.map +1 -1
- package/dist/data-sources/RpcDataSource.js +9 -0
- package/dist/data-sources/RpcDataSource.js.map +1 -1
- package/dist/data-sources/SnapDataSource.d.ts +8 -0
- package/dist/data-sources/SnapDataSource.d.ts.map +1 -1
- package/dist/data-sources/SnapDataSource.js +9 -1
- package/dist/data-sources/SnapDataSource.js.map +1 -1
- package/dist/data-sources/StakedBalanceDataSource.d.ts +10 -0
- package/dist/data-sources/StakedBalanceDataSource.d.ts.map +1 -1
- package/dist/data-sources/StakedBalanceDataSource.js +5 -2
- package/dist/data-sources/StakedBalanceDataSource.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Add `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.
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- **BREAKING:** `AssetsController` no longer calls other controllers or makes requests in its constructor; it bootstraps the first time the UI opens ([#11351](https://github.com/MetaMask/core/pull/11351))
|
|
18
|
+
- The constructor only subscribes to events and registers action handlers, so it no longer depends on the order in which controllers are constructed.
|
|
19
|
+
- The first `ClientController:stateChange` with `isUiOpen: true` reads `NetworkEnablementController:getState`, bootstraps the balance data sources, fetches the native asset map, calls `subscribeToBasicFunctionalityChange`, and runs the unlock cleanups if the keyring is already unlocked. Assets are then tracked as before, once the keyring is unlocked and the account tree is initialized.
|
|
20
|
+
- Until then, `NetworkEnablementController:stateChange` only records the enabled chains; network, transaction and `KeyringController:unlock` events and `handleBasicFunctionalityChange` are ignored.
|
|
21
|
+
- Clients must call `ClientController:setUiOpen(true)` when the UI opens, or assets are never loaded.
|
|
22
|
+
- **BREAKING:** `AccountsApiDataSource`, `RpcDataSource` and `SnapDataSource` no longer call other controllers or make requests in their constructors ([#11351](https://github.com/MetaMask/core/pull/11351))
|
|
23
|
+
- 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.
|
|
24
|
+
- `AccountsApiDataSource` ignores `RemoteFeatureFlagController:stateChange` until it has been bootstrapped.
|
|
25
|
+
- `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))
|
|
26
|
+
|
|
10
27
|
## [20.2.3]
|
|
11
28
|
|
|
12
29
|
### Changed
|
|
@@ -155,10 +155,13 @@ 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
|
-
*
|
|
158
|
+
* 4. **Client + Keyring Lifecycle**: The constructor never calls other
|
|
159
|
+
* controllers. The first time the UI opens (ClientController), the controller
|
|
160
|
+
* bootstraps: it reads enabled networks and bootstraps its data sources.
|
|
161
|
+
* After that it starts subscriptions only when both the UI is open and the
|
|
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.
|
|
162
165
|
*
|
|
163
166
|
* ## Architecture
|
|
164
167
|
*
|
|
@@ -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,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,oBAAoB,CAAC,QAAQ,EAAE,eAAe,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI,CAkC3E;IAED;;OAEG;IACH,sBAAsB,IAAI,IAAI,CAS7B;IA23BD;;;;;;;OAOG;IACH,8BAA8B,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAMtD;IAkqBD;;;;;;;;;OASG;IACG,kBAAkB,CACtB,QAAQ,EAAE,YAAY,EACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,IAAI,CAAC,CAYf;IAsMD,OAAO,IAAI,IAAI,CAqDd;CACF"}
|
package/dist/AssetsController.js
CHANGED
|
@@ -321,10 +321,13 @@ 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
|
-
*
|
|
324
|
+
* 4. **Client + Keyring Lifecycle**: The constructor never calls other
|
|
325
|
+
* controllers. The first time the UI opens (ClientController), the controller
|
|
326
|
+
* bootstraps: it reads enabled networks and bootstraps its data sources.
|
|
327
|
+
* After that it starts subscriptions only when both the UI is open and the
|
|
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.
|
|
328
331
|
*
|
|
329
332
|
* ## Architecture
|
|
330
333
|
*
|
|
@@ -426,8 +429,23 @@ let AssetsController = (() => {
|
|
|
426
429
|
* its forced `getAssets()` call) runs a second time for the same accounts.
|
|
427
430
|
*/
|
|
428
431
|
#startInFlight = false;
|
|
429
|
-
/**
|
|
432
|
+
/**
|
|
433
|
+
* Currently enabled chains from NetworkEnablementController.
|
|
434
|
+
*
|
|
435
|
+
* Empty until `NetworkEnablementController:stateChange` is published or the
|
|
436
|
+
* controller is bootstrapped, because the constructor must not read other
|
|
437
|
+
* controllers' state.
|
|
438
|
+
*/
|
|
430
439
|
#enabledChains = new Set();
|
|
440
|
+
/**
|
|
441
|
+
* Whether `#bootstrap()` has finished. Until then, event handlers only
|
|
442
|
+
* record state (such as enabled chains) and never fetch.
|
|
443
|
+
*/
|
|
444
|
+
#isBootstrapped = false;
|
|
445
|
+
/** Set by the first `#bootstrap()` call; later calls reuse it. */
|
|
446
|
+
#bootstrapPromise = null;
|
|
447
|
+
#isDestroyed = false;
|
|
448
|
+
#subscribeToBasicFunctionalityChange;
|
|
431
449
|
/**
|
|
432
450
|
* Get the currently selected accounts from AccountTreeController.
|
|
433
451
|
* This includes all accounts in the same group as the selected account
|
|
@@ -436,23 +454,44 @@ let AssetsController = (() => {
|
|
|
436
454
|
* @returns Array of InternalAccount objects from the selected account group.
|
|
437
455
|
*/
|
|
438
456
|
#getSelectedAccounts() {
|
|
439
|
-
const accounts = this.messenger.call('AccountTreeController:getAccountsFromSelectedAccountGroup');
|
|
457
|
+
const accounts = this.#callIfRegistered(() => this.messenger.call('AccountTreeController:getAccountsFromSelectedAccountGroup'), []);
|
|
440
458
|
if (accounts.length > 0) {
|
|
441
459
|
return accounts;
|
|
442
460
|
}
|
|
443
|
-
const selectedAccount = this.messenger.call('AccountsController:getSelectedAccount');
|
|
461
|
+
const selectedAccount = this.#callIfRegistered(() => this.messenger.call('AccountsController:getSelectedAccount'), undefined);
|
|
444
462
|
if (selectedAccount) {
|
|
445
463
|
return [selectedAccount];
|
|
446
464
|
}
|
|
447
465
|
return [];
|
|
448
466
|
}
|
|
467
|
+
/**
|
|
468
|
+
* Run a messenger call, returning `fallback` if it throws.
|
|
469
|
+
*
|
|
470
|
+
* The wallet may construct this controller before (or without) the
|
|
471
|
+
* controllers it reads from. A missing handler means that controller is not
|
|
472
|
+
* ready, which is treated the same as "not initialized" rather than crashing
|
|
473
|
+
* the caller.
|
|
474
|
+
*
|
|
475
|
+
* @param call - The messenger call to run.
|
|
476
|
+
* @param fallback - The value to return if the call throws.
|
|
477
|
+
* @returns The call's result, or `fallback`.
|
|
478
|
+
*/
|
|
479
|
+
#callIfRegistered(call, fallback) {
|
|
480
|
+
try {
|
|
481
|
+
return call();
|
|
482
|
+
}
|
|
483
|
+
catch (error) {
|
|
484
|
+
log('Messenger call failed; treating dependency as not ready', error);
|
|
485
|
+
return fallback;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
449
488
|
/**
|
|
450
489
|
* Whether `AccountTreeController.init()` has completed and the tree is ready.
|
|
451
490
|
*
|
|
452
491
|
* @returns True when the account tree has been initialized.
|
|
453
492
|
*/
|
|
454
493
|
#isAccountTreeInitialized() {
|
|
455
|
-
return this.messenger.call('AccountTreeController:isInitialized');
|
|
494
|
+
return this.#callIfRegistered(() => this.messenger.call('AccountTreeController:isInitialized'), false);
|
|
456
495
|
}
|
|
457
496
|
/**
|
|
458
497
|
* Whether the client (UI) is open, read from ClientController state.
|
|
@@ -460,7 +499,7 @@ let AssetsController = (() => {
|
|
|
460
499
|
* @returns True when the UI is open.
|
|
461
500
|
*/
|
|
462
501
|
#isUiOpen() {
|
|
463
|
-
return clientControllerSelectors.selectIsUiOpen(this.messenger.call('ClientController:getState'));
|
|
502
|
+
return this.#callIfRegistered(() => clientControllerSelectors.selectIsUiOpen(this.messenger.call('ClientController:getState')), false);
|
|
464
503
|
}
|
|
465
504
|
/**
|
|
466
505
|
* Whether the keyring is unlocked, read from KeyringController.
|
|
@@ -468,7 +507,7 @@ let AssetsController = (() => {
|
|
|
468
507
|
* @returns True when the wallet vault is unlocked.
|
|
469
508
|
*/
|
|
470
509
|
#isKeyringUnlocked() {
|
|
471
|
-
return this.messenger.call('KeyringController:isUnlocked');
|
|
510
|
+
return this.#callIfRegistered(() => this.messenger.call('KeyringController:isUnlocked'), false);
|
|
472
511
|
}
|
|
473
512
|
#accountActivityDataSource;
|
|
474
513
|
#accountsApiDataSource;
|
|
@@ -523,7 +562,9 @@ let AssetsController = (() => {
|
|
|
523
562
|
captureException,
|
|
524
563
|
}));
|
|
525
564
|
}
|
|
526
|
-
this.#
|
|
565
|
+
this.#seedNativeAssetsMap(queryApiClient);
|
|
566
|
+
this.#subscribeToBasicFunctionalityChange =
|
|
567
|
+
subscribeToBasicFunctionalityChange;
|
|
527
568
|
this.#onActiveChainsUpdated = (dataSourceName, chains, previousChains) => {
|
|
528
569
|
try {
|
|
529
570
|
this.#handleActiveChainsUpdate(dataSourceName, chains, previousChains);
|
|
@@ -608,24 +649,23 @@ let AssetsController = (() => {
|
|
|
608
649
|
log('Initializing AssetsController', {
|
|
609
650
|
defaultUpdateInterval: this.#defaultUpdateInterval,
|
|
610
651
|
});
|
|
611
|
-
|
|
652
|
+
// The constructor only subscribes to events and registers action
|
|
653
|
+
// handlers. It never calls other controllers, so it does not depend on
|
|
654
|
+
// the order in which the wallet constructs them. Everything that reads
|
|
655
|
+
// other controllers or makes requests happens in `#bootstrap()`, the first
|
|
656
|
+
// time the UI opens.
|
|
612
657
|
this.#subscribeToEvents();
|
|
613
658
|
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
|
-
}
|
|
623
659
|
}
|
|
624
660
|
// ============================================================================
|
|
625
661
|
// INITIALIZATION
|
|
626
662
|
// ============================================================================
|
|
627
|
-
|
|
628
|
-
|
|
663
|
+
/**
|
|
664
|
+
* Fetch the native asset map into the query cache, replacing the seed data
|
|
665
|
+
* written by {@link AssetsController.#seedNativeAssetsMap}.
|
|
666
|
+
*/
|
|
667
|
+
#fetchNativeAssetsMap() {
|
|
668
|
+
this.#queryApiClient.queryClient
|
|
629
669
|
.fetchQuery({
|
|
630
670
|
queryKey: NATIVE_ASSETS_QUERY_KEY,
|
|
631
671
|
queryFn: buildNativeAssetsFromApi,
|
|
@@ -637,6 +677,13 @@ let AssetsController = (() => {
|
|
|
637
677
|
// #isNativeAsset falls back to the seed data from buildNativeAssetsFromConstant.
|
|
638
678
|
log('Failed to populate native asset cache, falling back to seed data', error);
|
|
639
679
|
});
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Seed the native asset map in the query cache from constants.
|
|
683
|
+
*
|
|
684
|
+
* @param queryApiClient - The API client whose cache to seed.
|
|
685
|
+
*/
|
|
686
|
+
#seedNativeAssetsMap(queryApiClient) {
|
|
640
687
|
// Seed the cache synchronously so that synchronous consumers (e.g.
|
|
641
688
|
// #isNativeAsset, #resolveNativeAssetIds) have data available immediately.
|
|
642
689
|
// When fetchQuery resolves (currently instant, future: API), it overwrites
|
|
@@ -644,12 +691,76 @@ let AssetsController = (() => {
|
|
|
644
691
|
const initialNativeAssetMap = buildNativeAssetsFromConstant();
|
|
645
692
|
queryApiClient.setCachedData(NATIVE_ASSETS_QUERY_KEY, initialNativeAssetMap);
|
|
646
693
|
}
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
694
|
+
/**
|
|
695
|
+
* Finish the work the constructor defers: read enabled networks, bootstrap
|
|
696
|
+
* the data sources and subscribe to basic-functionality changes, then start
|
|
697
|
+
* tracking assets if the keyring is unlocked and the account tree is ready.
|
|
698
|
+
*
|
|
699
|
+
* Runs the first time the UI opens (`ClientController:stateChange`), by
|
|
700
|
+
* which time the wallet has constructed every controller. Only the first
|
|
701
|
+
* call does the work; later calls return the same promise.
|
|
702
|
+
*
|
|
703
|
+
* @returns A promise that resolves once bootstrapping has finished.
|
|
704
|
+
*/
|
|
705
|
+
async #bootstrap() {
|
|
706
|
+
this.#bootstrapPromise ??= this.#runBootstrap();
|
|
707
|
+
return this.#bootstrapPromise;
|
|
708
|
+
}
|
|
709
|
+
async #runBootstrap() {
|
|
710
|
+
log('Bootstrapping AssetsController');
|
|
711
|
+
this.#readEnabledChains();
|
|
712
|
+
this.#fetchNativeAssetsMap();
|
|
713
|
+
// Data sources report their active chains through `#onActiveChainsUpdated`
|
|
714
|
+
// while bootstrapping. Those reports are ignored until `#isBootstrapped`
|
|
715
|
+
// is set; `#updateActive()` below subscribes with the final chains.
|
|
716
|
+
await Promise.allSettled([...this.#allBalanceDataSources, this.#stakedBalanceDataSource].map(async (source) => source.bootstrap()));
|
|
717
|
+
if (this.#isDestroyed) {
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
this.#isBootstrapped = true;
|
|
721
|
+
if (this.#subscribeToBasicFunctionalityChange) {
|
|
722
|
+
const unsubscribe = this.#subscribeToBasicFunctionalityChange((isBasic) => this.handleBasicFunctionalityChange(isBasic));
|
|
723
|
+
if (typeof unsubscribe === 'function') {
|
|
724
|
+
this.#unsubscribeBasicFunctionality = unsubscribe;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
// `KeyringController:unlock` handlers skip their work before bootstrap,
|
|
728
|
+
// so run it now if the wallet was unlocked before the UI opened.
|
|
729
|
+
if (this.#isKeyringUnlocked()) {
|
|
730
|
+
await this.#runUnlockCleanups();
|
|
731
|
+
}
|
|
732
|
+
this.#updateActive();
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Read enabled chains from NetworkEnablementController.
|
|
736
|
+
*
|
|
737
|
+
* `NetworkEnablementController:stateChange` keeps `#enabledChains` current,
|
|
738
|
+
* but it is only published when the state changes. If the controller
|
|
739
|
+
* restored persisted state and nothing has changed since, this read is the
|
|
740
|
+
* only way to learn which chains are enabled. If the controller is not
|
|
741
|
+
* registered, the chains received from events are kept.
|
|
742
|
+
*/
|
|
743
|
+
#readEnabledChains() {
|
|
744
|
+
const enabledNetworkMap = this.#callIfRegistered(() => this.messenger.call('NetworkEnablementController:getState')
|
|
745
|
+
.enabledNetworkMap, undefined);
|
|
746
|
+
if (enabledNetworkMap) {
|
|
747
|
+
this.#enabledChains = this.#extractEnabledChains(enabledNetworkMap);
|
|
748
|
+
}
|
|
749
|
+
log('Read enabled chains', { enabledChains: this.#enabledChains });
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* Remove balances outside the current scope and spam tokens. Runs on
|
|
753
|
+
* unlock, and at bootstrap when the wallet was already unlocked.
|
|
754
|
+
*/
|
|
755
|
+
async #runUnlockCleanups() {
|
|
756
|
+
try {
|
|
757
|
+
this.#runOutOfScopeBalanceCleanup();
|
|
758
|
+
}
|
|
759
|
+
catch {
|
|
760
|
+
/* Do nothing */
|
|
761
|
+
}
|
|
762
|
+
await this.#runSpamCleanup().catch(() => {
|
|
763
|
+
/* Do nothing */
|
|
653
764
|
});
|
|
654
765
|
}
|
|
655
766
|
/**
|
|
@@ -709,6 +820,11 @@ let AssetsController = (() => {
|
|
|
709
820
|
});
|
|
710
821
|
// Subscribe to network enablement changes (only enabledNetworkMap)
|
|
711
822
|
this.messenger.subscribe('NetworkEnablementController:stateChange', ({ enabledNetworkMap }) => {
|
|
823
|
+
if (!this.#isBootstrapped) {
|
|
824
|
+
// Only record the chains; `#bootstrap()` starts fetching.
|
|
825
|
+
this.#enabledChains = this.#extractEnabledChains(enabledNetworkMap);
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
712
828
|
this.#handleEnabledNetworksChanged(enabledNetworkMap).catch(console.error);
|
|
713
829
|
});
|
|
714
830
|
// When a network is added or removed from NetworkController, refresh
|
|
@@ -718,34 +834,50 @@ let AssetsController = (() => {
|
|
|
718
834
|
// entries appear immediately without waiting for it to also be
|
|
719
835
|
// enabled in NetworkEnablementController.
|
|
720
836
|
this.messenger.subscribe('NetworkController:networkAdded', (networkConfiguration) => {
|
|
837
|
+
// Seeding default tracked assets only updates state, so it runs even
|
|
838
|
+
// before bootstrap; the refresh fetches, so it waits for bootstrap.
|
|
721
839
|
this.#handleNetworkAdded(networkConfiguration.chainId);
|
|
840
|
+
if (!this.#isBootstrapped) {
|
|
841
|
+
return;
|
|
842
|
+
}
|
|
722
843
|
this.#refreshAssetsAfterNetworkAdded(networkConfiguration.chainId).catch((error) => {
|
|
723
844
|
log('Failed to refresh assets after network added', { error });
|
|
724
845
|
});
|
|
725
846
|
});
|
|
726
847
|
this.messenger.subscribe('NetworkController:networkRemoved', () => {
|
|
848
|
+
if (!this.#isBootstrapped) {
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
727
851
|
this.#refreshAssetsAfterNetworkChange();
|
|
728
852
|
});
|
|
729
853
|
// Selected EVM network switch (network picker). Enablement changes are
|
|
730
854
|
// handled separately via NetworkEnablementController:stateChange.
|
|
731
855
|
this.messenger.subscribe('NetworkController:networkDidChange', (networkState) => {
|
|
856
|
+
if (!this.#isBootstrapped) {
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
732
859
|
this.#handleNetworkDidChange(networkState).catch(console.error);
|
|
733
860
|
});
|
|
734
|
-
// Client + Keyring lifecycle:
|
|
735
|
-
|
|
861
|
+
// Client + Keyring lifecycle: the first time the UI opens, bootstrap.
|
|
862
|
+
// After that, only run when UI is open AND keyring is unlocked.
|
|
863
|
+
this.messenger.subscribe('ClientController:stateChange', (isUiOpen) => {
|
|
864
|
+
if (!this.#isBootstrapped) {
|
|
865
|
+
if (isUiOpen) {
|
|
866
|
+
this.#bootstrap().catch((error) => {
|
|
867
|
+
log('Failed to bootstrap AssetsController', error);
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
736
872
|
this.#updateActive();
|
|
737
873
|
}, clientControllerSelectors.selectIsUiOpen);
|
|
738
874
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
739
875
|
this.messenger.subscribe('KeyringController:unlock', async () => {
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
catch {
|
|
744
|
-
/* Do nothing */
|
|
876
|
+
// Before bootstrap, `#bootstrap()` runs the cleanups itself.
|
|
877
|
+
if (!this.#isBootstrapped) {
|
|
878
|
+
return;
|
|
745
879
|
}
|
|
746
|
-
await this.#
|
|
747
|
-
/* Do nothing */
|
|
748
|
-
});
|
|
880
|
+
await this.#runUnlockCleanups();
|
|
749
881
|
this.#updateActive();
|
|
750
882
|
});
|
|
751
883
|
this.messenger.subscribe('KeyringController:lock', () => {
|
|
@@ -755,6 +887,9 @@ let AssetsController = (() => {
|
|
|
755
887
|
// Ensures balances for the account making the transaction are updated
|
|
756
888
|
// (e.g. for gas estimations), except on AccountActivity-active chains.
|
|
757
889
|
this.messenger.subscribe('TransactionController:unapprovedTransactionAdded', (transactionMeta) => {
|
|
890
|
+
if (!this.#isBootstrapped) {
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
758
893
|
this.#refreshAssetsForEVMTransaction(transactionMeta);
|
|
759
894
|
});
|
|
760
895
|
// Post-tx refresh via the full fetch pipeline (Accounts API + RPC fallback).
|
|
@@ -762,6 +897,9 @@ let AssetsController = (() => {
|
|
|
762
897
|
// RpcDataSource also listens for transactionConfirmed, but only refreshes
|
|
763
898
|
// chains it owns via an active subscription.
|
|
764
899
|
this.messenger.subscribe('TransactionController:transactionConfirmed', (transactionMeta) => {
|
|
900
|
+
if (!this.#isBootstrapped) {
|
|
901
|
+
return;
|
|
902
|
+
}
|
|
765
903
|
this.#refreshAssetsForEVMTransaction(transactionMeta);
|
|
766
904
|
});
|
|
767
905
|
// Non-EVM equivalent of the above: Snap keyrings report transaction
|
|
@@ -769,6 +907,9 @@ let AssetsController = (() => {
|
|
|
769
907
|
// not covered by AccountActivity (WebSocket down / unsupported), refresh
|
|
770
908
|
// via the Accounts API with the server cache bypassed.
|
|
771
909
|
this.messenger.subscribe('MultichainTransactionsController:transactionConfirmed', (transaction) => {
|
|
910
|
+
if (!this.#isBootstrapped) {
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
772
913
|
this.#refreshAssetsForNonEvmTransaction(transaction);
|
|
773
914
|
});
|
|
774
915
|
}
|
|
@@ -896,6 +1037,9 @@ let AssetsController = (() => {
|
|
|
896
1037
|
* the keyring is unlocked, and the account tree has finished `init()`.
|
|
897
1038
|
*/
|
|
898
1039
|
#updateActive() {
|
|
1040
|
+
if (!this.#isBootstrapped) {
|
|
1041
|
+
return;
|
|
1042
|
+
}
|
|
899
1043
|
const shouldRun = this.#isUiOpen() &&
|
|
900
1044
|
this.#isKeyringUnlocked() &&
|
|
901
1045
|
this.#isAccountTreeInitialized();
|
|
@@ -955,7 +1099,10 @@ let AssetsController = (() => {
|
|
|
955
1099
|
* @param previousChains - Previous chains; used to compute added/removed.
|
|
956
1100
|
*/
|
|
957
1101
|
#handleActiveChainsUpdate(dataSourceId, activeChains, previousChains) {
|
|
958
|
-
if (!this.#
|
|
1102
|
+
if (!this.#isBootstrapped ||
|
|
1103
|
+
!this.#isUiOpen() ||
|
|
1104
|
+
!this.#isKeyringUnlocked() ||
|
|
1105
|
+
!this.#isEnabled()) {
|
|
959
1106
|
return;
|
|
960
1107
|
}
|
|
961
1108
|
log('Data source active chains changed', {
|
|
@@ -2419,6 +2566,9 @@ let AssetsController = (() => {
|
|
|
2419
2566
|
* @param _isBasic - The new value (for call-site clarity; the getter is the source of truth).
|
|
2420
2567
|
*/
|
|
2421
2568
|
handleBasicFunctionalityChange(_isBasic) {
|
|
2569
|
+
if (!this.#isBootstrapped) {
|
|
2570
|
+
return;
|
|
2571
|
+
}
|
|
2422
2572
|
this.#stop();
|
|
2423
2573
|
this.#subscribeAssets();
|
|
2424
2574
|
}
|
|
@@ -3136,6 +3286,7 @@ let AssetsController = (() => {
|
|
|
3136
3286
|
// CLEANUP
|
|
3137
3287
|
// ============================================================================
|
|
3138
3288
|
destroy() {
|
|
3289
|
+
this.#isDestroyed = true;
|
|
3139
3290
|
log('Destroying AssetsController', {
|
|
3140
3291
|
dataSourceCount: this.#allBalanceDataSources.length,
|
|
3141
3292
|
subscriptionCount: this.#activeSubscriptions.size,
|