@metamask-previews/account-tree-controller 2.0.0-preview-359767df → 2.0.0-preview-5e4e26a6

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.
@@ -97,6 +97,18 @@ export declare class AccountTreeController extends BaseController<typeof control
97
97
  } | undefined;
98
98
  exportable?: boolean | undefined;
99
99
  };
100
+ /**
101
+ * Helper method to prune a group if it holds no accounts and additionally
102
+ * prune the wallet if it holds no groups. This action should take place
103
+ * after a singular account removal.
104
+ *
105
+ * NOTE: This method should only be used for a group that we know to be empty.
106
+ *
107
+ * @param state - The AccountTreeController state to prune.
108
+ * @param walletId - The wallet ID to prune, the wallet should be the parent of the associated group that holds the removed account.
109
+ * @param groupId - The group ID to prune, the group should be the parent of the associated account that was removed.
110
+ * @returns The updated state.
111
+ */
100
112
  metadata: {
101
113
  name: string;
102
114
  importTime: number;
@@ -1 +1 @@
1
- {"version":3,"file":"AccountTreeController.d.cts","sourceRoot":"","sources":["../src/AccountTreeController.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,eAAe,EAIhB,8BAA8B;AAK/B,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAI3D,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAUtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,oBAAgB;AACvE,OAAO,EACL,0BAA0B,EAI3B,oBAAgB;AAMjB,OAAO,KAAK,EACV,2BAA2B,EAE3B,8BAA8B,EAC9B,0BAA0B,EAC3B,oBAAgB;AACjB,OAAO,EAAE,KAAK,mBAAmB,EAA8B,qBAAiB;AAEhF,eAAO,MAAM,cAAc,0BAA0B,CAAC;AAoCtD;;;;GAIG;AACH,wBAAgB,oCAAoC,IAAI,0BAA0B,CAWjF;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B;;OAEG;IACH,QAAQ,EAAE,mBAAmB,CAAC,IAAI,CAAC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AAI;IAyBnE;;;;;;OAMG;IACH,qBAAqB,CAAC,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI;IAmCrE;;;;;;OAMG;IACH,qBAAqB,CAAC,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI;IAmCrE;;;OAGG;IACH,UAAU,IAAI,IAAI;IAsDlB;;;;;;;;;;OAUG;IACG,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAI1C;;;;;;;;;;;OAWG;IACG,8BAA8B,IAAI,OAAO,CAAC,IAAI,CAAC;CAoBtD"}
@@ -97,6 +97,18 @@ export declare class AccountTreeController extends BaseController<typeof control
97
97
  } | undefined;
98
98
  exportable?: boolean | undefined;
99
99
  };
