@metamask-previews/account-tree-controller 7.5.3-preview-d52465c2b → 7.5.3-preview-34f2bcbf7

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 CHANGED
@@ -7,10 +7,16 @@ 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
+ - **BREAKING:** Expose `status` on `AccountGroupMultichainAccountObject` ([#9104](https://github.com/MetaMask/core/pull/9104))
13
+ - The controller now requires the new event `MultichainAccountService:groupStatusChange`.
14
+ - The field reflects `MultichainAccountGroupStatus` and is kept in sync via the new `MultichainAccountService:groupStatusChange` event subscription.
15
+
10
16
  ### Changed
11
17
 
12
18
  - The `Multichain Account Syncing - Full` trace is now only emitted when a backup-and-sync run actually mutates local or remote state (rolled-back local changes do not count) ([#9343](https://github.com/MetaMask/core/pull/9343))
13
- - Bump `@metamask/keyring-api` from `^23.1.0` to `^23.3.0` ([#9249](https://github.com/MetaMask/core/pull/9249))
19
+ - Bump `@metamask/keyring-api` from `^23.1.0` to `^23.5.0` ([#9249](https://github.com/MetaMask/core/pull/9249), [#9390](https://github.com/MetaMask/core/pull/9390))
14
20
  - Bump `@metamask/multichain-account-service` from `^11.0.0` to `^11.1.0` ([#9264](https://github.com/MetaMask/core/pull/9264))
15
21
  - Bump `@metamask/accounts-controller` from `^39.0.3` to `^39.0.4` ([#9349](https://github.com/MetaMask/core/pull/9349))
16
22
  - Bump `@metamask/messenger` from `^1.2.0` to `^2.0.0` ([#9392](https://github.com/MetaMask/core/pull/9392))
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _AccountTreeController_instances, _AccountTreeController_accountIdToContext, _AccountTreeController_groupIdToWalletId, _AccountTreeController_backupAndSyncService, _AccountTreeController_rules, _AccountTreeController_trace, _AccountTreeController_backupAndSyncConfig, _AccountTreeController_accountOrderCallbacks, _AccountTreeController_initialized, _AccountTreeController_initTreeContext, _AccountTreeController_getEntropyRule, _AccountTreeController_getSnapRule, _AccountTreeController_getKeyringRule, _AccountTreeController_applyAccountWalletMetadata, _AccountTreeController_getRuleForWallet, _AccountTreeController_getComputedAccountGroupName, _AccountTreeController_getDefaultAccountGroupName, _AccountTreeController_applyAccountGroupMetadata, _AccountTreeController_handleAccountsAdded, _AccountTreeController_handleAccountsRemoved, _AccountTreeController_pruneEmptyGroupAndWallet, _AccountTreeController_publishAccountGroupCreated, _AccountTreeController_publishAccountGroupUpdated, _AccountTreeController_publishAccountGroupRemoved, _AccountTreeController_insert, _AccountTreeController_listAccounts, _AccountTreeController_assertAccountGroupExists, _AccountTreeController_assertAccountWalletExists, _AccountTreeController_assertAccountGroupNameIsUnique, _AccountTreeController_setSelectedAccountGroup, _AccountTreeController_getDefaultSelectedAccountGroup, _AccountTreeController_handleSelectedAccountChange, _AccountTreeController_handleMultichainAccountWalletStatusChange, _AccountTreeController_getAccountGroup, _AccountTreeController_getDefaultAccountFromAccountGroupId, _AccountTreeController_getDefaultAccountGroupId, _AccountTreeController_hasEvmAccount, _AccountTreeController_resolveNameConflict, _AccountTreeController_createBackupAndSyncContext;
13
+ var _AccountTreeController_instances, _AccountTreeController_accountIdToContext, _AccountTreeController_groupIdToWalletId, _AccountTreeController_backupAndSyncService, _AccountTreeController_rules, _AccountTreeController_trace, _AccountTreeController_backupAndSyncConfig, _AccountTreeController_accountOrderCallbacks, _AccountTreeController_initialized, _AccountTreeController_initTreeContext, _AccountTreeController_getEntropyRule, _AccountTreeController_getSnapRule, _AccountTreeController_getKeyringRule, _AccountTreeController_applyAccountWalletMetadata, _AccountTreeController_getRuleForWallet, _AccountTreeController_getComputedAccountGroupName, _AccountTreeController_getDefaultAccountGroupName, _AccountTreeController_applyAccountGroupMetadata, _AccountTreeController_handleAccountsAdded, _AccountTreeController_handleAccountsRemoved, _AccountTreeController_pruneEmptyGroupAndWallet, _AccountTreeController_publishAccountGroupCreated, _AccountTreeController_publishAccountGroupUpdated, _AccountTreeController_publishAccountGroupRemoved, _AccountTreeController_insert, _AccountTreeController_listAccounts, _AccountTreeController_assertAccountGroupExists, _AccountTreeController_assertAccountWalletExists, _AccountTreeController_assertAccountGroupNameIsUnique, _AccountTreeController_setSelectedAccountGroup, _AccountTreeController_getDefaultSelectedAccountGroup, _AccountTreeController_handleSelectedAccountChange, _AccountTreeController_handleMultichainAccountWalletStatusChange, _AccountTreeController_handleMultichainAccountGroupStatusChange, _AccountTreeController_getMultichainAccountWalletStatus, _AccountTreeController_getMultichainAccountGroupStatus, _AccountTreeController_getAccountGroup, _AccountTreeController_getDefaultAccountFromAccountGroupId, _AccountTreeController_getDefaultAccountGroupId, _AccountTreeController_hasEvmAccount, _AccountTreeController_resolveNameConflict, _AccountTreeController_createBackupAndSyncContext;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.AccountTreeController = exports.getDefaultAccountTreeControllerState = exports.controllerName = void 0;
16
16
  const account_api_1 = require("@metamask/account-api");
@@ -25,6 +25,7 @@ const logger_1 = require("./logger.cjs");
25
25
  const entropy_1 = require("./rules/entropy.cjs");
26
26
  const keyring_1 = require("./rules/keyring.cjs");
27
27
  const snap_1 = require("./rules/snap.cjs");
28
+ const wallet_1 = require("./wallet.cjs");
28
29
  exports.controllerName = 'AccountTreeController';
29
30
  const MESSENGER_EXPOSED_METHODS = [
30
31
  'getSelectedAccountGroup',
@@ -181,6 +182,9 @@ class AccountTreeController extends base_controller_1.BaseController {
181
182
  this.messenger.subscribe('MultichainAccountService:walletStatusChange', (walletId, status) => {
182
183
  __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_handleMultichainAccountWalletStatusChange).call(this, walletId, status);
183
184
  });
185
+ this.messenger.subscribe('MultichainAccountService:groupStatusChange', (groupId, status) => {
186
+ __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_handleMultichainAccountGroupStatusChange).call(this, groupId, status);
187
+ });
184
188
  this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
185
189
  }
186
190
  /**
@@ -920,7 +924,9 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
920
924
  (0, logger_1.projectLogger)(`[${walletId}] Added as new wallet`);
921
925
  wallets[walletId] = {
922
926
  ...result.wallet,
923
- status: 'ready',
927
+ status: (0, wallet_1.isMultichainAccountWallet)(result.wallet)
928
+ ? __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_getMultichainAccountWalletStatus).call(this, result.wallet.metadata.entropy.id)
929
+ : 'ready',
924
930
  groups: {},
925
931
  metadata: {
926
932
  name: '', // Will get updated later.
@@ -931,7 +937,7 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
931
937
  };
932
938
  wallet = wallets[walletId];
933
939
  // Trigger atomic sync for new wallet (only for entropy wallets)
934
- if (wallet.type === account_api_1.AccountWalletType.Entropy) {
940
+ if ((0, wallet_1.isMultichainAccountWallet)(wallet)) {
935
941
  __classPrivateFieldGet(this, _AccountTreeController_backupAndSyncService, "f").enqueueSingleWalletSync(walletId);
936
942
  }
937
943
  }
@@ -946,6 +952,10 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
946
952
  ...result.group,
947
953
  // Type-wise, we are guaranteed to always have at least 1 account.
948
954
  accounts: [id],
955
+ ...((0, group_1.isMultichainAccountGroup)(result.group) &&
956
+ (0, wallet_1.isMultichainAccountWallet)(result.wallet) && {
957
+ status: __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_getMultichainAccountGroupStatus).call(this, result.wallet.metadata.entropy.id, result.group.metadata.entropy.groupIndex),
958
+ }),
949
959
  metadata: {
950
960
  name: '',
951
961
  ...{ pinned: false, hidden: false, lastSelected: 0 }, // Default UI states
@@ -958,7 +968,7 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
958
968
  // Map group ID to its containing wallet ID for efficient direct access
959
969
  __classPrivateFieldGet(this, _AccountTreeController_groupIdToWalletId, "f").set(groupId, walletId);
960
970
  // Trigger atomic sync for new group (only for entropy wallets)
961
- if (wallet.type === account_api_1.AccountWalletType.Entropy) {
971
+ if ((0, wallet_1.isMultichainAccountWallet)(wallet)) {
962
972
  __classPrivateFieldGet(this, _AccountTreeController_backupAndSyncService, "f").enqueueSingleGroupSync(groupId);
963
973
  }
964
974
  }
@@ -1015,9 +1025,6 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
1015
1025
  if (!accountToSelect) {
1016
1026
  throw new Error('No accounts found in group');
1017
1027
  }
1018
- const gutoSetGroupStart = Date.now();
1019
- console.log('[GUTO PERFORMANCE LOG] AccountTreeController.#setSelectedAccountGroup START');
1020
- const gutoUpdateStart = Date.now();
1021
1028
  this.update((state) => {
1022
1029
  // Update our selected account group first.
1023
1030
  state.selectedAccountGroup = groupId;
@@ -1034,20 +1041,14 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
1034
1041
  state.accountTree.wallets[walletId].groups[groupId].metadata.lastSelected = now;
1035
1042
  }
1036
1043
  });
1037
- console.log(`[GUTO PERFORMANCE LOG] AccountTreeController state.update (sync) took ${Date.now() - gutoUpdateStart}ms`);
1038
1044
  (0, logger_1.projectLogger)(`Selected group is now: [${this.state.selectedAccountGroup}]`);
1039
- const gutoPublishStart = Date.now();
1040
1045
  this.messenger.publish(`${exports.controllerName}:selectedAccountGroupChange`, groupId, previousSelectedAccountGroup);
1041
- console.log(`[GUTO PERFORMANCE LOG] AccountTreeController publish selectedAccountGroupChange (sync subscriber fan-out) took ${Date.now() - gutoPublishStart}ms`);
1042
1046
  if (forwardSelectedAccount) {
1043
1047
  // Update AccountsController - this will trigger selectedAccountChange event,
1044
1048
  // but our handler is idempotent so it won't cause infinite loop
1045
- const gutoSetAccountStart = Date.now();
1046
1049
  this.messenger.call('AccountsController:setSelectedAccount', accountToSelect);
1047
- console.log(`[GUTO PERFORMANCE LOG] AccountTreeController AccountsController:setSelectedAccount (sync selectedAccountChange fan-out) took ${Date.now() - gutoSetAccountStart}ms`);
1048
1050
  (0, logger_1.projectLogger)(`Selected account is now: ${accountToSelect}`);
1049
1051
  }
1050
- console.log(`[GUTO PERFORMANCE LOG] AccountTreeController.#setSelectedAccountGroup END (total, sync) took ${Date.now() - gutoSetGroupStart}ms`);
1051
1052
  }, _AccountTreeController_getDefaultSelectedAccountGroup = function _AccountTreeController_getDefaultSelectedAccountGroup(wallets) {
1052
1053
  const selectedAccount = this.messenger.call('AccountsController:getSelectedMultichainAccount');
1053
1054
  if (selectedAccount?.id) {
@@ -1076,6 +1077,30 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
1076
1077
  wallet.status = walletStatus;
1077
1078
  }
1078
1079
  });
1080
+ }, _AccountTreeController_handleMultichainAccountGroupStatusChange = function _AccountTreeController_handleMultichainAccountGroupStatusChange(groupId, groupStatus) {
1081
+ this.update((state) => {
1082
+ const walletId = __classPrivateFieldGet(this, _AccountTreeController_groupIdToWalletId, "f").get(groupId);
1083
+ if (walletId) {
1084
+ const group = state.accountTree.wallets[walletId]?.groups[groupId];
1085
+ if (group && (0, group_1.isMultichainAccountGroup)(group)) {
1086
+ group.status = groupStatus;
1087
+ }
1088
+ }
1089
+ });
1090
+ }, _AccountTreeController_getMultichainAccountWalletStatus = function _AccountTreeController_getMultichainAccountWalletStatus(entropySource) {
1091
+ try {
1092
+ return this.messenger.call('MultichainAccountService:getMultichainAccountWallet', { entropySource }).status;
1093
+ }
1094
+ catch {
1095
+ return 'uninitialized';
1096
+ }
1097
+ }, _AccountTreeController_getMultichainAccountGroupStatus = function _AccountTreeController_getMultichainAccountGroupStatus(entropySource, groupIndex) {
1098
+ try {
1099
+ return this.messenger.call('MultichainAccountService:getMultichainAccountGroup', { entropySource, groupIndex }).status;
1100
+ }
1101
+ catch {
1102
+ return 'uninitialized';
1103
+ }
1079
1104
  }, _AccountTreeController_getAccountGroup = function _AccountTreeController_getAccountGroup(groupId) {
1080
1105
  const found = Object.values(this.state.accountTree.wallets).find((wallet) => wallet.groups[groupId] !== undefined);
1081
1106
  return found?.groups[groupId];