@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 +7 -1
- package/dist/AccountTreeController.cjs +38 -13
- package/dist/AccountTreeController.cjs.map +1 -1
- package/dist/AccountTreeController.d.cts.map +1 -1
- package/dist/AccountTreeController.d.mts.map +1 -1
- package/dist/AccountTreeController.mjs +40 -15
- package/dist/AccountTreeController.mjs.map +1 -1
- package/dist/group.cjs +16 -1
- package/dist/group.cjs.map +1 -1
- package/dist/group.d.cts +19 -2
- package/dist/group.d.cts.map +1 -1
- package/dist/group.d.mts +19 -2
- package/dist/group.d.mts.map +1 -1
- package/dist/group.mjs +14 -0
- package/dist/group.mjs.map +1 -1
- package/dist/index.cjs +4 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +4 -4
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +4 -4
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/wallet.cjs +16 -0
- package/dist/wallet.cjs.map +1 -1
- package/dist/wallet.d.cts +17 -2
- package/dist/wallet.d.cts.map +1 -1
- package/dist/wallet.d.mts +17 -2
- package/dist/wallet.d.mts.map +1 -1
- package/dist/wallet.mjs +14 -1
- package/dist/wallet.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -9,19 +9,20 @@ 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_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
|
-
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_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;
|
|
13
|
+
import { AccountGroupType, 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";
|
|
17
17
|
import { formatAnalyticsEvent, traceFallback } from "./backup-and-sync/analytics/index.mjs";
|
|
18
18
|
import { BackupAndSyncService } from "./backup-and-sync/service/index.mjs";
|
|
19
19
|
import { createSyncMutationTracker } from "./backup-and-sync/utils/index.mjs";
|
|
20
|
-
import { ACCOUNT_TYPE_TO_SORT_ORDER, isAccountGroupNameUnique, isAccountGroupNameUniqueFromWallet, MAX_SORT_ORDER } from "./group.mjs";
|
|
20
|
+
import { ACCOUNT_TYPE_TO_SORT_ORDER, isAccountGroupNameUnique, isAccountGroupNameUniqueFromWallet, isMultichainAccountGroup, MAX_SORT_ORDER } from "./group.mjs";
|
|
21
21
|
import { projectLogger as log } from "./logger.mjs";
|
|
22
22
|
import { EntropyRule } from "./rules/entropy.mjs";
|
|
23
23
|
import { KeyringRule } from "./rules/keyring.mjs";
|
|
24
24
|
import { SnapRule } from "./rules/snap.mjs";
|
|
25
|
+
import { isMultichainAccountWallet } from "./wallet.mjs";
|
|
25
26
|
export const controllerName = 'AccountTreeController';
|
|
26
27
|
const MESSENGER_EXPOSED_METHODS = [
|
|
27
28
|
'getSelectedAccountGroup',
|
|
@@ -177,6 +178,9 @@ export class AccountTreeController extends BaseController {
|
|
|
177
178
|
this.messenger.subscribe('MultichainAccountService:walletStatusChange', (walletId, status) => {
|
|
178
179
|
__classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_handleMultichainAccountWalletStatusChange).call(this, walletId, status);
|
|
179
180
|
});
|
|
181
|
+
this.messenger.subscribe('MultichainAccountService:groupStatusChange', (groupId, status) => {
|
|
182
|
+
__classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_handleMultichainAccountGroupStatusChange).call(this, groupId, status);
|
|
183
|
+
});
|
|
180
184
|
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
181
185
|
}
|
|
182
186
|
/**
|
|
@@ -915,7 +919,9 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
|
|
|
915
919
|
log(`[${walletId}] Added as new wallet`);
|
|
916
920
|
wallets[walletId] = {
|
|
917
921
|
...result.wallet,
|
|
918
|
-
status:
|
|
922
|
+
status: isMultichainAccountWallet(result.wallet)
|
|
923
|
+
? __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_getMultichainAccountWalletStatus).call(this, result.wallet.metadata.entropy.id)
|
|
924
|
+
: 'ready',
|
|
919
925
|
groups: {},
|
|
920
926
|
metadata: {
|
|
921
927
|
name: '', // Will get updated later.
|
|
@@ -926,7 +932,7 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
|
|
|
926
932
|
};
|
|
927
933
|
wallet = wallets[walletId];
|
|
928
934
|
// Trigger atomic sync for new wallet (only for entropy wallets)
|
|
929
|
-
if (wallet
|
|
935
|
+
if (isMultichainAccountWallet(wallet)) {
|
|
930
936
|
__classPrivateFieldGet(this, _AccountTreeController_backupAndSyncService, "f").enqueueSingleWalletSync(walletId);
|
|
931
937
|
}
|
|
932
938
|
}
|
|
@@ -941,6 +947,10 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
|
|
|
941
947
|
...result.group,
|
|
942
948
|
// Type-wise, we are guaranteed to always have at least 1 account.
|
|
943
949
|
accounts: [id],
|
|
950
|
+
...(isMultichainAccountGroup(result.group) &&
|
|
951
|
+
isMultichainAccountWallet(result.wallet) && {
|
|
952
|
+
status: __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_getMultichainAccountGroupStatus).call(this, result.wallet.metadata.entropy.id, result.group.metadata.entropy.groupIndex),
|
|
953
|
+
}),
|
|
944
954
|
metadata: {
|
|
945
955
|
name: '',
|
|
946
956
|
...{ pinned: false, hidden: false, lastSelected: 0 }, // Default UI states
|
|
@@ -953,7 +963,7 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
|
|
|
953
963
|
// Map group ID to its containing wallet ID for efficient direct access
|
|
954
964
|
__classPrivateFieldGet(this, _AccountTreeController_groupIdToWalletId, "f").set(groupId, walletId);
|
|
955
965
|
// Trigger atomic sync for new group (only for entropy wallets)
|
|
956
|
-
if (wallet
|
|
966
|
+
if (isMultichainAccountWallet(wallet)) {
|
|
957
967
|
__classPrivateFieldGet(this, _AccountTreeController_backupAndSyncService, "f").enqueueSingleGroupSync(groupId);
|
|
958
968
|
}
|
|
959
969
|
}
|
|
@@ -1010,9 +1020,6 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
|
|
|
1010
1020
|
if (!accountToSelect) {
|
|
1011
1021
|
throw new Error('No accounts found in group');
|
|
1012
1022
|
}
|
|
1013
|
-
const gutoSetGroupStart = Date.now();
|
|
1014
|
-
console.log('[GUTO PERFORMANCE LOG] AccountTreeController.#setSelectedAccountGroup START');
|
|
1015
|
-
const gutoUpdateStart = Date.now();
|
|
1016
1023
|
this.update((state) => {
|
|
1017
1024
|
// Update our selected account group first.
|
|
1018
1025
|
state.selectedAccountGroup = groupId;
|
|
@@ -1029,20 +1036,14 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
|
|
|
1029
1036
|
state.accountTree.wallets[walletId].groups[groupId].metadata.lastSelected = now;
|
|
1030
1037
|
}
|
|
1031
1038
|
});
|
|
1032
|
-
console.log(`[GUTO PERFORMANCE LOG] AccountTreeController state.update (sync) took ${Date.now() - gutoUpdateStart}ms`);
|
|
1033
1039
|
log(`Selected group is now: [${this.state.selectedAccountGroup}]`);
|
|
1034
|
-
const gutoPublishStart = Date.now();
|
|
1035
1040
|
this.messenger.publish(`${controllerName}:selectedAccountGroupChange`, groupId, previousSelectedAccountGroup);
|
|
1036
|
-
console.log(`[GUTO PERFORMANCE LOG] AccountTreeController publish selectedAccountGroupChange (sync subscriber fan-out) took ${Date.now() - gutoPublishStart}ms`);
|
|
1037
1041
|
if (forwardSelectedAccount) {
|
|
1038
1042
|
// Update AccountsController - this will trigger selectedAccountChange event,
|
|
1039
1043
|
// but our handler is idempotent so it won't cause infinite loop
|
|
1040
|
-
const gutoSetAccountStart = Date.now();
|
|
1041
1044
|
this.messenger.call('AccountsController:setSelectedAccount', accountToSelect);
|
|
1042
|
-
console.log(`[GUTO PERFORMANCE LOG] AccountTreeController AccountsController:setSelectedAccount (sync selectedAccountChange fan-out) took ${Date.now() - gutoSetAccountStart}ms`);
|
|
1043
1045
|
log(`Selected account is now: ${accountToSelect}`);
|
|
1044
1046
|
}
|
|
1045
|
-
console.log(`[GUTO PERFORMANCE LOG] AccountTreeController.#setSelectedAccountGroup END (total, sync) took ${Date.now() - gutoSetGroupStart}ms`);
|
|
1046
1047
|
}, _AccountTreeController_getDefaultSelectedAccountGroup = function _AccountTreeController_getDefaultSelectedAccountGroup(wallets) {
|
|
1047
1048
|
const selectedAccount = this.messenger.call('AccountsController:getSelectedMultichainAccount');
|
|
1048
1049
|
if (selectedAccount?.id) {
|
|
@@ -1071,6 +1072,30 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
|
|
|
1071
1072
|
wallet.status = walletStatus;
|
|
1072
1073
|
}
|
|
1073
1074
|
});
|
|
1075
|
+
}, _AccountTreeController_handleMultichainAccountGroupStatusChange = function _AccountTreeController_handleMultichainAccountGroupStatusChange(groupId, groupStatus) {
|
|
1076
|
+
this.update((state) => {
|
|
1077
|
+
const walletId = __classPrivateFieldGet(this, _AccountTreeController_groupIdToWalletId, "f").get(groupId);
|
|
1078
|
+
if (walletId) {
|
|
1079
|
+
const group = state.accountTree.wallets[walletId]?.groups[groupId];
|
|
1080
|
+
if (group && isMultichainAccountGroup(group)) {
|
|
1081
|
+
group.status = groupStatus;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
});
|
|
1085
|
+
}, _AccountTreeController_getMultichainAccountWalletStatus = function _AccountTreeController_getMultichainAccountWalletStatus(entropySource) {
|
|
1086
|
+
try {
|
|
1087
|
+
return this.messenger.call('MultichainAccountService:getMultichainAccountWallet', { entropySource }).status;
|
|
1088
|
+
}
|
|
1089
|
+
catch {
|
|
1090
|
+
return 'uninitialized';
|
|
1091
|
+
}
|
|
1092
|
+
}, _AccountTreeController_getMultichainAccountGroupStatus = function _AccountTreeController_getMultichainAccountGroupStatus(entropySource, groupIndex) {
|
|
1093
|
+
try {
|
|
1094
|
+
return this.messenger.call('MultichainAccountService:getMultichainAccountGroup', { entropySource, groupIndex }).status;
|
|
1095
|
+
}
|
|
1096
|
+
catch {
|
|
1097
|
+
return 'uninitialized';
|
|
1098
|
+
}
|
|
1074
1099
|
}, _AccountTreeController_getAccountGroup = function _AccountTreeController_getAccountGroup(groupId) {
|
|
1075
1100
|
const found = Object.values(this.state.accountTree.wallets).find((wallet) => wallet.groups[groupId] !== undefined);
|
|
1076
1101
|
return found?.groups[groupId];
|