100
+ /**
101
+ * Helper method to prune a group if it holds no accounts and additionally
102
+ * prune the wallet if it holds no groups. This action should take place
103
+ * after a singular account removal.
104
+ *
105
+ * NOTE: This method should only be used for a group that we know to be empty.
106
+ *
107
+ * @param state - The AccountTreeController state to prune.
108
+ * @param walletId - The wallet ID to prune, the wallet should be the parent of the associated group that holds the removed account.
109
+ * @param groupId - The group ID to prune, the group should be the parent of the associated account that was removed.
110
+ * @returns The updated state.
111
+ */
100
112
  metadata: {
101
113
  name: string;
102
114
  importTime: number;
@@ -1 +1 @@
1
- {"version":3,"file":"AccountTreeController.d.mts","sourceRoot":"","sources":["../src/AccountTreeController.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,eAAe,EAIhB,8BAA8B;AAK/B,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAI3D,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAUtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,oBAAgB;AACvE,OAAO,EACL,0BAA0B,EAI3B,oBAAgB;AAMjB,OAAO,KAAK,EACV,2BAA2B,EAE3B,8BAA8B,EAC9B,0BAA0B,EAC3B,oBAAgB;AACjB,O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B,IAAI,EAAE,MAAM,GACX,MAAM;IAeT;;;;;;;;OAQG;IACH,mBAAmB,CACjB,OAAO,EAAE,cAAc,EACvB,IAAI,EAAE,MAAM,EACZ,kBAAkB,GAAE,OAAe,GAClC,IAAI;IAgDP;;;;;;OAMG;IACH,oBAAoB,CAAC,QAAQ,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAyBnE;;;;;;OAMG;IACH,qBAAqB,CAAC,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI;IAmCrE;;;;;;OAMG;IACH,qBAAqB,CAAC,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI;IAmCrE;;;OAGG;IACH,UAAU,IAAI,IAAI;IAsDlB;;;;;;;;;;OAUG;IACG,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAI1C;;;;;;;;;;;OAWG;IACG,8BAA8B,IAAI,OAAO,CAAC,IAAI,CAAC;CAoBtD"}
@@ -9,8 +9,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  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");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _AccountTreeController_instances, _AccountTreeController_accountIdToContext, _AccountTreeController_groupIdToWalletId, _AccountTreeController_backupAndSyncService, _AccountTreeController_rules, _AccountTreeController_trace, _AccountTreeController_backupAndSyncConfig, _AccountTreeController_accountOrderCallbacks, _AccountTreeController_initialized, _AccountTreeController_getEntropyRule, _AccountTreeController_getSnapRule, _AccountTreeController_getKeyringRule, _AccountTreeController_applyAccountWalletMetadata, _AccountTreeController_getRuleForWallet, _AccountTreeController_getComputedAccountGroupName, _AccountTreeController_getDefaultAccountGroupName, _AccountTreeController_applyAccountGroupMetadata, _AccountTreeController_handleAccountAdded, _AccountTreeController_handleAccountRemoved, _AccountTreeController_removeAccounts, _AccountTreeController_pruneEmptyGroupAndWallet, _AccountTreeController_insert, _AccountTreeController_listAccounts, _AccountTreeController_assertAccountGroupExists, _AccountTreeController_assertAccountWalletExists, _AccountTreeController_assertAccountGroupNameIsUnique, _AccountTreeController_getDefaultSelectedAccountGroup, _AccountTreeController_handleSelectedAccountChange, _AccountTreeController_handleMultichainAccountWalletStatusChange, _AccountTreeController_getBip44AccountIdsFromMultichainAccountGroup, _AccountTreeController_getBip44AccountIds, _AccountTreeController_handleMultichainAccountWalletGroupCreatedOrUpdated, _AccountTreeController_getAccountGroup, _AccountTreeController_getDefaultAccountFromAccountGroupId, _AccountTreeController_getDefaultAccountGroupId, _AccountTreeController_registerMessageHandlers, _AccountTreeController_createBackupAndSyncContext;
13
- import { AccountWalletType, isBip44Account, select } from "@metamask/account-api";
12
+ var _AccountTreeController_instances, _AccountTreeController_accountIdToContext, _AccountTreeController_groupIdToWalletId, _AccountTreeController_backupAndSyncService, _AccountTreeController_rules, _AccountTreeController_trace, _AccountTreeController_backupAndSyncConfig, _AccountTreeController_accountOrderCallbacks, _AccountTreeController_initialized, _AccountTreeController_getEntropyRule, _AccountTreeController_getSnapRule, _AccountTreeController_getKeyringRule, _AccountTreeController_applyAccountWalletMetadata, _AccountTreeController_getRuleForWallet, _AccountTreeController_getComputedAccountGroupName, _AccountTreeController_getDefaultAccountGroupName, _AccountTreeController_applyAccountGroupMetadata, _AccountTreeController_handleAccountAdded, _AccountTreeController_handleAccountRemoved, _AccountTreeController_pruneEmptyGroupAndWallet, _AccountTreeController_insert, _AccountTreeController_listAccounts, _AccountTreeController_assertAccountGroupExists, _AccountTreeController_assertAccountWalletExists, _AccountTreeController_assertAccountGroupNameIsUnique, _AccountTreeController_getDefaultSelectedAccountGroup, _AccountTreeController_handleSelectedAccountChange, _AccountTreeController_handleMultichainAccountWalletStatusChange, _AccountTreeController_getAccountGroup, _AccountTreeController_getDefaultAccountFromAccountGroupId, _AccountTreeController_getDefaultAccountGroupId, _AccountTreeController_registerMessageHandlers, _AccountTreeController_createBackupAndSyncContext;
13
+ import { AccountWalletType, select } from "@metamask/account-api";
14
14
  import { BaseController } from "@metamask/base-controller";
15
15
  import { isEvmAccountType } from "@metamask/keyring-api";
16
16
  import { assert } from "@metamask/utils";
@@ -148,12 +148,6 @@ export class AccountTreeController extends BaseController {
148
148
  this.messenger.subscribe('MultichainAccountService:walletStatusChange', (walletId, status) => {
149
149
  __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_handleMultichainAccountWalletStatusChange).call(this, walletId, status);
150
150
  });
151
- this.messenger.subscribe('MultichainAccountService:multichainAccountGroupCreated', (group) => {
152
- __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_handleMultichainAccountWalletGroupCreatedOrUpdated).call(this, group);
153
- });
154
- this.messenger.subscribe('MultichainAccountService:multichainAccountGroupUpdated', (group) => {
155
- __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_handleMultichainAccountWalletGroupCreatedOrUpdated).call(this, group);
156
- });
157
151
  __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_registerMessageHandlers).call(this);
