@metamask-previews/account-tree-controller 1.5.0-preview-cd26f001 → 1.5.0-preview-e9856975

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
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
11
11
 
12
12
  ### Changed
13
13
 
14
+ - **BREAKING:** Use new `Messenger` from `@metamask/messenger` ([#6380](https://github.com/MetaMask/core/pull/6380))
15
+ - Previously, `AccountTreeController` accepted a `RestrictedMessenger` instance from `@metamask/base-controller`.
14
16
  - Use non-EVM account names for group names ([#6831](https://github.com/MetaMask/core/pull/6831))
15
17
  - EVM accounts still take precedence over non-EVM accounts.
16
18
  - Before accounts get re-aligned, it is possible that a group contains only non-EVM accounts, in which case, the first non-EVM account name will be used for that account group.
@@ -14,7 +14,7 @@ var _AccountTreeController_instances, _AccountTreeController_accountIdToContext,
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");
17
- const base_controller_1 = require("@metamask/base-controller");
17
+ const next_1 = require("@metamask/base-controller/next");
18
18
  const keyring_api_1 = require("@metamask/keyring-api");
19
19
  const utils_1 = require("@metamask/utils");
20
20
  const analytics_1 = require("./backup-and-sync/analytics/index.cjs");
@@ -29,31 +29,31 @@ const accountTreeControllerMetadata = {
29
29
  accountTree: {
30
30
  includeInStateLogs: true,
31
31
  persist: false,
32
- anonymous: false,
32
+ includeInDebugSnapshot: false,
33
33
  usedInUi: true,
34
34
  },
35
35
  isAccountTreeSyncingInProgress: {
36
36
  includeInStateLogs: false,
37
37
  persist: false,
38
- anonymous: false,
38
+ includeInDebugSnapshot: false,
39
39
  usedInUi: true,
40
40
  },
41
41
  hasAccountTreeSyncingSyncedAtLeastOnce: {
42
42
  includeInStateLogs: true,
43
43
  persist: true,
44
- anonymous: false,
44
+ includeInDebugSnapshot: false,
45
45
  usedInUi: true,
46
46
  },
47
47
  accountGroupsMetadata: {
48
48
  includeInStateLogs: true,
49
49
  persist: true,
50
- anonymous: false,
50
+ includeInDebugSnapshot: false,
51
51
  usedInUi: true,
52
52
  },
53
53
  accountWalletsMetadata: {
54
54
  includeInStateLogs: true,
55
55
  persist: true,
56
- anonymous: false,
56
+ includeInDebugSnapshot: false,
57
57
  usedInUi: true,
58
58
  },
59
59
  };
@@ -75,7 +75,7 @@ function getDefaultAccountTreeControllerState() {
75
75
  };
76
76
  }
77
77
  exports.getDefaultAccountTreeControllerState = getDefaultAccountTreeControllerState;
78
- class AccountTreeController extends base_controller_1.BaseController {
78
+ class AccountTreeController extends next_1.BaseController {
79
79
  /**
80
80
  * Constructor for AccountTreeController.
81
81
  *
@@ -114,11 +114,11 @@ class AccountTreeController extends base_controller_1.BaseController {
114
114
  // Rules to apply to construct the wallets tree.
115
115
  __classPrivateFieldSet(this, _AccountTreeController_rules, [
116
116
  // 1. We group by entropy-source
117
- new entropy_1.EntropyRule(this.messagingSystem),
117
+ new entropy_1.EntropyRule(this.messenger),
118
118
  // 2. We group by Snap ID
119
- new snap_1.SnapRule(this.messagingSystem),
119
+ new snap_1.SnapRule(this.messenger),
120
120
  // 3. We group by wallet type (this rule cannot fail and will group all non-matching accounts)
121
- new keyring_1.KeyringRule(this.messagingSystem),
121
+ new keyring_1.KeyringRule(this.messenger),
122
122
  ], "f");
123
123
  // Initialize trace function
124
124
  __classPrivateFieldSet(this, _AccountTreeController_trace, config?.trace ?? analytics_1.traceFallback, "f");
@@ -131,19 +131,19 @@ class AccountTreeController extends base_controller_1.BaseController {
131
131
  }, "f");
132
132
  // Initialize the backup and sync service
133
133
  __classPrivateFieldSet(this, _AccountTreeController_backupAndSyncService, new service_1.BackupAndSyncService(__classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_createBackupAndSyncContext).call(this)), "f");
134
- this.messagingSystem.subscribe('AccountsController:accountAdded', (account) => {
134
+ this.messenger.subscribe('AccountsController:accountAdded', (account) => {
135
135
  __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_handleAccountAdded).call(this, account);
136
136
  });
137
- this.messagingSystem.subscribe('AccountsController:accountRemoved', (accountId) => {
137
+ this.messenger.subscribe('AccountsController:accountRemoved', (accountId) => {
138
138
  __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_handleAccountRemoved).call(this, accountId);
139
139
  });
140
- this.messagingSystem.subscribe('AccountsController:selectedAccountChange', (account) => {
140
+ this.messenger.subscribe('AccountsController:selectedAccountChange', (account) => {
141
141
  __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_handleSelectedAccountChange).call(this, account);
142
142
  });
143
- this.messagingSystem.subscribe('UserStorageController:stateChange', (userStorageControllerState) => {
143
+ this.messenger.subscribe('UserStorageController:stateChange', (userStorageControllerState) => {
144
144
  __classPrivateFieldGet(this, _AccountTreeController_backupAndSyncService, "f").handleUserStorageStateChange(userStorageControllerState);
145
145
  });
146
- this.messagingSystem.subscribe('MultichainAccountService:walletStatusChange', (walletId, status) => {
146
+ this.messenger.subscribe('MultichainAccountService:walletStatusChange', (walletId, status) => {
147
147
  __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_handleMultichainAccountWalletStatusChange).call(this, walletId, status);
148
148
  });
149
149
  __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_registerMessageHandlers).call(this);
@@ -232,7 +232,7 @@ class AccountTreeController extends base_controller_1.BaseController {
232
232
  if (previousSelectedAccountGroup !==
233
233
  this.state.accountTree.selectedAccountGroup) {
234
234
  (0, logger_1.projectLogger)(`Selected (initial) group is: [${this.state.accountTree.selectedAccountGroup}]`);
235
- this.messagingSystem.publish(`${exports.controllerName}:selectedAccountGroupChange`, this.state.accountTree.selectedAccountGroup, previousSelectedAccountGroup);
235
+ this.messenger.publish(`${exports.controllerName}:selectedAccountGroupChange`, this.state.accountTree.selectedAccountGroup, previousSelectedAccountGroup);
236
236
  }
237
237
  (0, logger_1.projectLogger)('Initialized!');
238
238
  __classPrivateFieldSet(this, _AccountTreeController_initialized, true, "f");
@@ -293,7 +293,7 @@ class AccountTreeController extends base_controller_1.BaseController {
293
293
  }
294
294
  const accounts = [];
295
295
  for (const id of group.accounts) {
296
- const account = this.messagingSystem.call('AccountsController:getAccount', id);
296
+ const account = this.messenger.call('AccountsController:getAccount', id);
297
297
  // For now, we're filtering undefined account, but I believe
298
298
  // throwing would be more appropriate here.
299
299
  if (account) {
@@ -345,10 +345,10 @@ class AccountTreeController extends base_controller_1.BaseController {
345
345
  state.accountTree.selectedAccountGroup = groupId;
346
346
  });
347
347
  (0, logger_1.projectLogger)(`Selected group is now: [${this.state.accountTree.selectedAccountGroup}]`);
348
- this.messagingSystem.publish(`${exports.controllerName}:selectedAccountGroupChange`, groupId, previousSelectedAccountGroup);
348
+ this.messenger.publish(`${exports.controllerName}:selectedAccountGroupChange`, groupId, previousSelectedAccountGroup);
349
349
  // Update AccountsController - this will trigger selectedAccountChange event,
350
350
  // but our handler is idempotent so it won't cause infinite loop
351
- this.messagingSystem.call('AccountsController:setSelectedAccount', accountToSelect);
351
+ this.messenger.call('AccountsController:setSelectedAccount', accountToSelect);
352
352
  }
353
353
  /**
354
354
  * Resolves name conflicts by adding a suffix to make the name unique.
@@ -596,7 +596,7 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
596
596
  }, _AccountTreeController_getComputedAccountGroupName = function _AccountTreeController_getComputedAccountGroupName(wallet, group) {
597
597
  let proposedName = ''; // Empty means there's no computed name for this group.
598
598
  for (const id of group.accounts) {
599
- const account = this.messagingSystem.call('AccountsController:getAccount', id);
599
+ const account = this.messenger.call('AccountsController:getAccount', id);
600
600
  if (!account || !account.metadata.name.length) {
601
601
  continue;
602
602
  }
@@ -735,7 +735,7 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
735
735
  }
736
736
  }
737
737
  });
738
- this.messagingSystem.publish(`${exports.controllerName}:accountTreeChange`, this.state.accountTree);
738
+ this.messenger.publish(`${exports.controllerName}:accountTreeChange`, this.state.accountTree);
739
739
  }
740
740
  }, _AccountTreeController_handleAccountRemoved = function _AccountTreeController_handleAccountRemoved(accountId) {
741
741
  // We wait for the first `init` to be called to actually build up the tree and
@@ -770,10 +770,10 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
770
770
  }
771
771
  }
772
772
  });
773
- this.messagingSystem.publish(`${exports.controllerName}:accountTreeChange`, this.state.accountTree);
773
+ this.messenger.publish(`${exports.controllerName}:accountTreeChange`, this.state.accountTree);
774
774
  // Emit selectedAccountGroupChange event if the selected group changed
775
775
  if (selectedAccountGroupChanged) {
776
- this.messagingSystem.publish(`${exports.controllerName}:selectedAccountGroupChange`, this.state.accountTree.selectedAccountGroup, previousSelectedAccountGroup);
776
+ this.messenger.publish(`${exports.controllerName}:selectedAccountGroupChange`, this.state.accountTree.selectedAccountGroup, previousSelectedAccountGroup);
777
777
  }
778
778
  // Clear reverse-mapping for that account.
779
779
  __classPrivateFieldGet(this, _AccountTreeController_accountIdToContext, "f").delete(accountId);
@@ -868,7 +868,7 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
868
868
  sortOrder,
869
869
  });
870
870
  }, _AccountTreeController_listAccounts = function _AccountTreeController_listAccounts() {
871
- return this.messagingSystem.call('AccountsController:listMultichainAccounts');
871
+ return this.messenger.call('AccountsController:listMultichainAccounts');
872
872
  }, _AccountTreeController_assertAccountGroupExists = function _AccountTreeController_assertAccountGroupExists(groupId) {
873
873
  const exists = __classPrivateFieldGet(this, _AccountTreeController_groupIdToWalletId, "f").has(groupId);
874
874
  if (!exists) {
@@ -884,7 +884,7 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
884
884
  throw new Error('Account group name already exists');
885
885
  }
886
886
  }, _AccountTreeController_getDefaultSelectedAccountGroup = function _AccountTreeController_getDefaultSelectedAccountGroup(wallets) {
887
- const selectedAccount = this.messagingSystem.call('AccountsController:getSelectedMultichainAccount');
887
+ const selectedAccount = this.messenger.call('AccountsController:getSelectedMultichainAccount');
888
888
  if (selectedAccount && selectedAccount.id) {
889
889
  const accountMapping = __classPrivateFieldGet(this, _AccountTreeController_accountIdToContext, "f").get(selectedAccount.id);
890
890
  if (accountMapping) {
@@ -910,7 +910,7 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
910
910
  this.update((state) => {
911
911
  state.accountTree.selectedAccountGroup = groupId;
912
912
  });
913
- this.messagingSystem.publish(`${exports.controllerName}:selectedAccountGroupChange`, groupId, previousSelectedAccountGroup);
913
+ this.messenger.publish(`${exports.controllerName}:selectedAccountGroupChange`, groupId, previousSelectedAccountGroup);
914
914
  }, _AccountTreeController_handleMultichainAccountWalletStatusChange = function _AccountTreeController_handleMultichainAccountWalletStatusChange(walletId, walletStatus) {
915
915
  this.update((state) => {
916
916
  const wallet = state.accountTree.wallets[walletId];
@@ -926,7 +926,7 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
926
926
  if (group) {
927
927
  let candidate;
928
928
  for (const id of group.accounts) {
929
- const account = this.messagingSystem.call('AccountsController:getAccount', id);
929
+ const account = this.messenger.call('AccountsController:getAccount', id);
930
930
  if (!candidate) {
931
931
  candidate = id;
932
932
  }
@@ -950,7 +950,7 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
950
950
  candidate = group.id;
951
951
  }
952
952
  for (const id of group.accounts) {
953
- const account = this.messagingSystem.call('AccountsController:getAccount', id);
953
+ const account = this.messenger.call('AccountsController:getAccount', id);
954
954
  if (account && (0, keyring_api_1.isEvmAccountType)(account.type)) {
955
955
  // EVM accounts have a higher priority, so if we find any, we just
956
956
  // use that group!
@@ -961,18 +961,18 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
961
961
  }
962
962
  return candidate;
963
963
  }, _AccountTreeController_registerMessageHandlers = function _AccountTreeController_registerMessageHandlers() {
964
- this.messagingSystem.registerActionHandler(`${exports.controllerName}:getSelectedAccountGroup`, this.getSelectedAccountGroup.bind(this));
965
- this.messagingSystem.registerActionHandler(`${exports.controllerName}:setSelectedAccountGroup`, this.setSelectedAccountGroup.bind(this));
966
- this.messagingSystem.registerActionHandler(`${exports.controllerName}:getAccountsFromSelectedAccountGroup`, this.getAccountsFromSelectedAccountGroup.bind(this));
967
- this.messagingSystem.registerActionHandler(`${exports.controllerName}:setAccountWalletName`, this.setAccountWalletName.bind(this));
968
- this.messagingSystem.registerActionHandler(`${exports.controllerName}:setAccountGroupName`, this.setAccountGroupName.bind(this));
969
- this.messagingSystem.registerActionHandler(`${exports.controllerName}:setAccountGroupPinned`, this.setAccountGroupPinned.bind(this));
970
- this.messagingSystem.registerActionHandler(`${exports.controllerName}:setAccountGroupHidden`, this.setAccountGroupHidden.bind(this));
964
+ this.messenger.registerActionHandler(`${exports.controllerName}:getSelectedAccountGroup`, this.getSelectedAccountGroup.bind(this));
965
+ this.messenger.registerActionHandler(`${exports.controllerName}:setSelectedAccountGroup`, this.setSelectedAccountGroup.bind(this));
966
+ this.messenger.registerActionHandler(`${exports.controllerName}:getAccountsFromSelectedAccountGroup`, this.getAccountsFromSelectedAccountGroup.bind(this));
967
+ this.messenger.registerActionHandler(`${exports.controllerName}:setAccountWalletName`, this.setAccountWalletName.bind(this));
968
+ this.messenger.registerActionHandler(`${exports.controllerName}:setAccountGroupName`, this.setAccountGroupName.bind(this));
969
+ this.messenger.registerActionHandler(`${exports.controllerName}:setAccountGroupPinned`, this.setAccountGroupPinned.bind(this));
970
+ this.messenger.registerActionHandler(`${exports.controllerName}:setAccountGroupHidden`, this.setAccountGroupHidden.bind(this));
971
971
  }, _AccountTreeController_createBackupAndSyncContext = function _AccountTreeController_createBackupAndSyncContext() {
972
972
  return {
973
973
  ...__classPrivateFieldGet(this, _AccountTreeController_backupAndSyncConfig, "f"),
974
974
  controller: this,
975
- messenger: this.messagingSystem,
975
+ messenger: this.messenger,
976
976
  controllerStateUpdateFn: this.update.bind(this),
977
977
  traceFn: __classPrivateFieldGet(this, _AccountTreeController_trace, "f").bind(this),
978
978
  groupIdToWalletId: __classPrivateFieldGet(this, _AccountTreeController_groupIdToWalletId, "f"),