@metamask-previews/account-tree-controller 1.5.0-preview-53e28985 → 1.5.0-preview-887b5d5c
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 +0 -4
- package/dist/AccountTreeController.cjs +73 -167
- 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 +74 -168
- package/dist/AccountTreeController.mjs.map +1 -1
- package/dist/rules/entropy.cjs +34 -2
- package/dist/rules/entropy.cjs.map +1 -1
- package/dist/rules/entropy.d.cts +2 -1
- package/dist/rules/entropy.d.cts.map +1 -1
- package/dist/rules/entropy.d.mts +2 -1
- package/dist/rules/entropy.d.mts.map +1 -1
- package/dist/rules/entropy.mjs +35 -3
- package/dist/rules/entropy.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +8 -4
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +8 -4
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,10 +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
|
-
- Bump `@metamask/base-controller` from `^8.4.1` to `^8.4.2` ([#6917](https://github.com/MetaMask/core/pull/6917))
|
|
13
|
-
|
|
14
10
|
## [1.5.0]
|
|
15
11
|
|
|
16
12
|
### Changed
|
|
@@ -10,11 +10,10 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
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");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _AccountTreeController_instances, _AccountTreeController_accountIdToContext, _AccountTreeController_groupIdToWalletId, _AccountTreeController_backupAndSyncService, _AccountTreeController_rules, _AccountTreeController_trace, _AccountTreeController_backupAndSyncConfig, _AccountTreeController_initialized, _AccountTreeController_getEntropyRule, _AccountTreeController_getSnapRule, _AccountTreeController_getKeyringRule, _AccountTreeController_applyAccountWalletMetadata, _AccountTreeController_getRuleForWallet, _AccountTreeController_getComputedAccountGroupName, _AccountTreeController_getDefaultAccountGroupName, _AccountTreeController_applyAccountGroupMetadata, _AccountTreeController_handleAccountAdded, _AccountTreeController_handleAccountRemoved, _AccountTreeController_pruneEmptyGroupAndWallet,
|
|
13
|
+
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;
|
|
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 account_api_2 = require("@metamask/account-api");
|
|
18
17
|
const base_controller_1 = require("@metamask/base-controller");
|
|
19
18
|
const keyring_api_1 = require("@metamask/keyring-api");
|
|
20
19
|
const utils_1 = require("@metamask/utils");
|
|
@@ -105,6 +104,10 @@ class AccountTreeController extends base_controller_1.BaseController {
|
|
|
105
104
|
_AccountTreeController_rules.set(this, void 0);
|
|
106
105
|
_AccountTreeController_trace.set(this, void 0);
|
|
107
106
|
_AccountTreeController_backupAndSyncConfig.set(this, void 0);
|
|
107
|
+
/**
|
|
108
|
+
* Callbacks to migrate hidden and pinned account information from the account order controller
|
|
109
|
+
*/
|
|
110
|
+
_AccountTreeController_accountOrderCallbacks.set(this, void 0);
|
|
108
111
|
_AccountTreeController_initialized.set(this, void 0);
|
|
109
112
|
// This will be set to true upon the first `init` call.
|
|
110
113
|
__classPrivateFieldSet(this, _AccountTreeController_initialized, false, "f");
|
|
@@ -130,6 +133,7 @@ class AccountTreeController extends base_controller_1.BaseController {
|
|
|
130
133
|
config.backupAndSync.onBackupAndSyncEvent((0, analytics_1.formatAnalyticsEvent)(event)));
|
|
131
134
|
},
|
|
132
135
|
}, "f");
|
|
136
|
+
__classPrivateFieldSet(this, _AccountTreeController_accountOrderCallbacks, config?.accountOrderCallbacks, "f");
|
|
133
137
|
// Initialize the backup and sync service
|
|
134
138
|
__classPrivateFieldSet(this, _AccountTreeController_backupAndSyncService, new service_1.BackupAndSyncService(__classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_createBackupAndSyncContext).call(this)), "f");
|
|
135
139
|
this.messagingSystem.subscribe('AccountsController:accountAdded', (account) => {
|
|
@@ -144,12 +148,6 @@ class AccountTreeController extends base_controller_1.BaseController {
|
|
|
144
148
|
this.messagingSystem.subscribe('UserStorageController:stateChange', (userStorageControllerState) => {
|
|
145
149
|
__classPrivateFieldGet(this, _AccountTreeController_backupAndSyncService, "f").handleUserStorageStateChange(userStorageControllerState);
|
|
146
150
|
});
|
|
147
|
-
this.messagingSystem.subscribe('MultichainAccountService:multichainAccountGroupCreated', (group) => {
|
|
148
|
-
__classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_handleMultichainAccountGroupCreatedOrUpdated).call(this, group);
|
|
149
|
-
});
|
|
150
|
-
this.messagingSystem.subscribe('MultichainAccountService:multichainAccountGroupUpdated', (group) => {
|
|
151
|
-
__classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_handleMultichainAccountGroupCreatedOrUpdated).call(this, group);
|
|
152
|
-
});
|
|
153
151
|
this.messagingSystem.subscribe('MultichainAccountService:walletStatusChange', (walletId, status) => {
|
|
154
152
|
__classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_handleMultichainAccountWalletStatusChange).call(this, walletId, status);
|
|
155
153
|
});
|
|
@@ -169,7 +167,6 @@ class AccountTreeController extends base_controller_1.BaseController {
|
|
|
169
167
|
return;
|
|
170
168
|
}
|
|
171
169
|
(0, logger_1.projectLogger)('Initializing...');
|
|
172
|
-
// For now, we always re-compute all wallets, we do not re-use the existing state.
|
|
173
170
|
const wallets = {};
|
|
174
171
|
// Clear mappings for fresh rebuild.
|
|
175
172
|
__classPrivateFieldGet(this, _AccountTreeController_accountIdToContext, "f").clear();
|
|
@@ -177,12 +174,6 @@ class AccountTreeController extends base_controller_1.BaseController {
|
|
|
177
174
|
// Keep the current selected group to check if it's still part of the tree
|
|
178
175
|
// after rebuilding it.
|
|
179
176
|
const previousSelectedAccountGroup = this.state.accountTree.selectedAccountGroup;
|
|
180
|
-
// Insert all multichain account wallet/groups.
|
|
181
|
-
for (const wallet of __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_getMultichainAccountWallets).call(this)) {
|
|
182
|
-
for (const group of wallet.getMultichainAccountGroups()) {
|
|
183
|
-
__classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_insertOrUpdateMultichainAccountWalletAndGroup).call(this, wallets, wallet, group);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
177
|
// There's no guarantee that accounts would be sorted by their import time
|
|
187
178
|
// with `listMultichainAccounts`. We have to sort them here before constructing
|
|
188
179
|
// the tree.
|
|
@@ -195,9 +186,9 @@ class AccountTreeController extends base_controller_1.BaseController {
|
|
|
195
186
|
// won't be enough and we would have to use group properties instead (like group
|
|
196
187
|
// index or maybe introduce a `importTime` at group level).
|
|
197
188
|
const accounts = __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_listAccounts).call(this).sort((a, b) => a.metadata.importTime - b.metadata.importTime);
|
|
198
|
-
//
|
|
189
|
+
// For now, we always re-compute all wallets, we do not re-use the existing state.
|
|
199
190
|
for (const account of accounts) {
|
|
200
|
-
__classPrivateFieldGet(this, _AccountTreeController_instances, "m",
|
|
191
|
+
__classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_insert).call(this, wallets, account);
|
|
201
192
|
}
|
|
202
193
|
// Once we have the account tree, we can apply persisted metadata (names + UI states).
|
|
203
194
|
let previousSelectedAccountGroupStillExists = false;
|
|
@@ -569,7 +560,7 @@ class AccountTreeController extends base_controller_1.BaseController {
|
|
|
569
560
|
}
|
|
570
561
|
}
|
|
571
562
|
exports.AccountTreeController = AccountTreeController;
|
|
572
|
-
_AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeController_groupIdToWalletId = new WeakMap(), _AccountTreeController_backupAndSyncService = new WeakMap(), _AccountTreeController_rules = new WeakMap(), _AccountTreeController_trace = new WeakMap(), _AccountTreeController_backupAndSyncConfig = new WeakMap(), _AccountTreeController_initialized = new WeakMap(), _AccountTreeController_instances = new WeakSet(), _AccountTreeController_getEntropyRule = function _AccountTreeController_getEntropyRule() {
|
|
563
|
+
_AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeController_groupIdToWalletId = new WeakMap(), _AccountTreeController_backupAndSyncService = new WeakMap(), _AccountTreeController_rules = new WeakMap(), _AccountTreeController_trace = new WeakMap(), _AccountTreeController_backupAndSyncConfig = new WeakMap(), _AccountTreeController_accountOrderCallbacks = new WeakMap(), _AccountTreeController_initialized = new WeakMap(), _AccountTreeController_instances = new WeakSet(), _AccountTreeController_getEntropyRule = function _AccountTreeController_getEntropyRule() {
|
|
573
564
|
return __classPrivateFieldGet(this, _AccountTreeController_rules, "f")[0];
|
|
574
565
|
}, _AccountTreeController_getSnapRule = function _AccountTreeController_getSnapRule() {
|
|
575
566
|
return __classPrivateFieldGet(this, _AccountTreeController_rules, "f")[1];
|
|
@@ -725,9 +716,23 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
|
|
|
725
716
|
if (persistedGroupMetadata?.pinned?.value !== undefined) {
|
|
726
717
|
group.metadata.pinned = persistedGroupMetadata.pinned.value;
|
|
727
718
|
}
|
|
719
|
+
else if (__classPrivateFieldGet(this, _AccountTreeController_accountOrderCallbacks, "f")?.isPinnedAccount) {
|
|
720
|
+
// If any accounts was previously pinned, then we consider the group to be pinned as well.
|
|
721
|
+
group.metadata.pinned = Object.values(group.accounts).some((account) => __classPrivateFieldGet(this, _AccountTreeController_accountOrderCallbacks, "f")?.isPinnedAccount?.(account));
|
|
722
|
+
}
|
|
723
|
+
else {
|
|
724
|
+
group.metadata.pinned = false;
|
|
725
|
+
}
|
|
728
726
|
if (persistedGroupMetadata?.hidden?.value !== undefined) {
|
|
729
727
|
group.metadata.hidden = persistedGroupMetadata.hidden.value;
|
|
730
728
|
}
|
|
729
|
+
else if (__classPrivateFieldGet(this, _AccountTreeController_accountOrderCallbacks, "f")?.isHiddenAccount) {
|
|
730
|
+
// If any accounts was previously hidden, then we consider the group to be hidden as well.
|
|
731
|
+
group.metadata.hidden = Object.values(group.accounts).some((account) => __classPrivateFieldGet(this, _AccountTreeController_accountOrderCallbacks, "f")?.isHiddenAccount?.(account));
|
|
732
|
+
}
|
|
733
|
+
else {
|
|
734
|
+
group.metadata.hidden = false;
|
|
735
|
+
}
|
|
731
736
|
}, _AccountTreeController_handleAccountAdded = function _AccountTreeController_handleAccountAdded(account) {
|
|
732
737
|
// We wait for the first `init` to be called to actually build up the tree and
|
|
733
738
|
// mutate it. We expect the caller to first update the `AccountsController` state
|
|
@@ -735,15 +740,10 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
|
|
|
735
740
|
if (!__classPrivateFieldGet(this, _AccountTreeController_initialized, "f")) {
|
|
736
741
|
return;
|
|
737
742
|
}
|
|
738
|
-
if ((0, account_api_1.isBip44Account)(account)) {
|
|
739
|
-
// We're skipping BIP-44 accounts since we rely on the `MultichainAccountService` to do
|
|
740
|
-
// the grouping of wallets/groups directly.
|
|
741
|
-
return;
|
|
742
|
-
}
|
|
743
743
|
// Check if this account is already known by the tree to avoid double-insertion.
|
|
744
744
|
if (!__classPrivateFieldGet(this, _AccountTreeController_accountIdToContext, "f").has(account.id)) {
|
|
745
745
|
this.update((state) => {
|
|
746
|
-
__classPrivateFieldGet(this, _AccountTreeController_instances, "m",
|
|
746
|
+
__classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_insert).call(this, state.accountTree.wallets, account);
|
|
747
747
|
const context = __classPrivateFieldGet(this, _AccountTreeController_accountIdToContext, "f").get(account.id);
|
|
748
748
|
if (context) {
|
|
749
749
|
const { walletId, groupId } = context;
|
|
@@ -766,39 +766,33 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
|
|
|
766
766
|
const context = __classPrivateFieldGet(this, _AccountTreeController_accountIdToContext, "f").get(accountId);
|
|
767
767
|
if (context) {
|
|
768
768
|
const { walletId, groupId } = context;
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
const previousSelectedAccountGroup = this.state.accountTree.selectedAccountGroup;
|
|
777
|
-
this.update((state) => {
|
|
778
|
-
const accounts = state.accountTree.wallets[walletId]?.groups[groupId].accounts;
|
|
779
|
-
// Effectively remove account from the group and state.
|
|
769
|
+
const previousSelectedAccountGroup = this.state.accountTree.selectedAccountGroup;
|
|
770
|
+
let selectedAccountGroupChanged = false;
|
|
771
|
+
this.update((state) => {
|
|
772
|
+
const accounts = state.accountTree.wallets[walletId]?.groups[groupId]?.accounts;
|
|
773
|
+
if (accounts) {
|
|
774
|
+
const index = accounts.indexOf(accountId);
|
|
775
|
+
if (index !== -1) {
|
|
780
776
|
accounts.splice(index, 1);
|
|
781
|
-
//
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
//
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
newSelectedAccountGroup;
|
|
790
|
-
selectedAccountGroupChanged =
|
|
791
|
-
newSelectedAccountGroup !== previousSelectedAccountGroup;
|
|
792
|
-
}
|
|
793
|
-
__classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_pruneEmptyGroupAndWallet).call(this, state, walletId, groupId);
|
|
777
|
+
// Check if we need to update selectedAccountGroup after removal
|
|
778
|
+
if (state.accountTree.selectedAccountGroup === groupId &&
|
|
779
|
+
accounts.length === 0) {
|
|
780
|
+
// The currently selected group is now empty, find a new group to select
|
|
781
|
+
const newSelectedAccountGroup = __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_getDefaultAccountGroupId).call(this, state.accountTree.wallets);
|
|
782
|
+
state.accountTree.selectedAccountGroup = newSelectedAccountGroup;
|
|
783
|
+
selectedAccountGroupChanged =
|
|
784
|
+
newSelectedAccountGroup !== previousSelectedAccountGroup;
|
|
794
785
|
}
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
if (selectedAccountGroupChanged) {
|
|
799
|
-
this.messagingSystem.publish(`${exports.controllerName}:selectedAccountGroupChange`, this.state.accountTree.selectedAccountGroup, previousSelectedAccountGroup);
|
|
786
|
+
}
|
|
787
|
+
if (accounts.length === 0) {
|
|
788
|
+
__classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_pruneEmptyGroupAndWallet).call(this, state, walletId, groupId);
|
|
800
789
|
}
|
|
801
790
|
}
|
|
791
|
+
});
|
|
792
|
+
this.messagingSystem.publish(`${exports.controllerName}:accountTreeChange`, this.state.accountTree);
|
|
793
|
+
// Emit selectedAccountGroupChange event if the selected group changed
|
|
794
|
+
if (selectedAccountGroupChanged) {
|
|
795
|
+
this.messagingSystem.publish(`${exports.controllerName}:selectedAccountGroupChange`, this.state.accountTree.selectedAccountGroup, previousSelectedAccountGroup);
|
|
802
796
|
}
|
|
803
797
|
// Clear reverse-mapping for that account.
|
|
804
798
|
__classPrivateFieldGet(this, _AccountTreeController_accountIdToContext, "f").delete(accountId);
|
|
@@ -815,25 +809,9 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
|
|
|
815
809
|
delete state.accountWalletsMetadata[walletId];
|
|
816
810
|
}
|
|
817
811
|
return state;
|
|
818
|
-
},
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
* and return attribution vary across engines; final ordering is covered
|
|
822
|
-
* by behavior tests. Ignoring the entire comparator avoids flaky line
|
|
823
|
-
* coverage without reducing scenario coverage.
|
|
824
|
-
*/
|
|
825
|
-
(a, b) => {
|
|
826
|
-
const aSortOrder = __classPrivateFieldGet(this, _AccountTreeController_accountIdToContext, "f").get(a)?.sortOrder;
|
|
827
|
-
const bSortOrder = __classPrivateFieldGet(this, _AccountTreeController_accountIdToContext, "f").get(b)?.sortOrder;
|
|
828
|
-
return (aSortOrder ?? group_1.MAX_SORT_ORDER) - (bSortOrder ?? group_1.MAX_SORT_ORDER);
|
|
829
|
-
});
|
|
830
|
-
}, _AccountTreeController_insertAccount = function _AccountTreeController_insertAccount(wallets, account) {
|
|
831
|
-
if ((0, account_api_1.isBip44Account)(account)) {
|
|
832
|
-
// We're skipping BIP-44 accounts since we rely on the `MultichainAccountService` to do
|
|
833
|
-
// the grouping of wallets/groups directly.
|
|
834
|
-
return;
|
|
835
|
-
}
|
|
836
|
-
const result = __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_getSnapRule).call(this).match(account) ??
|
|
812
|
+
}, _AccountTreeController_insert = function _AccountTreeController_insert(wallets, account) {
|
|
813
|
+
const result = __classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_getEntropyRule).call(this).match(account) ??
|
|
814
|
+
__classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_getSnapRule).call(this).match(account) ??
|
|
837
815
|
__classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_getKeyringRule).call(this).match(account); // This one cannot fail.
|
|
838
816
|
// Update controller's state.
|
|
839
817
|
const walletId = result.wallet.id;
|
|
@@ -852,6 +830,10 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
|
|
|
852
830
|
// the union tag `result.wallet.type`.
|
|
853
831
|
};
|
|
854
832
|
wallet = wallets[walletId];
|
|
833
|
+
// Trigger atomic sync for new wallet (only for entropy wallets)
|
|
834
|
+
if (wallet.type === account_api_1.AccountWalletType.Entropy) {
|
|
835
|
+
__classPrivateFieldGet(this, _AccountTreeController_backupAndSyncService, "f").enqueueSingleWalletSync(walletId);
|
|
836
|
+
}
|
|
855
837
|
}
|
|
856
838
|
const groupId = result.group.id;
|
|
857
839
|
let group = wallet.groups[groupId];
|
|
@@ -874,9 +856,28 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
|
|
|
874
856
|
group = wallet.groups[groupId];
|
|
875
857
|
// Map group ID to its containing wallet ID for efficient direct access
|
|
876
858
|
__classPrivateFieldGet(this, _AccountTreeController_groupIdToWalletId, "f").set(groupId, walletId);
|
|
859
|
+
// Trigger atomic sync for new group (only for entropy wallets)
|
|
860
|
+
if (wallet.type === account_api_1.AccountWalletType.Entropy) {
|
|
861
|
+
__classPrivateFieldGet(this, _AccountTreeController_backupAndSyncService, "f").enqueueSingleGroupSync(groupId);
|
|
862
|
+
}
|
|
877
863
|
}
|
|
878
864
|
else {
|
|
879
865
|
group.accounts.push(id);
|
|
866
|
+
// We need to do this at every insertion because race conditions can happen
|
|
867
|
+
// during the account creation process where one provider completes before the other.
|
|
868
|
+
// The discovery process in the service can also lead to some accounts being created "out of order".
|
|
869
|
+
const { accounts } = group;
|
|
870
|
+
accounts.sort(
|
|
871
|
+
/* istanbul ignore next: Comparator branch execution (a===id vs b===id)
|
|
872
|
+
* and return attribution vary across engines; final ordering is covered
|
|
873
|
+
* by behavior tests. Ignoring the entire comparator avoids flaky line
|
|
874
|
+
* coverage without reducing scenario coverage.
|
|
875
|
+
*/
|
|
876
|
+
(a, b) => {
|
|
877
|
+
const aSortOrder = a === id ? sortOrder : __classPrivateFieldGet(this, _AccountTreeController_accountIdToContext, "f").get(a)?.sortOrder;
|
|
878
|
+
const bSortOrder = b === id ? sortOrder : __classPrivateFieldGet(this, _AccountTreeController_accountIdToContext, "f").get(b)?.sortOrder;
|
|
879
|
+
return ((aSortOrder ?? group_1.MAX_SORT_ORDER) - (bSortOrder ?? group_1.MAX_SORT_ORDER));
|
|
880
|
+
});
|
|
880
881
|
}
|
|
881
882
|
(0, logger_1.projectLogger)(`[${groupId}] Add new account: { id: "${account.id}", type: "${account.type}", address: "${account.address}"`);
|
|
882
883
|
// Update the reverse mapping for this account.
|
|
@@ -885,88 +886,6 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
|
|
|
885
886
|
groupId: group.id,
|
|
886
887
|
sortOrder,
|
|
887
888
|
});
|
|
888
|
-
// We need to do this at every insertion because race conditions can happen
|
|
889
|
-
// during the account creation process where one provider completes before the other.
|
|
890
|
-
// The discovery process in the service can also lead to some accounts being created "out of order".
|
|
891
|
-
__classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_sortAccountsOfGroup).call(this, group);
|
|
892
|
-
}, _AccountTreeController_insertOrUpdateMultichainAccountWalletAndGroup = function _AccountTreeController_insertOrUpdateMultichainAccountWalletAndGroup(wallets, multichainAccountWallet, multichainAccountGroup) {
|
|
893
|
-
const walletId = multichainAccountWallet.id;
|
|
894
|
-
const groupId = multichainAccountGroup.id;
|
|
895
|
-
let wallet = null;
|
|
896
|
-
let group = null;
|
|
897
|
-
// Check type, mainly to infer proper wallet object type.
|
|
898
|
-
const walletObject = wallets[walletId];
|
|
899
|
-
if (walletObject && walletObject.type === account_api_1.AccountWalletType.Entropy) {
|
|
900
|
-
wallet = walletObject;
|
|
901
|
-
group = wallet.groups[groupId];
|
|
902
|
-
}
|
|
903
|
-
// We always re-use the account list from the group (if accounts get
|
|
904
|
-
// added/removed/re-ordered within the group).
|
|
905
|
-
const accounts = multichainAccountGroup.getAccounts();
|
|
906
|
-
const accountIds = accounts
|
|
907
|
-
// For now, we need this type-cast because `getAccounts` do not have the same
|
|
908
|
-
// type-constraint (uses string[] instead of [string; ...string])
|
|
909
|
-
.map((account) => account.id);
|
|
910
|
-
// Create the group object first, to inject it in the wallet in case this wallet is
|
|
911
|
-
// not part of the tree yet.
|
|
912
|
-
if (!group) {
|
|
913
|
-
group = {
|
|
914
|
-
id: multichainAccountGroup.id,
|
|
915
|
-
type: multichainAccountGroup.type,
|
|
916
|
-
accounts: accountIds,
|
|
917
|
-
metadata: {
|
|
918
|
-
entropy: {
|
|
919
|
-
groupIndex: multichainAccountGroup.groupIndex,
|
|
920
|
-
},
|
|
921
|
-
name: '',
|
|
922
|
-
pinned: false,
|
|
923
|
-
hidden: false,
|
|
924
|
-
},
|
|
925
|
-
};
|
|
926
|
-
}
|
|
927
|
-
else {
|
|
928
|
-
group.accounts = accountIds;
|
|
929
|
-
}
|
|
930
|
-
if (!wallet) {
|
|
931
|
-
wallet = {
|
|
932
|
-
id: multichainAccountWallet.id,
|
|
933
|
-
type: multichainAccountWallet.type,
|
|
934
|
-
status: multichainAccountWallet.status,
|
|
935
|
-
groups: {
|
|
936
|
-
[group.id]: group,
|
|
937
|
-
},
|
|
938
|
-
metadata: {
|
|
939
|
-
entropy: {
|
|
940
|
-
id: multichainAccountWallet.entropySource,
|
|
941
|
-
},
|
|
942
|
-
name: '', // Will get updated later.
|
|
943
|
-
},
|
|
944
|
-
};
|
|
945
|
-
wallets[walletId] = wallet;
|
|
946
|
-
// Trigger atomic sync for new wallet.
|
|
947
|
-
__classPrivateFieldGet(this, _AccountTreeController_backupAndSyncService, "f").enqueueSingleWalletSync(walletId);
|
|
948
|
-
}
|
|
949
|
-
else {
|
|
950
|
-
wallet.groups[group.id] = group;
|
|
951
|
-
// Trigger atomic sync for new group.
|
|
952
|
-
__classPrivateFieldGet(this, _AccountTreeController_backupAndSyncService, "f").enqueueSingleGroupSync(groupId);
|
|
953
|
-
}
|
|
954
|
-
// Map group ID to its containing wallet ID for efficient direct access
|
|
955
|
-
__classPrivateFieldGet(this, _AccountTreeController_groupIdToWalletId, "f").set(groupId, walletId);
|
|
956
|
-
// Update the reverse mapping for all accounts account.
|
|
957
|
-
for (const account of accounts) {
|
|
958
|
-
__classPrivateFieldGet(this, _AccountTreeController_accountIdToContext, "f").set(account.id, {
|
|
959
|
-
walletId: wallet.id,
|
|
960
|
-
groupId: group.id,
|
|
961
|
-
sortOrder: group_1.ACCOUNT_TYPE_TO_SORT_ORDER[account.type] ?? group_1.MAX_SORT_ORDER,
|
|
962
|
-
});
|
|
963
|
-
}
|
|
964
|
-
// We need to do this at every insertion because race conditions can happen
|
|
965
|
-
// during the account creation process where one provider completes before the other.
|
|
966
|
-
// The discovery process in the service can also lead to some accounts being created "out of order".
|
|
967
|
-
__classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_sortAccountsOfGroup).call(this, group);
|
|
968
|
-
}, _AccountTreeController_getMultichainAccountWallets = function _AccountTreeController_getMultichainAccountWallets() {
|
|
969
|
-
return this.messagingSystem.call('MultichainAccountService:getMultichainAccountWallets');
|
|
970
889
|
}, _AccountTreeController_listAccounts = function _AccountTreeController_listAccounts() {
|
|
971
890
|
return this.messagingSystem.call('AccountsController:listMultichainAccounts');
|
|
972
891
|
}, _AccountTreeController_assertAccountGroupExists = function _AccountTreeController_assertAccountGroupExists(groupId) {
|
|
@@ -1011,19 +930,6 @@ _AccountTreeController_accountIdToContext = new WeakMap(), _AccountTreeControlle
|
|
|
1011
930
|
state.accountTree.selectedAccountGroup = groupId;
|
|
1012
931
|
});
|
|
1013
932
|
this.messagingSystem.publish(`${exports.controllerName}:selectedAccountGroupChange`, groupId, previousSelectedAccountGroup);
|
|
1014
|
-
}, _AccountTreeController_handleMultichainAccountGroupCreatedOrUpdated = function _AccountTreeController_handleMultichainAccountGroupCreatedOrUpdated(multichainAccountGroup) {
|
|
1015
|
-
this.update((state) => {
|
|
1016
|
-
__classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_insertOrUpdateMultichainAccountWalletAndGroup).call(this, state.accountTree.wallets, multichainAccountGroup.wallet, multichainAccountGroup);
|
|
1017
|
-
const wallet = state.accountTree.wallets[multichainAccountGroup.wallet.id];
|
|
1018
|
-
if (wallet) {
|
|
1019
|
-
__classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_applyAccountWalletMetadata).call(this, state, wallet.id);
|
|
1020
|
-
const group = wallet.groups[multichainAccountGroup.id];
|
|
1021
|
-
if (group) {
|
|
1022
|
-
__classPrivateFieldGet(this, _AccountTreeController_instances, "m", _AccountTreeController_applyAccountGroupMetadata).call(this, state, wallet.id, group.id);
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
});
|
|
1026
|
-
this.messagingSystem.publish(`${exports.controllerName}:accountTreeChange`, this.state.accountTree);
|
|
1027
933
|
}, _AccountTreeController_handleMultichainAccountWalletStatusChange = function _AccountTreeController_handleMultichainAccountWalletStatusChange(walletId, walletStatus) {
|
|
1028
934
|
this.update((state) => {
|
|
1029
935
|
const wallet = state.accountTree.wallets[walletId];
|