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