@metamask/accounts-controller 37.2.0 → 38.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.cjs +79 -90
- package/dist/AccountsController.cjs.map +1 -1
- package/dist/AccountsController.d.cts +1 -2
- package/dist/AccountsController.d.cts.map +1 -1
- package/dist/AccountsController.d.mts +1 -2
- package/dist/AccountsController.d.mts.map +1 -1
- package/dist/AccountsController.mjs +80 -91
- package/dist/AccountsController.mjs.map +1 -1
- package/dist/utils.cjs +16 -2
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +8 -0
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +8 -0
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +14 -1
- package/dist/utils.mjs.map +1 -1
- package/package.json +23 -25
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountsController.d.cts","sourceRoot":"","sources":["../src/AccountsController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAEnC,OAAO,KAAK,EACV,uCAAuC,EACvC,sCAAsC,EACtC,0CAA0C,EAC3C,mCAAmC;
|
|
1
|
+
{"version":3,"file":"AccountsController.d.cts","sourceRoot":"","sources":["../src/AccountsController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAEnC,OAAO,KAAK,EACV,uCAAuC,EACvC,sCAAsC,EACtC,0CAA0C,EAC3C,mCAAmC;AAGpC,OAAO,EACL,cAAc,EAEd,QAAQ,EAGT,8BAA8B;AAE/B,OAAO,KAAK,EAEV,wCAAwC,EACxC,iCAAiC,EACjC,+BAA+B,EAEhC,qCAAqC;AACtC,O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H,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAoBjE;;;;;;OAMG;IACH,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAe3C;;;;;;;;OAQG;IACH,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI;IAS5D;;;;;;;;OAQG;IACH,8BAA8B,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI;IAyC5E;;;;;;;OAOG;IACH,qBAAqB,CACnB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,OAAO,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,GAC7C,IAAI;IAwBP;;;;;;;OAOG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAkErC;;;;;;OAMG;IACH,UAAU,CAAC,MAAM,EAAE,uBAAuB,GAAG,IAAI;CAgkBlD"}
|
|
@@ -5,7 +5,6 @@ import { EthAccountType, EthScope } from "@metamask/keyring-api";
|
|
|
5
5
|
import type { KeyringControllerGetKeyringsByTypeAction, KeyringControllerStateChangeEvent, KeyringControllerGetStateAction } from "@metamask/keyring-controller";
|
|
6
6
|
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
7
7
|
import type { Messenger } from "@metamask/messenger";
|
|
8
|
-
import type { SnapControllerStateChangeEvent } from "@metamask/snaps-controllers";
|
|
9
8
|
import type { CaipChainId } from "@metamask/utils";
|
|
10
9
|
import { AccountsControllerMethodActions } from "./AccountsController-method-action-types.mjs";
|
|
11
10
|
import type { MultichainNetworkControllerNetworkDidChangeEvent } from "./types.mjs";
|
|
@@ -122,7 +121,7 @@ export type AccountsControllerAccountAssetListUpdatedEvent = {
|
|
|
122
121
|
* @deprecated This type is deprecated and will be removed in a future version.
|
|
123
122
|
* Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.
|
|
124
123
|
*/
|
|
125
|
-
export type AllowedEvents = KeyringControllerStateChangeEvent |
|
|
124
|
+
export type AllowedEvents = KeyringControllerStateChangeEvent | SnapKeyringAccountAssetListUpdatedEvent | SnapKeyringAccountBalancesUpdatedEvent | SnapKeyringAccountTransactionsUpdatedEvent | MultichainNetworkControllerNetworkDidChangeEvent;
|
|
126
125
|
/**
|
|
127
126
|
* @deprecated This type is deprecated and will be removed in a future version.
|
|
128
127
|
* Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountsController.d.mts","sourceRoot":"","sources":["../src/AccountsController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAEnC,OAAO,KAAK,EACV,uCAAuC,EACvC,sCAAsC,EACtC,0CAA0C,EAC3C,mCAAmC;
|
|
1
|
+
{"version":3,"file":"AccountsController.d.mts","sourceRoot":"","sources":["../src/AccountsController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAEnC,OAAO,KAAK,EACV,uCAAuC,EACvC,sCAAsC,EACtC,0CAA0C,EAC3C,mCAAmC;AAGpC,OAAO,EACL,cAAc,EAEd,QAAQ,EAGT,8BAA8B;AAE/B,OAAO,KAAK,EAEV,wCAAwC,EACxC,iCAAiC,EACjC,+BAA+B,EAEhC,qCAAqC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EAAE,SAAS,EAAuB,4BAA4B;AAG1E,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAwB;AAInD,OAAO,EAAE,+BAA+B,EAAE,qDAAiD;AAE3F,OAAO,KAAK,EAAE,gDAAgD,EAAE,oBAAgB;AAgBhF,QAAA,MAAM,cAAc,uBAAuB,CAAC;AAE5C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S,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI;IAyC5E;;;;;;;OAOG;IACH,qBAAqB,CACnB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,OAAO,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,GAC7C,IAAI;IAwBP;;;;;;;OAOG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAkErC;;;;;;OAMG;IACH,UAAU,CAAC,MAAM,EAAE,uBAAuB,GAAG,IAAI;CAgkBlD"}
|
|
@@ -3,16 +3,18 @@ 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_getAccountExpect, _AccountsController_assertAccountCanBeRenamed, _AccountsController_getInternalAccountForNonSnapAccount, _AccountsController_getSnapKeyring, _AccountsController_handleOnSnapKeyringAccountEvent, _AccountsController_handleOnKeyringStateChange, _AccountsController_update,
|
|
6
|
+
var _AccountsController_instances, _AccountsController_getAccountExpect, _AccountsController_assertAccountCanBeRenamed, _AccountsController_getInternalAccountForNonSnapAccount, _AccountsController_getSnapKeyring, _AccountsController_getAccountFromSnapKeyringV1, _AccountsController_getAccountFromSnapKeyringV2, _AccountsController_handleOnSnapKeyringAccountEvent, _AccountsController_handleOnKeyringStateChange, _AccountsController_update, _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
|
+
import { SnapKeyring as SnapKeyringV2 } from "@metamask/eth-snap-keyring/v2";
|
|
9
10
|
import { EthAccountType, EthMethod, EthScope, isEvmAccountType, KeyringAccountEntropyTypeOption } from "@metamask/keyring-api";
|
|
11
|
+
import { KeyringType } from "@metamask/keyring-api/v2";
|
|
10
12
|
import { isScopeEqualToAny } from "@metamask/keyring-utils";
|
|
11
13
|
import { isCaipChainId } from "@metamask/utils";
|
|
12
14
|
import $lodash from "lodash";
|
|
13
15
|
const { cloneDeep } = $lodash;
|
|
14
16
|
import { projectLogger as log } from "./logger.mjs";
|
|
15
|
-
import { constructAccountIdByAddress, getEvmDerivationPathForIndex, getEvmGroupIndexFromAddressIndex, getUUIDFromAddressOfNormalAccount, isHdKeyringType, isHdSnapKeyringAccount, isMoneyKeyringType, isSnapKeyringType, keyringTypeToName } from "./utils.mjs";
|
|
17
|
+
import { constructAccountIdByAddress, getEvmDerivationPathForIndex, getEvmGroupIndexFromAddressIndex, getUUIDFromAddressOfNormalAccount, isHdKeyringType, isHdSnapKeyringAccount, isMoneyKeyringType, isSnapKeyringType, isSnapKeyringV2Type, keyringTypeToName } from "./utils.mjs";
|
|
16
18
|
const controllerName = 'AccountsController';
|
|
17
19
|
const MESSENGER_EXPOSED_METHODS = [
|
|
18
20
|
'setSelectedAccount',
|
|
@@ -472,6 +474,43 @@ _AccountsController_instances = new WeakSet(), _AccountsController_getAccountExp
|
|
|
472
474
|
// Snap keyring is not available until the first account is created in the keyring
|
|
473
475
|
// controller, so this might be undefined.
|
|
474
476
|
return snapKeyring;
|
|
477
|
+
}, _AccountsController_getAccountFromSnapKeyringV1 = function _AccountsController_getAccountFromSnapKeyringV1(address) {
|
|
478
|
+
const snapKeyring = __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_getSnapKeyring).call(this);
|
|
479
|
+
// We need the Snap keyring to retrieve the account from its address.
|
|
480
|
+
if (!snapKeyring) {
|
|
481
|
+
return undefined;
|
|
482
|
+
}
|
|
483
|
+
// This might be undefined if the Snap deleted the account before
|
|
484
|
+
// reaching that point.
|
|
485
|
+
return snapKeyring.getAccountByAddress(address);
|
|
486
|
+
}, _AccountsController_getAccountFromSnapKeyringV2 = function _AccountsController_getAccountFromSnapKeyringV2(address) {
|
|
487
|
+
const keyrings = this.messenger.call('KeyringController:getKeyringsByType', KeyringType.Snap);
|
|
488
|
+
// Snap keyring v2 are "per-Snaps", so we need to iterate over all of them to find the account.
|
|
489
|
+
for (const keyring of keyrings) {
|
|
490
|
+
if (keyring instanceof SnapKeyringV2) {
|
|
491
|
+
// We use the synchronous method here since this method is used during `:stateChange` that are
|
|
492
|
+
// use synchronous handlers.
|
|
493
|
+
const account = keyring.lookupByAddress(address);
|
|
494
|
+
if (account) {
|
|
495
|
+
return {
|
|
496
|
+
...account,
|
|
497
|
+
// We still have to use internal account for now, so we inject some metadata.
|
|
498
|
+
metadata: {
|
|
499
|
+
name: '',
|
|
500
|
+
importTime: Date.now(),
|
|
501
|
+
lastSelected: 0,
|
|
502
|
+
keyring: {
|
|
503
|
+
type: KeyringType.Snap,
|
|
504
|
+
},
|
|
505
|
+
snap: {
|
|
506
|
+
id: keyring.snapId,
|
|
507
|
+
},
|
|
508
|
+
},
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
return undefined;
|
|
475
514
|
}, _AccountsController_handleOnSnapKeyringAccountEvent = function _AccountsController_handleOnSnapKeyringAccountEvent(event, ...payload) {
|
|
476
515
|
this.messenger.publish(event, ...payload);
|
|
477
516
|
}, _AccountsController_handleOnKeyringStateChange = function _AccountsController_handleOnKeyringStateChange({ isUnlocked, keyrings, }) {
|
|
@@ -484,30 +523,15 @@ _AccountsController_instances = new WeakSet(), _AccountsController_getAccountExp
|
|
|
484
523
|
}
|
|
485
524
|
log('Synchronizing accounts with keyrings (through :stateChange)...');
|
|
486
525
|
// State patches.
|
|
487
|
-
const
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
removed: [],
|
|
493
|
-
};
|
|
494
|
-
};
|
|
495
|
-
const patches = {
|
|
496
|
-
snap: generatePatch(),
|
|
497
|
-
normal: generatePatch(),
|
|
498
|
-
};
|
|
499
|
-
// Gets the patch object based on the keyring type (since Snap accounts and other accounts
|
|
500
|
-
// are handled differently).
|
|
501
|
-
const patchOf = (type) => {
|
|
502
|
-
if (isSnapKeyringType(type)) {
|
|
503
|
-
return patches.snap;
|
|
504
|
-
}
|
|
505
|
-
return patches.normal;
|
|
526
|
+
const patch = {
|
|
527
|
+
previous: {},
|
|
528
|
+
added: [],
|
|
529
|
+
updated: [],
|
|
530
|
+
removed: [],
|
|
506
531
|
};
|
|
507
532
|
// Create a map (with lower-cased addresses) of all existing accounts.
|
|
508
533
|
for (const account of this.listMultichainAccounts()) {
|
|
509
534
|
const address = account.address.toLowerCase();
|
|
510
|
-
const patch = patchOf(account.metadata.keyring.type);
|
|
511
535
|
patch.previous[address] = account;
|
|
512
536
|
}
|
|
513
537
|
// Go over all keyring changes and create patches out of it.
|
|
@@ -518,7 +542,6 @@ _AccountsController_instances = new WeakSet(), _AccountsController_getAccountExp
|
|
|
518
542
|
if (isMoneyKeyringType(keyring.type)) {
|
|
519
543
|
continue;
|
|
520
544
|
}
|
|
521
|
-
const patch = patchOf(keyring.type);
|
|
522
545
|
for (const accountAddress of keyring.accounts) {
|
|
523
546
|
// Lower-case address to use it in the `previous` map.
|
|
524
547
|
const address = accountAddress.toLowerCase();
|
|
@@ -540,12 +563,10 @@ _AccountsController_instances = new WeakSet(), _AccountsController_getAccountExp
|
|
|
540
563
|
}
|
|
541
564
|
// We might have accounts associated with removed keyrings, so we iterate
|
|
542
565
|
// over all previous known accounts and check against the keyring addresses.
|
|
543
|
-
for (const
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
patch.removed.push(account);
|
|
548
|
-
}
|
|
566
|
+
for (const [address, account] of Object.entries(patch.previous)) {
|
|
567
|
+
// If a previous address is not part of the new addesses, then it got removed.
|
|
568
|
+
if (!addresses.has(address)) {
|
|
569
|
+
patch.removed.push(account);
|
|
549
570
|
}
|
|
550
571
|
}
|
|
551
572
|
// Diff that we will use to publish events afterward.
|
|
@@ -555,29 +576,27 @@ _AccountsController_instances = new WeakSet(), _AccountsController_getAccountExp
|
|
|
555
576
|
};
|
|
556
577
|
__classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_update).call(this, (state) => {
|
|
557
578
|
const { internalAccounts, accountIdByAddress } = state;
|
|
558
|
-
for (const
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
metadata
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
diff.added.push(internalAccounts.accounts[account.id]);
|
|
580
|
-
}
|
|
579
|
+
for (const account of patch.removed) {
|
|
580
|
+
delete internalAccounts.accounts[account.id];
|
|
581
|
+
delete accountIdByAddress[account.address];
|
|
582
|
+
diff.removed.push(account.id);
|
|
583
|
+
}
|
|
584
|
+
for (const added of patch.added) {
|
|
585
|
+
const account = __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_getInternalAccountFromAddressAndType).call(this, added.address, added.keyring);
|
|
586
|
+
if (account) {
|
|
587
|
+
const accounts = Object.values(internalAccounts.accounts);
|
|
588
|
+
// If it's the first account, we need to select it.
|
|
589
|
+
const lastSelected = accounts.length === 0 ? __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_getLastSelectedIndex).call(this) : 0;
|
|
590
|
+
internalAccounts.accounts[account.id] = {
|
|
591
|
+
...account,
|
|
592
|
+
metadata: {
|
|
593
|
+
...account.metadata,
|
|
594
|
+
importTime: Date.now(),
|
|
595
|
+
lastSelected,
|
|
596
|
+
},
|
|
597
|
+
};
|
|
598
|
+
accountIdByAddress[account.address] = account.id;
|
|
599
|
+
diff.added.push(internalAccounts.accounts[account.id]);
|
|
581
600
|
}
|
|
582
601
|
}
|
|
583
602
|
},
|
|
@@ -638,36 +657,6 @@ _AccountsController_instances = new WeakSet(), _AccountsController_getAccountExp
|
|
|
638
657
|
this.messenger.publish('AccountsController:selectedAccountChange', account);
|
|
639
658
|
}
|
|
640
659
|
}
|
|
641
|
-
}, _AccountsController_handleOnSnapStateChange = function _AccountsController_handleOnSnapStateChange(snapState) {
|
|
642
|
-
// Only check if Snaps changed in status.
|
|
643
|
-
const { snaps } = snapState;
|
|
644
|
-
const accounts = [];
|
|
645
|
-
for (const account of this.listMultichainAccounts()) {
|
|
646
|
-
if (account.metadata.snap) {
|
|
647
|
-
const snap = snaps[account.metadata.snap.id];
|
|
648
|
-
if (snap) {
|
|
649
|
-
const enabled = snap.enabled && !snap.blocked;
|
|
650
|
-
const metadata = account.metadata.snap;
|
|
651
|
-
if (metadata.enabled !== enabled) {
|
|
652
|
-
accounts.push({ id: account.id, enabled });
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
else {
|
|
656
|
-
// If Snap could not be found on the state, we consider it disabled.
|
|
657
|
-
accounts.push({ id: account.id, enabled: false });
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
if (accounts.length > 0) {
|
|
662
|
-
this.update((state) => {
|
|
663
|
-
for (const { id, enabled } of accounts) {
|
|
664
|
-
const account = state.internalAccounts.accounts[id];
|
|
665
|
-
if (account.metadata.snap) {
|
|
666
|
-
account.metadata.snap.enabled = enabled;
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
});
|
|
670
|
-
}
|
|
671
660
|
}, _AccountsController_getLastSelectedAccount = function _AccountsController_getLastSelectedAccount(accounts) {
|
|
672
661
|
const [accountToSelect] = accounts.sort((accountA, accountB) => {
|
|
673
662
|
// sort by lastSelected descending
|
|
@@ -680,15 +669,16 @@ _AccountsController_instances = new WeakSet(), _AccountsController_getAccountExp
|
|
|
680
669
|
// will always be higher than any already selected account index.
|
|
681
670
|
return Date.now();
|
|
682
671
|
}, _AccountsController_getInternalAccountFromAddressAndType = function _AccountsController_getInternalAccountFromAddressAndType(address, keyring) {
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
672
|
+
const isSnapKeyringV1 = isSnapKeyringType(keyring.type);
|
|
673
|
+
const isSnapKeyringV2 = isSnapKeyringV2Type(keyring.type);
|
|
674
|
+
if (isSnapKeyringV1 || isSnapKeyringV2) {
|
|
675
|
+
let account;
|
|
676
|
+
if (isSnapKeyringV1) {
|
|
677
|
+
account = __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_getAccountFromSnapKeyringV1).call(this, address);
|
|
678
|
+
}
|
|
679
|
+
else {
|
|
680
|
+
account = __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_getAccountFromSnapKeyringV2).call(this, address);
|
|
688
681
|
}
|
|
689
|
-
// This might be undefined if the Snap deleted the account before
|
|
690
|
-
// reaching that point.
|
|
691
|
-
let account = snapKeyring.getAccountByAddress(address);
|
|
692
682
|
if (account) {
|
|
693
683
|
// We force the copy here, to avoid mutating the reference returned by the Snap keyring.
|
|
694
684
|
account = cloneDeep(account);
|
|
@@ -738,7 +728,6 @@ _AccountsController_instances = new WeakSet(), _AccountsController_getAccountExp
|
|
|
738
728
|
});
|
|
739
729
|
// DO NOT publish AccountsController:setSelectedAccount to prevent circular listener loops
|
|
740
730
|
}, _AccountsController_subscribeToMessageEvents = function _AccountsController_subscribeToMessageEvents() {
|
|
741
|
-
this.messenger.subscribe('SnapController:stateChange', (snapStateState) => __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_handleOnSnapStateChange).call(this, snapStateState));
|
|
742
731
|
this.messenger.subscribe('KeyringController:stateChange', (keyringState) => __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_handleOnKeyringStateChange).call(this, keyringState));
|
|
743
732
|
this.messenger.subscribe('SnapKeyring:accountAssetListUpdated', (snapAccountEvent) => __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_handleOnSnapKeyringAccountEvent).call(this, 'AccountsController:accountAssetListUpdated', snapAccountEvent));
|
|
744
733
|
this.messenger.subscribe('SnapKeyring:accountBalancesUpdated', (snapAccountEvent) => __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_handleOnSnapKeyringAccountEvent).call(this, 'AccountsController:accountBalancesUpdated', snapAccountEvent));
|