@metamask/accounts-controller 36.0.1 → 37.0.0
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 +24 -1
- package/dist/AccountsController-method-action-types.cjs +7 -0
- package/dist/AccountsController-method-action-types.cjs.map +1 -0
- package/dist/AccountsController-method-action-types.d.cts +167 -0
- package/dist/AccountsController-method-action-types.d.cts.map +1 -0
- package/dist/AccountsController-method-action-types.d.mts +167 -0
- package/dist/AccountsController-method-action-types.d.mts.map +1 -0
- package/dist/AccountsController-method-action-types.mjs +6 -0
- package/dist/AccountsController-method-action-types.mjs.map +1 -0
- package/dist/AccountsController.cjs +96 -37
- package/dist/AccountsController.cjs.map +1 -1
- package/dist/AccountsController.d.cts +103 -57
- package/dist/AccountsController.d.cts.map +1 -1
- package/dist/AccountsController.d.mts +103 -57
- package/dist/AccountsController.d.mts.map +1 -1
- package/dist/AccountsController.mjs +97 -38
- package/dist/AccountsController.mjs.map +1 -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.map +1 -1
- package/dist/logger.cjs +8 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +5 -0
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.mts +5 -0
- package/dist/logger.d.mts.map +1 -0
- package/dist/logger.mjs +5 -0
- package/dist/logger.mjs.map +1 -0
- package/dist/typing.cjs.map +1 -1
- package/dist/typing.d.cts +1 -0
- package/dist/typing.d.cts.map +1 -1
- package/dist/typing.d.mts +1 -0
- package/dist/typing.d.mts.map +1 -1
- package/dist/typing.mjs.map +1 -1
- package/dist/utils.cjs +9 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +2 -0
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +2 -0
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +7 -0
- package/dist/utils.mjs.map +1 -1
- package/package.json +3 -2
- package/dist/tests/mocks.cjs +0 -89
- package/dist/tests/mocks.cjs.map +0 -1
- package/dist/tests/mocks.d.cts +0 -26
- package/dist/tests/mocks.d.cts.map +0 -1
- package/dist/tests/mocks.d.mts +0 -26
- package/dist/tests/mocks.d.mts.map +0 -1
- package/dist/tests/mocks.mjs +0 -83
- package/dist/tests/mocks.mjs.map +0 -1
|
@@ -4,7 +4,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
4
4
|
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");
|
|
5
5
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
6
|
};
|
|
7
|
-
var _AccountsController_instances, _AccountsController_assertAccountCanBeRenamed, _AccountsController_getInternalAccountForNonSnapAccount, _AccountsController_getSnapKeyring, _AccountsController_handleOnSnapKeyringAccountEvent, _AccountsController_handleOnKeyringStateChange, _AccountsController_update, _AccountsController_handleOnSnapStateChange, _AccountsController_getLastSelectedAccount, _AccountsController_getLastSelectedIndex, _AccountsController_getInternalAccountFromAddressAndType, _AccountsController_handleOnMultichainNetworkDidChange, _AccountsController_subscribeToMessageEvents
|
|
7
|
+
var _AccountsController_instances, _AccountsController_getAccountExpect, _AccountsController_assertAccountCanBeRenamed, _AccountsController_getInternalAccountForNonSnapAccount, _AccountsController_getSnapKeyring, _AccountsController_handleOnSnapKeyringAccountEvent, _AccountsController_handleOnKeyringStateChange, _AccountsController_update, _AccountsController_handleOnSnapStateChange, _AccountsController_getLastSelectedAccount, _AccountsController_getLastSelectedIndex, _AccountsController_getInternalAccountFromAddressAndType, _AccountsController_handleOnMultichainNetworkDidChange, _AccountsController_subscribeToMessageEvents;
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.AccountsController = exports.EMPTY_ACCOUNT = void 0;
|
|
10
10
|
const base_controller_1 = require("@metamask/base-controller");
|
|
@@ -13,8 +13,24 @@ const keyring_api_1 = require("@metamask/keyring-api");
|
|
|
13
13
|
const keyring_utils_1 = require("@metamask/keyring-utils");
|
|
14
14
|
const utils_1 = require("@metamask/utils");
|
|
15
15
|
const lodash_1 = require("lodash");
|
|
16
|
+
const logger_1 = require("./logger.cjs");
|
|
16
17
|
const utils_2 = require("./utils.cjs");
|
|
17
18
|
const controllerName = 'AccountsController';
|
|
19
|
+
const MESSENGER_EXPOSED_METHODS = [
|
|
20
|
+
'setSelectedAccount',
|
|
21
|
+
'setAccountName',
|
|
22
|
+
'setAccountNameAndSelectAccount',
|
|
23
|
+
'listAccounts',
|
|
24
|
+
'listMultichainAccounts',
|
|
25
|
+
'updateAccounts',
|
|
26
|
+
'getSelectedAccount',
|
|
27
|
+
'getSelectedMultichainAccount',
|
|
28
|
+
'getAccountByAddress',
|
|
29
|
+
'getAccount',
|
|
30
|
+
'getAccounts',
|
|
31
|
+
'updateAccountMetadata',
|
|
32
|
+
'loadBackup',
|
|
33
|
+
];
|
|
18
34
|
const accountsControllerMetadata = {
|
|
19
35
|
internalAccounts: {
|
|
20
36
|
includeInStateLogs: true,
|
|
@@ -22,13 +38,24 @@ const accountsControllerMetadata = {
|
|
|
22
38
|
includeInDebugSnapshot: false,
|
|
23
39
|
usedInUi: true,
|
|
24
40
|
},
|
|
41
|
+
accountIdByAddress: {
|
|
42
|
+
includeInStateLogs: false,
|
|
43
|
+
persist: false,
|
|
44
|
+
includeInDebugSnapshot: false,
|
|
45
|
+
usedInUi: true,
|
|
46
|
+
},
|
|
25
47
|
};
|
|
26
48
|
const defaultState = {
|
|
27
49
|
internalAccounts: {
|
|
28
50
|
accounts: {},
|
|
29
51
|
selectedAccount: '',
|
|
30
52
|
},
|
|
53
|
+
accountIdByAddress: {},
|
|
31
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* @deprecated This constant is deprecated and will be removed in a future version.
|
|
57
|
+
* Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.
|
|
58
|
+
*/
|
|
32
59
|
exports.EMPTY_ACCOUNT = {
|
|
33
60
|
id: '',
|
|
34
61
|
address: '',
|
|
@@ -51,6 +78,8 @@ exports.EMPTY_ACCOUNT = {
|
|
|
51
78
|
* The accounts controller also listens for keyring state changes and updates the internal accounts accordingly.
|
|
52
79
|
* The accounts controller also listens for snap state changes and updates the internal accounts accordingly.
|
|
53
80
|
*
|
|
81
|
+
* @deprecated This class is deprecated and will be removed in a future version.
|
|
82
|
+
* Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.
|
|
54
83
|
*/
|
|
55
84
|
class AccountsController extends base_controller_1.BaseController {
|
|
56
85
|
/**
|
|
@@ -61,6 +90,7 @@ class AccountsController extends base_controller_1.BaseController {
|
|
|
61
90
|
* @param options.state - Initial state to set on this controller
|
|
62
91
|
*/
|
|
63
92
|
constructor({ messenger, state, }) {
|
|
93
|
+
const accountIdByAddress = (0, utils_2.constructAccountIdByAddress)(state?.internalAccounts?.accounts ?? {});
|
|
64
94
|
super({
|
|
65
95
|
messenger,
|
|
66
96
|
name: controllerName,
|
|
@@ -68,15 +98,18 @@ class AccountsController extends base_controller_1.BaseController {
|
|
|
68
98
|
state: {
|
|
69
99
|
...defaultState,
|
|
70
100
|
...state,
|
|
101
|
+
accountIdByAddress,
|
|
71
102
|
},
|
|
72
103
|
});
|
|
73
104
|
_AccountsController_instances.add(this);
|
|
105
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
74
106
|
__classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_subscribeToMessageEvents).call(this);
|
|
75
|
-
__classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_registerMessageHandlers).call(this);
|
|
76
107
|
}
|
|
77
108
|
/**
|
|
78
109
|
* Returns the internal account object for the given account ID, if it exists.
|
|
79
110
|
*
|
|
111
|
+
* @deprecated This method is deprecated and will be removed in a future version.
|
|
112
|
+
* Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.
|
|
80
113
|
* @param accountId - The ID of the account to retrieve.
|
|
81
114
|
* @returns The internal account object, or undefined if the account does not exist.
|
|
82
115
|
*/
|
|
@@ -86,6 +119,8 @@ class AccountsController extends base_controller_1.BaseController {
|
|
|
86
119
|
/**
|
|
87
120
|
* Returns the internal account objects for the given account IDs, if they exist.
|
|
88
121
|
*
|
|
122
|
+
* @deprecated This method is deprecated and will be removed in a future version.
|
|
123
|
+
* Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.
|
|
89
124
|
* @param accountIds - The IDs of the accounts to retrieve.
|
|
90
125
|
* @returns The internal account objects, or undefined if the account(s) do not exist.
|
|
91
126
|
*/
|
|
@@ -95,6 +130,8 @@ class AccountsController extends base_controller_1.BaseController {
|
|
|
95
130
|
/**
|
|
96
131
|
* Returns an array of all evm internal accounts.
|
|
97
132
|
*
|
|
133
|
+
* @deprecated This method is deprecated and will be removed in a future version.
|
|
134
|
+
* Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.
|
|
98
135
|
* @returns An array of InternalAccount objects.
|
|
99
136
|
*/
|
|
100
137
|
listAccounts() {
|
|
@@ -104,6 +141,8 @@ class AccountsController extends base_controller_1.BaseController {
|
|
|
104
141
|
/**
|
|
105
142
|
* Returns an array of all internal accounts.
|
|
106
143
|
*
|
|
144
|
+
* @deprecated This method is deprecated and will be removed in a future version.
|
|
145
|
+
* Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.
|
|
107
146
|
* @param chainId - The chain ID.
|
|
108
147
|
* @returns An array of InternalAccount objects.
|
|
109
148
|
*/
|
|
@@ -117,23 +156,11 @@ class AccountsController extends base_controller_1.BaseController {
|
|
|
117
156
|
}
|
|
118
157
|
return accounts.filter((account) => (0, keyring_utils_1.isScopeEqualToAny)(chainId, account.scopes));
|
|
119
158
|
}
|
|
120
|
-
/**
|
|
121
|
-
* Returns the internal account object for the given account ID.
|
|
122
|
-
*
|
|
123
|
-
* @param accountId - The ID of the account to retrieve.
|
|
124
|
-
* @returns The internal account object.
|
|
125
|
-
* @throws An error if the account ID is not found.
|
|
126
|
-
*/
|
|
127
|
-
getAccountExpect(accountId) {
|
|
128
|
-
const account = this.getAccount(accountId);
|
|
129
|
-
if (account === undefined) {
|
|
130
|
-
throw new Error(`Account Id "${accountId}" not found`);
|
|
131
|
-
}
|
|
132
|
-
return account;
|
|
133
|
-
}
|
|
134
159
|
/**
|
|
135
160
|
* Returns the last selected EVM account.
|
|
136
161
|
*
|
|
162
|
+
* @deprecated This method is deprecated and will be removed in a future version.
|
|
163
|
+
* Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.
|
|
137
164
|
* @returns The selected internal account.
|
|
138
165
|
*/
|
|
139
166
|
getSelectedAccount() {
|
|
@@ -143,7 +170,7 @@ class AccountsController extends base_controller_1.BaseController {
|
|
|
143
170
|
if (selectedAccount === '') {
|
|
144
171
|
return exports.EMPTY_ACCOUNT;
|
|
145
172
|
}
|
|
146
|
-
const account = this.
|
|
173
|
+
const account = __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_getAccountExpect).call(this, selectedAccount);
|
|
147
174
|
if ((0, keyring_api_1.isEvmAccountType)(account.type)) {
|
|
148
175
|
return account;
|
|
149
176
|
}
|
|
@@ -161,6 +188,8 @@ class AccountsController extends base_controller_1.BaseController {
|
|
|
161
188
|
*
|
|
162
189
|
* Retrieves the last selected account by chain ID.
|
|
163
190
|
*
|
|
191
|
+
* @deprecated This method is deprecated and will be removed in a future version.
|
|
192
|
+
* Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.
|
|
164
193
|
* @param chainId - The chain ID to filter the accounts.
|
|
165
194
|
* @returns The last selected account compatible with the specified chain ID or undefined.
|
|
166
195
|
*/
|
|
@@ -172,7 +201,7 @@ class AccountsController extends base_controller_1.BaseController {
|
|
|
172
201
|
return exports.EMPTY_ACCOUNT;
|
|
173
202
|
}
|
|
174
203
|
if (!chainId) {
|
|
175
|
-
return this.
|
|
204
|
+
return __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_getAccountExpect).call(this, selectedAccount);
|
|
176
205
|
}
|
|
177
206
|
const accounts = this.listMultichainAccounts(chainId);
|
|
178
207
|
return __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_getLastSelectedAccount).call(this, accounts);
|
|
@@ -181,19 +210,37 @@ class AccountsController extends base_controller_1.BaseController {
|
|
|
181
210
|
* Returns the account with the specified address.
|
|
182
211
|
* ! This method will only return the first account that matches the address
|
|
183
212
|
*
|
|
213
|
+
* @deprecated This method is deprecated and will be removed in a future version.
|
|
214
|
+
* Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.
|
|
184
215
|
* @param address - The address of the account to retrieve.
|
|
185
216
|
* @returns The account with the specified address, or undefined if not found.
|
|
186
217
|
*/
|
|
187
218
|
getAccountByAddress(address) {
|
|
188
|
-
|
|
219
|
+
// We need to have a fallback as a cache miss might be attributed to a checksummed address being passed.
|
|
220
|
+
let accountId = this.state.accountIdByAddress[address];
|
|
221
|
+
if (!accountId) {
|
|
222
|
+
// FIXME: We should not need lower-cased addresses, but some consumers might
|
|
223
|
+
// still be using non-normalized addresses. For now we keep it
|
|
224
|
+
// for convenience, but we will need to remove this fallback
|
|
225
|
+
// at some point.
|
|
226
|
+
// NOTE: We should only hit that branch for EVM accounts only.
|
|
227
|
+
const lowercasedAddress = address.toLowerCase();
|
|
228
|
+
accountId = this.state.accountIdByAddress[lowercasedAddress];
|
|
229
|
+
if (accountId) {
|
|
230
|
+
(0, logger_1.projectLogger)(`Cache missed for account ID: ${accountId}, received address: "${address}", matched address: "${lowercasedAddress}"`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return accountId ? this.getAccount(accountId) : undefined;
|
|
189
234
|
}
|
|
190
235
|
/**
|
|
191
236
|
* Sets the selected account by its ID.
|
|
192
237
|
*
|
|
238
|
+
* @deprecated This method is deprecated and will be removed in a future version.
|
|
239
|
+
* Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.
|
|
193
240
|
* @param accountId - The ID of the account to be selected.
|
|
194
241
|
*/
|
|
195
242
|
setSelectedAccount(accountId) {
|
|
196
|
-
const account = this.
|
|
243
|
+
const account = __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_getAccountExpect).call(this, accountId);
|
|
197
244
|
if (this.state.internalAccounts.selectedAccount === account.id) {
|
|
198
245
|
return;
|
|
199
246
|
}
|
|
@@ -206,6 +253,8 @@ class AccountsController extends base_controller_1.BaseController {
|
|
|
206
253
|
/**
|
|
207
254
|
* Sets the name of the account with the given ID.
|
|
208
255
|
*
|
|
256
|
+
* @deprecated This method is deprecated and will be removed in a future version.
|
|
257
|
+
* Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.
|
|
209
258
|
* @param accountId - The ID of the account to set the name for.
|
|
210
259
|
* @param accountName - The new name for the account.
|
|
211
260
|
* @throws An error if an account with the same name already exists.
|
|
@@ -221,12 +270,14 @@ class AccountsController extends base_controller_1.BaseController {
|
|
|
221
270
|
/**
|
|
222
271
|
* Sets the name of the account with the given ID and select it.
|
|
223
272
|
*
|
|
273
|
+
* @deprecated This method is deprecated and will be removed in a future version.
|
|
274
|
+
* Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.
|
|
224
275
|
* @param accountId - The ID of the account to set the name for and select.
|
|
225
276
|
* @param accountName - The new name for the account.
|
|
226
277
|
* @throws An error if an account with the same name already exists.
|
|
227
278
|
*/
|
|
228
279
|
setAccountNameAndSelectAccount(accountId, accountName) {
|
|
229
|
-
const account = this.
|
|
280
|
+
const account = __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_getAccountExpect).call(this, accountId);
|
|
230
281
|
__classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_assertAccountCanBeRenamed).call(this, account, accountName);
|
|
231
282
|
const internalAccount = {
|
|
232
283
|
...account,
|
|
@@ -246,11 +297,13 @@ class AccountsController extends base_controller_1.BaseController {
|
|
|
246
297
|
/**
|
|
247
298
|
* Updates the metadata of the account with the given ID.
|
|
248
299
|
*
|
|
300
|
+
* @deprecated This method is deprecated and will be removed in a future version.
|
|
301
|
+
* Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.
|
|
249
302
|
* @param accountId - The ID of the account for which the metadata will be updated.
|
|
250
303
|
* @param metadata - The new metadata for the account.
|
|
251
304
|
*/
|
|
252
305
|
updateAccountMetadata(accountId, metadata) {
|
|
253
|
-
const account = this.
|
|
306
|
+
const account = __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_getAccountExpect).call(this, accountId);
|
|
254
307
|
if (metadata.name) {
|
|
255
308
|
__classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_assertAccountCanBeRenamed).call(this, account, metadata.name);
|
|
256
309
|
}
|
|
@@ -269,9 +322,12 @@ class AccountsController extends base_controller_1.BaseController {
|
|
|
269
322
|
* Updates the internal accounts list by retrieving normal and snap accounts,
|
|
270
323
|
* removing duplicates, and updating the metadata of each account.
|
|
271
324
|
*
|
|
325
|
+
* @deprecated This method is deprecated and will be removed in a future version.
|
|
326
|
+
* Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.
|
|
272
327
|
* @returns A Promise that resolves when the accounts have been updated.
|
|
273
328
|
*/
|
|
274
329
|
async updateAccounts() {
|
|
330
|
+
(0, logger_1.projectLogger)('Synchronizing accounts with keyrings...');
|
|
275
331
|
const keyringAccountIndexes = new Map();
|
|
276
332
|
const existingInternalAccounts = this.state.internalAccounts.accounts;
|
|
277
333
|
const internalAccounts = {};
|
|
@@ -307,23 +363,35 @@ class AccountsController extends base_controller_1.BaseController {
|
|
|
307
363
|
}
|
|
308
364
|
__classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_update).call(this, (state) => {
|
|
309
365
|
state.internalAccounts.accounts = internalAccounts;
|
|
366
|
+
state.accountIdByAddress = (0, utils_2.constructAccountIdByAddress)(internalAccounts);
|
|
310
367
|
});
|
|
368
|
+
(0, logger_1.projectLogger)('Accounts synchronized!');
|
|
311
369
|
}
|
|
312
370
|
/**
|
|
313
371
|
* Loads the backup state of the accounts controller.
|
|
314
372
|
*
|
|
373
|
+
* @deprecated This method is deprecated and will be removed in a future version.
|
|
374
|
+
* Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.
|
|
315
375
|
* @param backup - The backup state to load.
|
|
316
376
|
*/
|
|
317
377
|
loadBackup(backup) {
|
|
318
378
|
if (backup.internalAccounts) {
|
|
379
|
+
const accountIdByAddress = (0, utils_2.constructAccountIdByAddress)(backup.internalAccounts.accounts);
|
|
319
380
|
this.update((currentState) => {
|
|
320
381
|
currentState.internalAccounts = backup.internalAccounts;
|
|
382
|
+
currentState.accountIdByAddress = accountIdByAddress;
|
|
321
383
|
});
|
|
322
384
|
}
|
|
323
385
|
}
|
|
324
386
|
}
|
|
325
387
|
exports.AccountsController = AccountsController;
|
|
326
|
-
_AccountsController_instances = new WeakSet(),
|
|
388
|
+
_AccountsController_instances = new WeakSet(), _AccountsController_getAccountExpect = function _AccountsController_getAccountExpect(accountId) {
|
|
389
|
+
const account = this.getAccount(accountId);
|
|
390
|
+
if (account === undefined) {
|
|
391
|
+
throw new Error(`Account Id "${accountId}" not found`);
|
|
392
|
+
}
|
|
393
|
+
return account;
|
|
394
|
+
}, _AccountsController_assertAccountCanBeRenamed = function _AccountsController_assertAccountCanBeRenamed(account, accountName) {
|
|
327
395
|
if (this.listMultichainAccounts().find((internalAccount) => internalAccount.metadata.name === accountName &&
|
|
328
396
|
internalAccount.id !== account.id)) {
|
|
329
397
|
throw new Error('Account name already exists');
|
|
@@ -412,6 +480,7 @@ _AccountsController_instances = new WeakSet(), _AccountsController_assertAccount
|
|
|
412
480
|
if (!isUnlocked || keyrings.length === 0) {
|
|
413
481
|
return;
|
|
414
482
|
}
|
|
483
|
+
(0, logger_1.projectLogger)('Synchronizing accounts with keyrings (through :stateChange)...');
|
|
415
484
|
// State patches.
|
|
416
485
|
const generatePatch = () => {
|
|
417
486
|
return {
|
|
@@ -478,10 +547,11 @@ _AccountsController_instances = new WeakSet(), _AccountsController_assertAccount
|
|
|
478
547
|
added: [],
|
|
479
548
|
};
|
|
480
549
|
__classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_update).call(this, (state) => {
|
|
481
|
-
const { internalAccounts } = state;
|
|
550
|
+
const { internalAccounts, accountIdByAddress } = state;
|
|
482
551
|
for (const patch of [patches.snap, patches.normal]) {
|
|
483
552
|
for (const account of patch.removed) {
|
|
484
553
|
delete internalAccounts.accounts[account.id];
|
|
554
|
+
delete accountIdByAddress[account.address];
|
|
485
555
|
diff.removed.push(account.id);
|
|
486
556
|
}
|
|
487
557
|
for (const added of patch.added) {
|
|
@@ -498,6 +568,7 @@ _AccountsController_instances = new WeakSet(), _AccountsController_assertAccount
|
|
|
498
568
|
lastSelected,
|
|
499
569
|
},
|
|
500
570
|
};
|
|
571
|
+
accountIdByAddress[account.address] = account.id;
|
|
501
572
|
diff.added.push(internalAccounts.accounts[account.id]);
|
|
502
573
|
}
|
|
503
574
|
}
|
|
@@ -514,6 +585,7 @@ _AccountsController_instances = new WeakSet(), _AccountsController_assertAccount
|
|
|
514
585
|
this.messenger.publish('AccountsController:accountAdded', account);
|
|
515
586
|
}
|
|
516
587
|
});
|
|
588
|
+
(0, logger_1.projectLogger)('Accounts synchronized (through :stateChange)!');
|
|
517
589
|
// NOTE: Since we also track "updated" accounts with our patches, we could fire a new event
|
|
518
590
|
// like `accountUpdated` (we would still need to check if anything really changed on the account).
|
|
519
591
|
}, _AccountsController_update = function _AccountsController_update(callback, beforeAutoSelectAccount) {
|
|
@@ -660,18 +732,5 @@ _AccountsController_instances = new WeakSet(), _AccountsController_assertAccount
|
|
|
660
732
|
this.messenger.subscribe('SnapKeyring:accountTransactionsUpdated', (snapAccountEvent) => __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_handleOnSnapKeyringAccountEvent).call(this, 'AccountsController:accountTransactionsUpdated', snapAccountEvent));
|
|
661
733
|
// Handle account change when multichain network is changed
|
|
662
734
|
this.messenger.subscribe('MultichainNetworkController:networkDidChange', (id) => __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_handleOnMultichainNetworkDidChange).call(this, id));
|
|
663
|
-
}, _AccountsController_registerMessageHandlers = function _AccountsController_registerMessageHandlers() {
|
|
664
|
-
this.messenger.registerActionHandler(`${controllerName}:setSelectedAccount`, this.setSelectedAccount.bind(this));
|
|
665
|
-
this.messenger.registerActionHandler(`${controllerName}:listAccounts`, this.listAccounts.bind(this));
|
|
666
|
-
this.messenger.registerActionHandler(`${controllerName}:listMultichainAccounts`, this.listMultichainAccounts.bind(this));
|
|
667
|
-
this.messenger.registerActionHandler(`${controllerName}:setAccountName`, this.setAccountName.bind(this));
|
|
668
|
-
this.messenger.registerActionHandler(`${controllerName}:setAccountNameAndSelectAccount`, this.setAccountNameAndSelectAccount.bind(this));
|
|
669
|
-
this.messenger.registerActionHandler(`${controllerName}:updateAccounts`, this.updateAccounts.bind(this));
|
|
670
|
-
this.messenger.registerActionHandler(`${controllerName}:getSelectedAccount`, this.getSelectedAccount.bind(this));
|
|
671
|
-
this.messenger.registerActionHandler(`${controllerName}:getSelectedMultichainAccount`, this.getSelectedMultichainAccount.bind(this));
|
|
672
|
-
this.messenger.registerActionHandler(`${controllerName}:getAccountByAddress`, this.getAccountByAddress.bind(this));
|
|
673
|
-
this.messenger.registerActionHandler(`AccountsController:getAccount`, this.getAccount.bind(this));
|
|
674
|
-
this.messenger.registerActionHandler(`AccountsController:getAccounts`, this.getAccounts.bind(this));
|
|
675
|
-
this.messenger.registerActionHandler(`AccountsController:updateAccountMetadata`, this.updateAccountMetadata.bind(this));
|
|
676
735
|
};
|
|
677
736
|
//# sourceMappingURL=AccountsController.cjs.map
|