158
152
  }
159
153
  /**
@@ -189,20 +183,8 @@ export class AccountTreeController extends BaseController {
189
183
  // won't be enough and we would have to use group properties instead (like group
190
184
  // index or maybe introduce a `importTime` at group level).
191
185
  const accounts = __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_listAccounts).call(this).sort((a, b) => a.metadata.importTime - b.metadata.importTime);
192
- // HACK: Since we're not consuming accounts directly from the service, we have to
193
- // cross-check with its internal state before inserting initial BIP-44 accounts.
194
- // Those accounts could be marked as "disabled" (using the
195
- // `AccountProviderWrapper`) and if they are, we don't want to insert them in the tree.
196
- // The real fix for this would be consume accounts from the service instead of the
197
- // `AccountsController`, but this requires a bit more testing, for now we keep this
198
- // simple.
199
- const bip44Accounts = __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_getBip44AccountIds).call(this);
200
186
  // For now, we always re-compute all wallets, we do not re-use the existing state.
201
187
  for (const account of accounts) {
202
- if (isBip44Account(account) && !bip44Accounts.has(account.id)) {
203
- // We skip those, so they won't be part of the initial tree.
204
- continue;
205
- }
206
188
  __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_insert).call(this, wallets, account);
207
189
  }
208
190
  // Once we have the account tree, we can apply persisted metadata (names + UI states).
@@ -789,49 +771,39 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
789
771
  if (!__classPrivateFieldGet(this, _AccountTreeController_initialized, "f")) {
790
772
  return;
791
773
  }
792
- __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_removeAccounts).call(this, [accountId]);
793
- }, _AccountTreeController_removeAccounts = function _AccountTreeController_removeAccounts(accountIds) {
794
- const removedAccounts = [];
795
- const previousSelectedAccountGroup = this.state.accountTree.selectedAccountGroup;
796
- let selectedAccountGroupChanged = false;
797
- this.update((state) => {
798
- for (const accountId of accountIds) {
799
- const context = __classPrivateFieldGet(this, _AccountTreeController_accountIdToContext, "f").get(accountId);
800
- if (context) {
801
- const { walletId, groupId } = context;
802
- const accounts = state.accountTree.wallets[walletId]?.groups[groupId]?.accounts;
803
- if (accounts) {
804
- const index = accounts.indexOf(accountId);
805
- if (index !== -1) {
806
- accounts.splice(index, 1);
807
- // Now we know this account got removed.
808
- removedAccounts.push(accountId);
809
- // Check if we need to update selectedAccountGroup after removal
810
- if (state.accountTree.selectedAccountGroup === groupId &&
811
- accounts.length === 0) {
812
- // The currently selected group is now empty, find a new group to select
813
- const newSelectedAccountGroup = __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_getDefaultAccountGroupId).call(this, state.accountTree.wallets);
814
- state.accountTree.selectedAccountGroup =
815
- newSelectedAccountGroup;
816
- selectedAccountGroupChanged =
817
- newSelectedAccountGroup !== previousSelectedAccountGroup;
818
- }
819
- }
820
- if (accounts.length === 0) {
821
- __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_pruneEmptyGroupAndWallet).call(this, state, walletId, groupId);
774
+ const context = __classPrivateFieldGet(this, _AccountTreeController_accountIdToContext, "f").get(accountId);
775
+ if (context) {
776
+ const { walletId, groupId } = context;
777
+ const previousSelectedAccountGroup = this.state.accountTree.selectedAccountGroup;
778
+ let selectedAccountGroupChanged = false;
779
+ this.update((state) => {
780
+ const accounts = state.accountTree.wallets[walletId]?.groups[groupId]?.accounts;
781
+ if (accounts) {
782
+ const index = accounts.indexOf(accountId);
783
+ if (index !== -1) {
784
+ accounts.splice(index, 1);
785
+ // Check if we need to update selectedAccountGroup after removal
786
+ if (state.accountTree.selectedAccountGroup === groupId &&
787
+ accounts.length === 0) {
788
+ // The currently selected group is now empty, find a new group to select
789
+ const newSelectedAccountGroup = __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_getDefaultAccountGroupId).call(this, state.accountTree.wallets);
790
+ state.accountTree.selectedAccountGroup = newSelectedAccountGroup;
791
+ selectedAccountGroupChanged =
792
+ newSelectedAccountGroup !== previousSelectedAccountGroup;
822
793
  }
823
794
  }
795
+ if (accounts.length === 0) {
796
+ __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_pruneEmptyGroupAndWallet).call(this, state, walletId, groupId);
797
+ }
824
798
  }
825
- }
826
- });
827
- if (removedAccounts.length) {
799
+ });
828
800
  this.messenger.publish(`${controllerName}:accountTreeChange`, this.state.accountTree);
829
801
  // Emit selectedAccountGroupChange event if the selected group changed
830
802
  if (selectedAccountGroupChanged) {
831
803
  this.messenger.publish(`${controllerName}:selectedAccountGroupChange`, this.state.accountTree.selectedAccountGroup, previousSelectedAccountGroup);
832
804
  }
833
805
  // Clear reverse-mapping for that account.
834
- removedAccounts.forEach((accountId) => __classPrivateFieldGet(this, _AccountTreeController_accountIdToContext, "f").delete(accountId));
806
+ __classPrivateFieldGet(this, _AccountTreeController_accountIdToContext, "f").delete(accountId);
835
807
  }
836
808
  }, _AccountTreeController_pruneEmptyGroupAndWallet = function _AccountTreeController_pruneEmptyGroupAndWallet(state, walletId, groupId) {
837
809
  const { wallets } = state.accountTree;
@@ -973,35 +945,6 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
973
945
  wallet.status = walletStatus;
974
946
  }
975
947
  });
976
- }, _AccountTreeController_getBip44AccountIdsFromMultichainAccountGroup = function _AccountTreeController_getBip44AccountIdsFromMultichainAccountGroup(group) {
977
- // FIXME: We should introduce a way to just get the account IDs since getting
978
- // account object might be a bit more costly (at least with the current
979
- // architecture).
980
- return new Set(group.getAccounts().map((account) => account.id));
981
- }, _AccountTreeController_getBip44AccountIds = function _AccountTreeController_getBip44AccountIds() {
982
- const accounts = new Set();
983
- // Since we're building the tree out of of the account list, we don't know if those
984
- // accounts got disabled at the service level. To make sure both states are "in-sync"
985
- // we check each multichain account groups and remove extra accounts if there's any!
986
- for (const wallet of this.messenger.call('MultichainAccountService:getMultichainAccountWallets')) {
987
- for (const group of wallet.getMultichainAccountGroups()) {
988
- for (const account of __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_getBip44AccountIdsFromMultichainAccountGroup).call(this, group)) {
989
- accounts.add(account);
990
- }
991
- }
992
- }
993
- return accounts;
994
- }, _AccountTreeController_handleMultichainAccountWalletGroupCreatedOrUpdated = function _AccountTreeController_handleMultichainAccountWalletGroupCreatedOrUpdated(multichainGroup) {
995
- const bip44GroupAccounts = __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_getBip44AccountIdsFromMultichainAccountGroup).call(this, multichainGroup);
996
- const group = __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_getAccountGroup).call(this, multichainGroup.id);
997
- if (group) {
998
- __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_removeAccounts).call(this, group.accounts.filter(
999
- // We only check if some accounts are no longer part of the multichain
1000
- // account group. This is required mainly with the `AccountProviderWrapper`s that
1001
- // can be disabled when "Basic functionality" is turned OFF or when the wrappers
1002
- // are controlled by remote feature flags.
1003
- (account) => !bip44GroupAccounts.has(account)));
1004
- }
1005
948
  }, _AccountTreeController_getAccountGroup = function _AccountTreeController_getAccountGroup(groupId) {
1006
949
  const found = Object.values(this.state.accountTree.wallets).find((wallet) => wallet.groups[groupId] !== undefined);
1007
950
  return found?.groups[groupId];