@metamask-previews/assets-controller 20.1.0-preview-543acb9 → 20.2.0-preview-fbb37663c
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 +29 -1
- package/dist/AssetsController.d.ts +12 -2
- package/dist/AssetsController.d.ts.map +1 -1
- package/dist/AssetsController.js +150 -7
- package/dist/AssetsController.js.map +1 -1
- package/dist/data-sources/AccountActivityDataSource.d.ts.map +1 -1
- package/dist/data-sources/AccountActivityDataSource.js +19 -3
- package/dist/data-sources/AccountActivityDataSource.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 +17 -1
- package/dist/data-sources/AccountsApiDataSource.js.map +1 -1
- package/dist/data-sources/RpcDataSource.d.ts +5 -2
- package/dist/data-sources/RpcDataSource.d.ts.map +1 -1
- package/dist/data-sources/RpcDataSource.js +5 -3
- package/dist/data-sources/RpcDataSource.js.map +1 -1
- package/dist/data-sources/SnapDataSource.d.ts +9 -0
- package/dist/data-sources/SnapDataSource.d.ts.map +1 -1
- package/dist/data-sources/SnapDataSource.js +10 -1
- package/dist/data-sources/SnapDataSource.js.map +1 -1
- package/dist/data-sources/StakedBalanceDataSource.d.ts +9 -0
- package/dist/data-sources/StakedBalanceDataSource.d.ts.map +1 -1
- package/dist/data-sources/StakedBalanceDataSource.js +10 -0
- package/dist/data-sources/StakedBalanceDataSource.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,9 +7,36 @@ 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 `init()`, which reads enabled chains from `NetworkEnablementController:getState` after every controller has been constructed. Later enablement changes still arrive on `NetworkEnablementController:stateChange` ([#10885](https://github.com/MetaMask/core/pull/10885))
|
|
13
|
+
- `init()` refreshes data sources that read other controllers through the messenger: `RpcDataSource.refreshActiveChainsFromNetworkState()` (`NetworkController:getState`), `StakedBalanceDataSource.refreshActiveChainsFromNetworkEnablementState()` (`NetworkEnablementController:getState`), `SnapDataSource.init()` (snap discovery), and `AccountsApiDataSource.init()` (supported networks and `RemoteFeatureFlagController:getState`).
|
|
14
|
+
- Add `SnapDataSource.init()` and `AccountsApiDataSource.init()` ([#10885](https://github.com/MetaMask/core/pull/10885))
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- **BREAKING:** Subscribe to `AccountsController:selectedAccountChange` so a selected-account switch refreshes tracked assets when `AccountTreeController` is not registered ([#10885](https://github.com/MetaMask/core/pull/10885))
|
|
19
|
+
- Hosts that restrict which events flow through the `AssetsController` messenger must also delegate `AccountsController:selectedAccountChange`.
|
|
20
|
+
- When `AccountTreeController` is registered, that event is ignored. Group switches still refresh only through `AccountTreeController:selectedAccountGroupChange`, so the two events are not both handled.
|
|
21
|
+
- **BREAKING:** Constructors no longer call messenger actions. Call `AssetsController.init()` after the other controllers exist. `Wallet.init()` does this. Until `init()` runs, enabled chains and data-source active chains stay empty unless a later state change arrives ([#10885](https://github.com/MetaMask/core/pull/10885))
|
|
22
|
+
- `AssetsController` no longer calls `NetworkEnablementController:getState` in its constructor.
|
|
23
|
+
- `RpcDataSource` no longer calls `NetworkController:getState` in its constructor. Call `refreshActiveChainsFromNetworkState()`, or `AssetsController.init()`.
|
|
24
|
+
- `StakedBalanceDataSource` no longer calls `NetworkEnablementController:getState` in its constructor. Call `refreshActiveChainsFromNetworkEnablementState()`, or `AssetsController.init()`.
|
|
25
|
+
- `SnapDataSource` no longer calls `SnapController:getRunnableSnaps` in its constructor. Call `init()`. When `SnapController` is not registered, discovery leaves active chains empty.
|
|
26
|
+
- `AccountsApiDataSource` no longer starts its supported-network fetch, which calls `RemoteFeatureFlagController:getState`, from the constructor. Call `init()`.
|
|
27
|
+
- When `AccountTreeController` actions are not registered, selected-account reads fall back to `AccountsController:getSelectedAccount`, and asset tracking does not wait for account-tree initialization ([#10885](https://github.com/MetaMask/core/pull/10885))
|
|
28
|
+
- `AccountActivityDataSource` uses the same fallback when resolving the account for a balance update.
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
|
|
32
|
+
- Refresh the newly selected account after startup completes when it changes while the initial asset fetch is in progress ([#10885](https://github.com/MetaMask/core/pull/10885))
|
|
33
|
+
|
|
34
|
+
## [20.2.0]
|
|
35
|
+
|
|
10
36
|
### Changed
|
|
11
37
|
|
|
12
38
|
- Use SLIP-44 coin type 16661 for the 0G native asset ([#11221](https://github.com/MetaMask/core/pull/11221))
|
|
39
|
+
- Bump `@metamask/assets-controllers` from `^113.0.1` to `^113.1.0` ([#11255](https://github.com/MetaMask/core/pull/11255))
|
|
13
40
|
|
|
14
41
|
## [20.1.0]
|
|
15
42
|
|
|
@@ -1229,7 +1256,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
1229
1256
|
- Refactor `RpcDataSource` to delegate polling to `BalanceFetcher` and `TokenDetector` services ([#7709](https://github.com/MetaMask/core/pull/7709))
|
|
1230
1257
|
- Refactor `BalanceFetcher` and `TokenDetector` to extend `StaticIntervalPollingControllerOnly` for independent polling management ([#7709](https://github.com/MetaMask/core/pull/7709))
|
|
1231
1258
|
|
|
1232
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@20.
|
|
1259
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@20.2.0...HEAD
|
|
1260
|
+
[20.2.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@20.1.0...@metamask/assets-controller@20.2.0
|
|
1233
1261
|
[20.1.0]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@20.0.2...@metamask/assets-controller@20.1.0
|
|
1234
1262
|
[20.0.2]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@20.0.1...@metamask/assets-controller@20.0.2
|
|
1235
1263
|
[20.0.1]: https://github.com/MetaMask/core/compare/@metamask/assets-controller@20.0.0...@metamask/assets-controller@20.0.1
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AccountTreeControllerGetAccountsFromSelectedAccountGroupAction, AccountTreeControllerInitializedEvent, AccountTreeControllerIsInitializedAction, AccountTreeControllerSelectedAccountGroupChangeEvent, AccountTreeControllerUninitializedEvent } from '@metamask/account-tree-controller';
|
|
2
|
-
import type { AccountsControllerGetSelectedAccountAction } from '@metamask/accounts-controller';
|
|
2
|
+
import type { AccountsControllerGetSelectedAccountAction, AccountsControllerSelectedAccountChangeEvent } from '@metamask/accounts-controller';
|
|
3
3
|
import { BaseController } from '@metamask/base-controller';
|
|
4
4
|
import type { ControllerGetStateAction, ControllerStateChangeEvent } from '@metamask/base-controller';
|
|
5
5
|
import type { ClientControllerGetStateAction, ClientControllerStateChangeEvent } from '@metamask/client-controller';
|
|
@@ -74,7 +74,7 @@ export type AssetsControllerPriceChangedEvent = {
|
|
|
74
74
|
};
|
|
75
75
|
export type AssetsControllerEvents = AssetsControllerStateChangeEvent | AssetsControllerBalanceChangedEvent | AssetsControllerPriceChangedEvent;
|
|
76
76
|
type AllowedActions = AccountsControllerGetSelectedAccountAction | AccountTreeControllerGetAccountsFromSelectedAccountGroupAction | AccountTreeControllerIsInitializedAction | ClientControllerGetStateAction | KeyringControllerIsUnlockedAction | NetworkControllerGetStateAction | NetworkControllerGetNetworkClientByIdAction | ConfigRegistryControllerGetNetworkConfigByCaip2ChainIdAction | NetworkEnablementControllerGetStateAction | SnapControllerGetRunnableSnapsAction | SnapControllerHandleRequestAction | GetPermissions | PhishingControllerBulkScanTokensAction | RemoteFeatureFlagControllerGetStateAction;
|
|
77
|
-
type AllowedEvents = AccountTreeControllerSelectedAccountGroupChangeEvent | AccountTreeControllerInitializedEvent | AccountTreeControllerUninitializedEvent | ClientControllerStateChangeEvent | KeyringControllerLockEvent | KeyringControllerUnlockEvent | PreferencesControllerStateChangeEvent | TransactionControllerUnapprovedTransactionAddedEvent | TransactionControllerTransactionConfirmedEvent | MultichainTransactionsControllerTransactionConfirmedEvent | NetworkControllerStateChangeEvent | NetworkControllerNetworkAddedEvent | NetworkControllerNetworkDidChangeEvent | NetworkControllerNetworkRemovedEvent | NetworkEnablementControllerEvents | AccountsControllerAccountBalancesUpdatedEvent | PermissionControllerStateChange | SnapControllerSnapInstalledEvent | AccountActivityServiceBalanceUpdatedEvent | AccountActivityServiceStatusChangedEvent | RemoteFeatureFlagControllerStateChangeEvent;
|
|
77
|
+
type AllowedEvents = AccountTreeControllerSelectedAccountGroupChangeEvent | AccountTreeControllerInitializedEvent | AccountTreeControllerUninitializedEvent | AccountsControllerSelectedAccountChangeEvent | ClientControllerStateChangeEvent | KeyringControllerLockEvent | KeyringControllerUnlockEvent | PreferencesControllerStateChangeEvent | TransactionControllerUnapprovedTransactionAddedEvent | TransactionControllerTransactionConfirmedEvent | MultichainTransactionsControllerTransactionConfirmedEvent | NetworkControllerStateChangeEvent | NetworkControllerNetworkAddedEvent | NetworkControllerNetworkDidChangeEvent | NetworkControllerNetworkRemovedEvent | NetworkEnablementControllerEvents | AccountsControllerAccountBalancesUpdatedEvent | PermissionControllerStateChange | SnapControllerSnapInstalledEvent | AccountActivityServiceBalanceUpdatedEvent | AccountActivityServiceStatusChangedEvent | RemoteFeatureFlagControllerStateChangeEvent;
|
|
78
78
|
export type AssetsControllerMessenger = Messenger<typeof CONTROLLER_NAME, AssetsControllerActions | AllowedActions, AssetsControllerEvents | AllowedEvents>;
|
|
79
79
|
export type AssetsControllerOptions = {
|
|
80
80
|
messenger: AssetsControllerMessenger;
|
|
@@ -169,6 +169,16 @@ export type AssetsControllerOptions = {
|
|
|
169
169
|
export declare class AssetsController extends BaseController<typeof CONTROLLER_NAME, AssetsControllerState, AssetsControllerMessenger> {
|
|
170
170
|
#private;
|
|
171
171
|
constructor({ messenger, state, defaultUpdateInterval, isEnabled, isBasicFunctionality, subscribeToBasicFunctionalityChange, queryApiClient, rpcDataSourceConfig, trace, captureException, accountsApiDataSourceConfig, priceDataSourceConfig, stakedBalanceDataSourceConfig, isOnboarded, tempMigrateAssetsInfoMetadataAssets3346, }: AssetsControllerOptions);
|
|
172
|
+
/**
|
|
173
|
+
* Read the current enabled chains from NetworkEnablementController, and
|
|
174
|
+
* refresh data sources that would otherwise read other controllers through
|
|
175
|
+
* the messenger.
|
|
176
|
+
*
|
|
177
|
+
* This controller does not call messenger actions in its constructor.
|
|
178
|
+
* `Wallet` constructs every controller first, then `Wallet.init()` calls
|
|
179
|
+
* `init()`. Later enablement changes arrive on `stateChange` events.
|
|
180
|
+
*/
|
|
181
|
+
init(): Promise<void>;
|
|
172
182
|
/**
|
|
173
183
|
* Returns the callback passed to data sources for reporting active chain updates.
|
|
174
184
|
* Used by tests to simulate a data source reporting chain changes.
|
|
@@ -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,
|
|
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,EACV,0CAA0C,EAC1C,4CAA4C,EAC7C,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EACV,8BAA8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AO,EAAE,aAAa,GAAG,IAAI,CActC;IAED;;;;;;;OAOG;IACG,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CA6BvD;IA0BD;;;;OAIG;IACH,mBAAmB,CAAC,gBAAgB,EAAE,iBAAiB,GAAG,IAAI,CA8B7D;IAMD;;;;;;OAMG;IACH,oBAAoB,CAAC,QAAQ,EAAE,eAAe,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI,CAkC3E;IAED;;OAEG;IACH,sBAAsB,IAAI,IAAI,CAS7B;IA04BD;;;;;;;OAOG;IACH,8BAA8B,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAGtD;IA6sBD;;;;;;;;;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,CAoDd;CACF"}
|
package/dist/AssetsController.js
CHANGED
|
@@ -426,6 +426,13 @@ let AssetsController = (() => {
|
|
|
426
426
|
* its forced `getAssets()` call) runs a second time for the same accounts.
|
|
427
427
|
*/
|
|
428
428
|
#startInFlight = false;
|
|
429
|
+
/**
|
|
430
|
+
* Whether an account switch occurred while startup was force-fetching.
|
|
431
|
+
*
|
|
432
|
+
* The startup subscription skips its initial Accounts API fetch, so a
|
|
433
|
+
* selection made in that window must be refreshed once startup completes.
|
|
434
|
+
*/
|
|
435
|
+
#pendingAccountRefresh = false;
|
|
429
436
|
/** Currently enabled chains from NetworkEnablementController */
|
|
430
437
|
#enabledChains = new Set();
|
|
431
438
|
/**
|
|
@@ -433,12 +440,22 @@ let AssetsController = (() => {
|
|
|
433
440
|
* This includes all accounts in the same group as the selected account
|
|
434
441
|
* (EVM, Bitcoin, Solana, Tron, etc. that belong to the same logical account group).
|
|
435
442
|
*
|
|
443
|
+
* When `AccountTreeController` is not registered, falls back to
|
|
444
|
+
* `AccountsController:getSelectedAccount`.
|
|
445
|
+
*
|
|
436
446
|
* @returns Array of InternalAccount objects from the selected account group.
|
|
437
447
|
*/
|
|
438
448
|
#getSelectedAccounts() {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
449
|
+
try {
|
|
450
|
+
const accounts = this.messenger.call('AccountTreeController:getAccountsFromSelectedAccountGroup');
|
|
451
|
+
if (accounts.length > 0) {
|
|
452
|
+
return accounts;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
catch (error) {
|
|
456
|
+
if (!isUnregisteredActionError(error)) {
|
|
457
|
+
throw error;
|
|
458
|
+
}
|
|
442
459
|
}
|
|
443
460
|
const selectedAccount = this.messenger.call('AccountsController:getSelectedAccount');
|
|
444
461
|
if (selectedAccount) {
|
|
@@ -449,10 +466,43 @@ let AssetsController = (() => {
|
|
|
449
466
|
/**
|
|
450
467
|
* Whether `AccountTreeController.init()` has completed and the tree is ready.
|
|
451
468
|
*
|
|
452
|
-
*
|
|
469
|
+
* When `AccountTreeController` is not registered, returns true so tracking
|
|
470
|
+
* is not blocked on a controller the host has not installed.
|
|
471
|
+
*
|
|
472
|
+
* @returns True when the account tree has been initialized, or when that controller is absent.
|
|
453
473
|
*/
|
|
454
474
|
#isAccountTreeInitialized() {
|
|
455
|
-
|
|
475
|
+
try {
|
|
476
|
+
return this.messenger.call('AccountTreeController:isInitialized');
|
|
477
|
+
}
|
|
478
|
+
catch (error) {
|
|
479
|
+
if (!isUnregisteredActionError(error)) {
|
|
480
|
+
throw error;
|
|
481
|
+
}
|
|
482
|
+
return true;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Whether `AccountTreeController` has registered its actions.
|
|
487
|
+
*
|
|
488
|
+
* Selected-account switches are published by `AccountsController` in both
|
|
489
|
+
* setups. When the tree controller is registered it turns those switches
|
|
490
|
+
* into `selectedAccountGroupChange`, so handling both events would refresh
|
|
491
|
+
* tracked assets twice.
|
|
492
|
+
*
|
|
493
|
+
* @returns True when `AccountTreeController:isInitialized` is registered.
|
|
494
|
+
*/
|
|
495
|
+
#isAccountTreeControllerRegistered() {
|
|
496
|
+
try {
|
|
497
|
+
this.messenger.call('AccountTreeController:isInitialized');
|
|
498
|
+
return true;
|
|
499
|
+
}
|
|
500
|
+
catch (error) {
|
|
501
|
+
if (!isUnregisteredActionError(error)) {
|
|
502
|
+
throw error;
|
|
503
|
+
}
|
|
504
|
+
return false;
|
|
505
|
+
}
|
|
456
506
|
}
|
|
457
507
|
/**
|
|
458
508
|
* Whether the client (UI) is open, read from ClientController state.
|
|
@@ -608,7 +658,9 @@ let AssetsController = (() => {
|
|
|
608
658
|
log('Initializing AssetsController', {
|
|
609
659
|
defaultUpdateInterval: this.#defaultUpdateInterval,
|
|
610
660
|
});
|
|
611
|
-
|
|
661
|
+
// Subscribe during construction so a stateChange published before init()
|
|
662
|
+
// is not missed. Enabled chains are read in init(), after every
|
|
663
|
+
// controller has been constructed.
|
|
612
664
|
this.#subscribeToEvents();
|
|
613
665
|
this.#registerActionHandlers();
|
|
614
666
|
// Subscriptions start only when both UI is open and keyring unlocked -> #updateActive().
|
|
@@ -644,8 +696,34 @@ let AssetsController = (() => {
|
|
|
644
696
|
const initialNativeAssetMap = buildNativeAssetsFromConstant();
|
|
645
697
|
queryApiClient.setCachedData(NATIVE_ASSETS_QUERY_KEY, initialNativeAssetMap);
|
|
646
698
|
}
|
|
699
|
+
/**
|
|
700
|
+
* Read the current enabled chains from NetworkEnablementController, and
|
|
701
|
+
* refresh data sources that would otherwise read other controllers through
|
|
702
|
+
* the messenger.
|
|
703
|
+
*
|
|
704
|
+
* This controller does not call messenger actions in its constructor.
|
|
705
|
+
* `Wallet` constructs every controller first, then `Wallet.init()` calls
|
|
706
|
+
* `init()`. Later enablement changes arrive on `stateChange` events.
|
|
707
|
+
*/
|
|
708
|
+
async init() {
|
|
709
|
+
this.#initializeState();
|
|
710
|
+
this.#rpcDataSource.refreshActiveChainsFromNetworkState();
|
|
711
|
+
this.#stakedBalanceDataSource.refreshActiveChainsFromNetworkEnablementState();
|
|
712
|
+
this.#snapDataSource.init();
|
|
713
|
+
await this.#accountsApiDataSource.init();
|
|
714
|
+
}
|
|
647
715
|
#initializeState() {
|
|
648
|
-
|
|
716
|
+
let enabledNetworkMap;
|
|
717
|
+
try {
|
|
718
|
+
({ enabledNetworkMap } = this.messenger.call('NetworkEnablementController:getState'));
|
|
719
|
+
}
|
|
720
|
+
catch (error) {
|
|
721
|
+
if (!isUnregisteredActionError(error)) {
|
|
722
|
+
throw error;
|
|
723
|
+
}
|
|
724
|
+
log('NetworkEnablementController:getState is not registered yet. Enabled chains are applied from NetworkEnablementController:stateChange.', { error });
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
649
727
|
this.#enabledChains = this.#extractEnabledChains(enabledNetworkMap);
|
|
650
728
|
log('Initialized state', {
|
|
651
729
|
enabledNetworkMap,
|
|
@@ -701,6 +779,12 @@ let AssetsController = (() => {
|
|
|
701
779
|
this.messenger.subscribe('AccountTreeController:selectedAccountGroupChange', (groupId, previousGroupId) => {
|
|
702
780
|
this.#handleAccountGroupChanged(groupId, previousGroupId).catch(console.error);
|
|
703
781
|
});
|
|
782
|
+
// Fallback for hosts that do not register AccountTreeController.
|
|
783
|
+
// Ignored while that controller is registered so a switch is not
|
|
784
|
+
// refreshed here and again on `selectedAccountGroupChange`.
|
|
785
|
+
this.messenger.subscribe('AccountsController:selectedAccountChange', () => {
|
|
786
|
+
this.#handleSelectedAccountChanged().catch(console.error);
|
|
787
|
+
});
|
|
704
788
|
this.messenger.subscribe('AccountTreeController:initialized', () => {
|
|
705
789
|
this.#updateActive();
|
|
706
790
|
});
|
|
@@ -2373,6 +2457,18 @@ let AssetsController = (() => {
|
|
|
2373
2457
|
})
|
|
2374
2458
|
.finally(() => {
|
|
2375
2459
|
this.#startInFlight = false;
|
|
2460
|
+
const shouldRefreshPendingAccount = this.#pendingAccountRefresh &&
|
|
2461
|
+
this.#isUiOpen() &&
|
|
2462
|
+
this.#isKeyringUnlocked() &&
|
|
2463
|
+
this.#isAccountTreeInitialized();
|
|
2464
|
+
this.#pendingAccountRefresh = false;
|
|
2465
|
+
if (shouldRefreshPendingAccount) {
|
|
2466
|
+
this.#refreshTrackedAccounts(this.#getSelectedAccounts()).catch((error) => {
|
|
2467
|
+
log('Failed to refresh assets after startup account switch', {
|
|
2468
|
+
error,
|
|
2469
|
+
});
|
|
2470
|
+
});
|
|
2471
|
+
}
|
|
2376
2472
|
});
|
|
2377
2473
|
}
|
|
2378
2474
|
/**
|
|
@@ -2768,6 +2864,9 @@ let AssetsController = (() => {
|
|
|
2768
2864
|
// (including when the group did not change) so late subscribers can catch
|
|
2769
2865
|
// up — ignore those until we are already tracking.
|
|
2770
2866
|
if (this.#activeSubscriptions.size === 0) {
|
|
2867
|
+
if (this.#startInFlight && groupId !== previousGroupId) {
|
|
2868
|
+
this.#pendingAccountRefresh = true;
|
|
2869
|
+
}
|
|
2771
2870
|
return;
|
|
2772
2871
|
}
|
|
2773
2872
|
if (groupId === previousGroupId) {
|
|
@@ -2780,6 +2879,41 @@ let AssetsController = (() => {
|
|
|
2780
2879
|
groupId,
|
|
2781
2880
|
previousGroupId,
|
|
2782
2881
|
});
|
|
2882
|
+
await this.#refreshTrackedAccounts(accounts);
|
|
2883
|
+
}
|
|
2884
|
+
/**
|
|
2885
|
+
* Refresh tracked assets after `AccountsController:selectedAccountChange`
|
|
2886
|
+
* when `AccountTreeController` is not registered.
|
|
2887
|
+
*
|
|
2888
|
+
* Ignored while the account tree controller is registered, because that
|
|
2889
|
+
* controller republishes the switch as `selectedAccountGroupChange`.
|
|
2890
|
+
* Also ignored until tracking has started, matching group switches, so the
|
|
2891
|
+
* first start stays owned by unlock and account-tree initialization.
|
|
2892
|
+
*/
|
|
2893
|
+
async #handleSelectedAccountChanged() {
|
|
2894
|
+
if (this.#isAccountTreeControllerRegistered()) {
|
|
2895
|
+
return;
|
|
2896
|
+
}
|
|
2897
|
+
if (this.#activeSubscriptions.size === 0) {
|
|
2898
|
+
if (this.#startInFlight) {
|
|
2899
|
+
this.#pendingAccountRefresh = true;
|
|
2900
|
+
}
|
|
2901
|
+
return;
|
|
2902
|
+
}
|
|
2903
|
+
const accounts = this.#getSelectedAccounts();
|
|
2904
|
+
log('Selected account changed', {
|
|
2905
|
+
accountCount: accounts.length,
|
|
2906
|
+
accountIds: accounts.map((account) => account.id),
|
|
2907
|
+
});
|
|
2908
|
+
await this.#refreshTrackedAccounts(accounts);
|
|
2909
|
+
}
|
|
2910
|
+
/**
|
|
2911
|
+
* Force-fetch and resubscribe for the accounts that should be tracked now.
|
|
2912
|
+
*
|
|
2913
|
+
* @param accounts - Accounts to refresh. An empty list skips the fetch and
|
|
2914
|
+
* still resubscribes, matching a switch onto an empty selection.
|
|
2915
|
+
*/
|
|
2916
|
+
async #refreshTrackedAccounts(accounts) {
|
|
2783
2917
|
const releaseLock = await this.#accountRefreshMutex.acquire();
|
|
2784
2918
|
try {
|
|
2785
2919
|
this.#ensureNativeBalancesDefaultZero();
|
|
@@ -3173,4 +3307,13 @@ let AssetsController = (() => {
|
|
|
3173
3307
|
};
|
|
3174
3308
|
})();
|
|
3175
3309
|
export { AssetsController };
|
|
3310
|
+
/**
|
|
3311
|
+
* Whether a messenger call failed because no controller has registered the action yet.
|
|
3312
|
+
*
|
|
3313
|
+
* @param error - The error thrown by `messenger.call`.
|
|
3314
|
+
* @returns True when the action handler is not registered.
|
|
3315
|
+
*/
|
|
3316
|
+
function isUnregisteredActionError(error) {
|
|
3317
|
+
return (error instanceof Error && error.message.includes('has not been registered'));
|
|
3318
|
+
}
|
|
3176
3319
|
//# sourceMappingURL=AssetsController.js.map
|