@metamask-previews/account-tree-controller 2.0.0-preview-4419d7e4 → 2.0.0-preview-359767df
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 +8 -0
- package/dist/AccountTreeController.cjs +82 -25
- package/dist/AccountTreeController.cjs.map +1 -1
- package/dist/AccountTreeController.d.cts +0 -12
- package/dist/AccountTreeController.d.cts.map +1 -1
- package/dist/AccountTreeController.d.mts +0 -12
- package/dist/AccountTreeController.d.mts.map +1 -1
- package/dist/AccountTreeController.mjs +83 -26
- package/dist/AccountTreeController.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +3 -3
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +3 -3
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +4 -2
|
@@ -97,18 +97,6 @@ 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
|
-
*/
|
|
112
100
|
metadata: {
|
|
113
101
|
name: string;
|
|
114
102
|
importTime: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountTreeController.d.cts","sourceRoot":"","sources":["../src/AccountTreeController.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Account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B,GAAG,SAAS;IASlC;;;;OAIG;IACH,uBAAuB,IAAI,mBAAmB,EAAE;IAIhD;;;;;;;;;;OAUG;IACH,mCAAmC,CACjC,QAAQ,CAAC,EAAE,eAAe,CAAC,eAAe,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA4B7C;;;;;OAKG;IACH,qBAAqB,CACnB,OAAO,EAAE,cAAc,GACtB,kBAAkB,GAAG,SAAS;IAuUjC;;;;OAIG;IACH,uBAAuB,IAAI,cAAc,GAAG,EAAE;IAI9C;;;;OAIG;IACH,uBAAuB,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IA6QtD;;;;;;;;OAQG;IACH,mBAAmB,CACjB,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,cAAc,EACvB,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"}
|
|
@@ -97,18 +97,6 @@ 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
|
-
*/
|
|
112
100
|
metadata: {
|
|
113
101
|
name: string;
|
|
114
102
|
importTime: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountTreeController.d.mts","sourceRoot":"","sources":["../src/AccountTreeController.ts"],"names":[],"mappings":"
|
|
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,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,CAAC;IAEpC;;OAEG;IACH,OAAO,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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_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";
|
|
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";
|
|
14
14
|
import { BaseController } from "@metamask/base-controller";
|
|
15
15
|
import { isEvmAccountType } from "@metamask/keyring-api";
|
|
16
16
|
import { assert } from "@metamask/utils";
|
|
@@ -148,6 +148,12 @@ 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
|
+
});
|
|
151
157
|
__classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_registerMessageHandlers).call(this);
|
|
152
158
|
}
|
|
153
159
|
/**
|
|
@@ -183,8 +189,20 @@ export class AccountTreeController extends BaseController {
|
|
|
183
189
|
// won't be enough and we would have to use group properties instead (like group
|
|
184
190
|
// index or maybe introduce a `importTime` at group level).
|
|
185
191
|
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);
|
|
186
200
|
// For now, we always re-compute all wallets, we do not re-use the existing state.
|
|
187
201
|
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
|
+
}
|
|
188
206
|
__classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_insert).call(this, wallets, account);
|
|
189
207
|
}
|
|
190
208
|
// Once we have the account tree, we can apply persisted metadata (names + UI states).
|
|
@@ -771,39 +789,49 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
|
|
|
771
789
|
if (!__classPrivateFieldGet(this, _AccountTreeController_initialized, "f")) {
|
|
772
790
|
return;
|
|
773
791
|
}
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
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);
|
|
793
822
|
}
|
|
794
|
-
}
|
|
795
|
-
if (accounts.length === 0) {
|
|
796
|
-
__classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_pruneEmptyGroupAndWallet).call(this, state, walletId, groupId);
|
|
797
823
|
}
|
|
798
824
|
}
|
|
799
|
-
}
|
|
825
|
+
}
|
|
826
|
+
});
|
|
827
|
+
if (removedAccounts.length) {
|
|
800
828
|
this.messenger.publish(`${controllerName}:accountTreeChange`, this.state.accountTree);
|
|
801
829
|
// Emit selectedAccountGroupChange event if the selected group changed
|
|
802
830
|
if (selectedAccountGroupChanged) {
|
|
803
831
|
this.messenger.publish(`${controllerName}:selectedAccountGroupChange`, this.state.accountTree.selectedAccountGroup, previousSelectedAccountGroup);
|
|
804
832
|
}
|
|
805
833
|
// Clear reverse-mapping for that account.
|
|
806
|
-
__classPrivateFieldGet(this, _AccountTreeController_accountIdToContext, "f").delete(accountId);
|
|
834
|
+
removedAccounts.forEach((accountId) => __classPrivateFieldGet(this, _AccountTreeController_accountIdToContext, "f").delete(accountId));
|
|
807
835
|
}
|
|
808
836
|
}, _AccountTreeController_pruneEmptyGroupAndWallet = function _AccountTreeController_pruneEmptyGroupAndWallet(state, walletId, groupId) {
|
|
809
837
|
const { wallets } = state.accountTree;
|
|
@@ -945,6 +973,35 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
|
|
|
945
973
|
wallet.status = walletStatus;
|
|
946
974
|
}
|
|
947
975
|
});
|
|
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
|
+
}
|
|
948
1005
|
}, _AccountTreeController_getAccountGroup = function _AccountTreeController_getAccountGroup(groupId) {
|
|
949
1006
|
const found = Object.values(this.state.accountTree.wallets).find((wallet) => wallet.groups[groupId] !== undefined);
|
|
950
1007
|
return found?.groups[groupId];
|