@metamask-previews/account-tree-controller 1.6.0-preview-0458fe94 → 1.6.0-preview-ebf01f52

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,11 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
- ### Changed
11
-
12
- - **BREAKING:** Use new `Messenger` from `@metamask/messenger` ([#6380](https://github.com/MetaMask/core/pull/6380))
13
- - Previously, `AccountTreeController` accepted a `RestrictedMessenger` instance from `@metamask/base-controller`.
14
-
15
10
  ## [1.6.0]
16
11
 
17
12
  ### Changed
@@ -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 next_1 = require("@metamask/base-controller/next");
17
+ const base_controller_1 = require("@metamask/base-controller");
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
- includeInDebugSnapshot: false,
32
+ anonymous: false,
33
33
  usedInUi: true,
34
34
  },
35
35
  isAccountTreeSyncingInProgress: {
36
36
  includeInStateLogs: false,
37
37
  persist: false,
38
- includeInDebugSnapshot: false,
38
+ anonymous: false,
39
39
  usedInUi: true,
40
40
  },
41
41
  hasAccountTreeSyncingSyncedAtLeastOnce: {
42
42
  includeInStateLogs: true,
43
43
  persist: true,
44
- includeInDebugSnapshot: false,
44
+ anonymous: false,
45
45
  usedInUi: true,
46
46
  },
47
47
  accountGroupsMetadata: {
48
48
  includeInStateLogs: true,
49
49
  persist: true,
50
- includeInDebugSnapshot: false,
50
+ anonymous: false,
51
51
  usedInUi: true,
52
52
  },
53
53
  accountWalletsMetadata: {
54
54
  includeInStateLogs: true,
55
55
  persist: true,
56
- includeInDebugSnapshot: false,
56
+ anonymous: 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 next_1.BaseController {
78
+ class AccountTreeController extends base_controller_1.BaseController {
79
79
  /**
80
80
  * Constructor for AccountTreeController.
81
81
  *
@@ -118,11 +118,11 @@ class AccountTreeController extends next_1.BaseController {
118
118
  // Rules to apply to construct the wallets tree.
119
119
  __classPrivateFieldSet(this, _AccountTreeController_rules, [
120
120
  // 1. We group by entropy-source
121
- new entropy_1.EntropyRule(this.messenger),
121
+ new entropy_1.EntropyRule(this.messagingSystem),
122
122
  // 2. We group by Snap ID
123
- new snap_1.SnapRule(this.messenger),
123
+ new snap_1.SnapRule(this.messagingSystem),
124
124
  // 3. We group by wallet type (this rule cannot fail and will group all non-matching accounts)
125
- new keyring_1.KeyringRule(this.messenger),
125
+ new keyring_1.KeyringRule(this.messagingSystem),
126
126
  ], "f");
127
127
  // Initialize trace function
128
128
  __classPrivateFieldSet(this, _AccountTreeController_trace, config?.trace ?? analytics_1.traceFallback, "f");
@@ -137,19 +137,19 @@ class AccountTreeController extends next_1.BaseController {
137
137
  __classPrivateFieldSet(this, _AccountTreeController_accountOrderCallbacks, config?.accountOrderCallbacks, "f");
138
138
  // Initialize the backup and sync service
139
139
  __classPrivateFieldSet(this, _AccountTreeController_backupAndSyncService, new service_1.BackupAndSyncService(__classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_createBackupAndSyncContext).call(this)), "f");
140
- this.messenger.subscribe('AccountsController:accountAdded', (account) => {
140
+ this.messagingSystem.subscribe('AccountsController:accountAdded', (account) => {
141
141
  __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_handleAccountAdded).call(this, account);
142
142
  });
143
- this.messenger.subscribe('AccountsController:accountRemoved', (accountId) => {
143
+ this.messagingSystem.subscribe('AccountsController:accountRemoved', (accountId) => {
144
144
  __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_handleAccountRemoved).call(this, accountId);
145
145
  });
146
- this.messenger.subscribe('AccountsController:selectedAccountChange', (account) => {
146
+ this.messagingSystem.subscribe('AccountsController:selectedAccountChange', (account) => {
147
147
  __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_handleSelectedAccountChange).call(this, account);
148
148
  });
149
- this.messenger.subscribe('UserStorageController:stateChange', (userStorageControllerState) => {
149
+ this.messagingSystem.subscribe('UserStorageController:stateChange', (userStorageControllerState) => {
150
150
  __classPrivateFieldGet(this, _AccountTreeController_backupAndSyncService, "f").handleUserStorageStateChange(userStorageControllerState);
151
151
  });
152
- this.messenger.subscribe('MultichainAccountService:walletStatusChange', (walletId, status) => {
152
+ this.messagingSystem.subscribe('MultichainAccountService:walletStatusChange', (walletId, status) => {
153
153
  __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_handleMultichainAccountWalletStatusChange).call(this, walletId, status);
154
154
  });
155
155
  __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_registerMessageHandlers).call(this);
@@ -238,7 +238,7 @@ class AccountTreeController extends next_1.BaseController {
238
238
  if (previousSelectedAccountGroup !==
239
239
  this.state.accountTree.selectedAccountGroup) {
240
240
  (0, logger_1.projectLogger)(`Selected (initial) group is: [${this.state.accountTree.selectedAccountGroup}]`);
241
- this.messenger.publish(`${exports.controllerName}:selectedAccountGroupChange`, this.state.accountTree.selectedAccountGroup, previousSelectedAccountGroup);
241
+ this.messagingSystem.publish(`${exports.controllerName}:selectedAccountGroupChange`, this.state.accountTree.selectedAccountGroup, previousSelectedAccountGroup);
242
242
  }
243
243
  (0, logger_1.projectLogger)('Initialized!');
244
244
  __classPrivateFieldSet(this, _AccountTreeController_initialized, true, "f");
@@ -299,7 +299,7 @@ class AccountTreeController extends next_1.BaseController {
299
299
  }
300
300
  const accounts = [];
301
301
  for (const id of group.accounts) {
302
- const account = this.messenger.call('AccountsController:getAccount', id);
302
+ const account = this.messagingSystem.call('AccountsController:getAccount', id);
303
303
  // For now, we're filtering undefined account, but I believe
304
304
  // throwing would be more appropriate here.
305
305
  if (account) {
@@ -351,10 +351,10 @@ class AccountTreeController extends next_1.BaseController {
351
351
  state.accountTree.selectedAccountGroup = groupId;
352
352
  });
353
353
  (0, logger_1.projectLogger)(`Selected group is now: [${this.state.accountTree.selectedAccountGroup}]`);
354
- this.messenger.publish(`${exports.controllerName}:selectedAccountGroupChange`, groupId, previousSelectedAccountGroup);
354
+ this.messagingSystem.publish(`${exports.controllerName}:selectedAccountGroupChange`, groupId, previousSelectedAccountGroup);
355
355
  // Update AccountsController - this will trigger selectedAccountChange event,
356
356
  // but our handler is idempotent so it won't cause infinite loop
357
- this.messenger.call('AccountsController:setSelectedAccount', accountToSelect);
357
+ this.messagingSystem.call('AccountsController:setSelectedAccount', accountToSelect);
358
358
  }
359
359
  /**
360
360
  * Resolves name conflicts by adding a suffix to make the name unique.
@@ -602,7 +602,7 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
602
602
  }, _AccountTreeController_getComputedAccountGroupName = function _AccountTreeController_getComputedAccountGroupName(wallet, group) {
603
603
  let proposedName = ''; // Empty means there's no computed name for this group.
604
604
  for (const id of group.accounts) {
605
- const account = this.messenger.call('AccountsController:getAccount', id);
605
+ const account = this.messagingSystem.call('AccountsController:getAccount', id);
606
606
  if (!account || !account.metadata.name.length) {
607
607
  continue;
608
608
  }
@@ -767,7 +767,7 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
767
767
  }
768
768
  }
769
769
  });
770
- this.messenger.publish(`${exports.controllerName}:accountTreeChange`, this.state.accountTree);
770
+ this.messagingSystem.publish(`${exports.controllerName}:accountTreeChange`, this.state.accountTree);
771
771
  }
772
772
  }, _AccountTreeController_handleAccountRemoved = function _AccountTreeController_handleAccountRemoved(accountId) {
773
773
  // We wait for the first `init` to be called to actually build up the tree and
@@ -802,10 +802,10 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
802
802
  }
803
803
  }
804
804
  });
805
- this.messenger.publish(`${exports.controllerName}:accountTreeChange`, this.state.accountTree);
805
+ this.messagingSystem.publish(`${exports.controllerName}:accountTreeChange`, this.state.accountTree);
806
806
  // Emit selectedAccountGroupChange event if the selected group changed
807
807
  if (selectedAccountGroupChanged) {
808
- this.messenger.publish(`${exports.controllerName}:selectedAccountGroupChange`, this.state.accountTree.selectedAccountGroup, previousSelectedAccountGroup);
808
+ this.messagingSystem.publish(`${exports.controllerName}:selectedAccountGroupChange`, this.state.accountTree.selectedAccountGroup, previousSelectedAccountGroup);
809
809
  }
810
810
  // Clear reverse-mapping for that account.
811
811
  __classPrivateFieldGet(this, _AccountTreeController_accountIdToContext, "f").delete(accountId);
@@ -900,7 +900,7 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
900
900
  sortOrder,
901
901
  });
902
902
  }, _AccountTreeController_listAccounts = function _AccountTreeController_listAccounts() {
903
- return this.messenger.call('AccountsController:listMultichainAccounts');
903
+ return this.messagingSystem.call('AccountsController:listMultichainAccounts');
904
904
  }, _AccountTreeController_assertAccountGroupExists = function _AccountTreeController_assertAccountGroupExists(groupId) {
905
905
  const exists = __classPrivateFieldGet(this, _AccountTreeController_groupIdToWalletId, "f").has(groupId);
906
906
  if (!exists) {
@@ -916,7 +916,7 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
916
916
  throw new Error('Account group name already exists');
917
917
  }
918
918
  }, _AccountTreeController_getDefaultSelectedAccountGroup = function _AccountTreeController_getDefaultSelectedAccountGroup(wallets) {
919
- const selectedAccount = this.messenger.call('AccountsController:getSelectedMultichainAccount');
919
+ const selectedAccount = this.messagingSystem.call('AccountsController:getSelectedMultichainAccount');
920
920
  if (selectedAccount && selectedAccount.id) {
921
921
  const accountMapping = __classPrivateFieldGet(this, _AccountTreeController_accountIdToContext, "f").get(selectedAccount.id);
922
922
  if (accountMapping) {
@@ -942,7 +942,7 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
942
942
  this.update((state) => {
943
943
  state.accountTree.selectedAccountGroup = groupId;
944
944
  });
945
- this.messenger.publish(`${exports.controllerName}:selectedAccountGroupChange`, groupId, previousSelectedAccountGroup);
945
+ this.messagingSystem.publish(`${exports.controllerName}:selectedAccountGroupChange`, groupId, previousSelectedAccountGroup);
946
946
  }, _AccountTreeController_handleMultichainAccountWalletStatusChange = function _AccountTreeController_handleMultichainAccountWalletStatusChange(walletId, walletStatus) {
947
947
  this.update((state) => {
948
948
  const wallet = state.accountTree.wallets[walletId];
@@ -958,7 +958,7 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
958
958
  if (group) {
959
959
  let candidate;
960
960
  for (const id of group.accounts) {
961
- const account = this.messenger.call('AccountsController:getAccount', id);
961
+ const account = this.messagingSystem.call('AccountsController:getAccount', id);
962
962
  if (!candidate) {
963
963
  candidate = id;
964
964
  }
@@ -982,7 +982,7 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
982
982
  candidate = group.id;
983
983
  }
984
984
  for (const id of group.accounts) {
985
- const account = this.messenger.call('AccountsController:getAccount', id);
985
+ const account = this.messagingSystem.call('AccountsController:getAccount', id);
986
986
  if (account && (0, keyring_api_1.isEvmAccountType)(account.type)) {
987
987
  // EVM accounts have a higher priority, so if we find any, we just
988
988
  // use that group!
@@ -993,18 +993,18 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
993
993
  }
994
994
  return candidate;
995
995
  }, _AccountTreeController_registerMessageHandlers = function _AccountTreeController_registerMessageHandlers() {
996
- this.messenger.registerActionHandler(`${exports.controllerName}:getSelectedAccountGroup`, this.getSelectedAccountGroup.bind(this));
997
- this.messenger.registerActionHandler(`${exports.controllerName}:setSelectedAccountGroup`, this.setSelectedAccountGroup.bind(this));
998
- this.messenger.registerActionHandler(`${exports.controllerName}:getAccountsFromSelectedAccountGroup`, this.getAccountsFromSelectedAccountGroup.bind(this));
999
- this.messenger.registerActionHandler(`${exports.controllerName}:setAccountWalletName`, this.setAccountWalletName.bind(this));
1000
- this.messenger.registerActionHandler(`${exports.controllerName}:setAccountGroupName`, this.setAccountGroupName.bind(this));
1001
- this.messenger.registerActionHandler(`${exports.controllerName}:setAccountGroupPinned`, this.setAccountGroupPinned.bind(this));
1002
- this.messenger.registerActionHandler(`${exports.controllerName}:setAccountGroupHidden`, this.setAccountGroupHidden.bind(this));
996
+ this.messagingSystem.registerActionHandler(`${exports.controllerName}:getSelectedAccountGroup`, this.getSelectedAccountGroup.bind(this));
997
+ this.messagingSystem.registerActionHandler(`${exports.controllerName}:setSelectedAccountGroup`, this.setSelectedAccountGroup.bind(this));
998
+ this.messagingSystem.registerActionHandler(`${exports.controllerName}:getAccountsFromSelectedAccountGroup`, this.getAccountsFromSelectedAccountGroup.bind(this));
999
+ this.messagingSystem.registerActionHandler(`${exports.controllerName}:setAccountWalletName`, this.setAccountWalletName.bind(this));
1000
+ this.messagingSystem.registerActionHandler(`${exports.controllerName}:setAccountGroupName`, this.setAccountGroupName.bind(this));
1001
+ this.messagingSystem.registerActionHandler(`${exports.controllerName}:setAccountGroupPinned`, this.setAccountGroupPinned.bind(this));
1002
+ this.messagingSystem.registerActionHandler(`${exports.controllerName}:setAccountGroupHidden`, this.setAccountGroupHidden.bind(this));
1003
1003
  }, _AccountTreeController_createBackupAndSyncContext = function _AccountTreeController_createBackupAndSyncContext() {
1004
1004
  return {
1005
1005
  ...__classPrivateFieldGet(this, _AccountTreeController_backupAndSyncConfig, "f"),
1006
1006
  controller: this,
1007
- messenger: this.messenger,
1007
+ messenger: this.messagingSystem,
1008
1008
  controllerStateUpdateFn: this.update.bind(this),
1009
1009
  traceFn: __classPrivateFieldGet(this, _AccountTreeController_trace, "f").bind(this),
1010
1010
  groupIdToWalletId: __classPrivateFieldGet(this, _AccountTreeController_groupIdToWalletId, "f"),