@@ -7,18 +7,18 @@ import type {
7
7
} from '@metamask/keyring-api' ;
8
8
import {
9
9
BtcAccountType ,
10
+ BtcScope ,
10
11
EthAccountType ,
11
12
EthScope ,
12
- BtcScope ,
13
13
} from '@metamask/keyring-api' ;
14
14
import { KeyringTypes } from '@metamask/keyring-controller' ;
15
15
import type { InternalAccount } from '@metamask/keyring-internal-api' ;
16
16
import type { NetworkClientId } from '@metamask/network-controller' ;
17
17
import type { SnapControllerState } from '@metamask/snaps-controllers' ;
18
18
import { SnapStatus } from '@metamask/snaps-utils' ;
19
19
import type { CaipChainId } from '@metamask/utils' ;
20
- import * as uuid from 'uuid' ;
21
20
import type { V4Options } from 'uuid' ;
21
+ import * as uuid from 'uuid' ;
22
22
23
23
import type {
24
24
AccountsControllerActions ,
@@ -180,6 +180,29 @@ function setLastSelectedAsAny(account: InternalAccount): InternalAccount {
180
180
return deepClonedAccount ;
181
181
}
182
182
183
+ /**
184
+ * Sets the `entropySource` property of the given `account` to the specified
185
+ * keyringId value.
186
+ *
187
+ * @param account - The account to modify.
188
+ * @param keyringId - The keyring ID to set as entropySource.
189
+ * @returns The modified account.
190
+ */
191
+ function populateEntropySource (
192
+ account : InternalAccount ,
193
+ keyringId : string ,
194
+ ) : InternalAccount {
195
+ return JSON . parse (
196
+ JSON . stringify ( {
197
+ ...account ,
198
+ options : {
199
+ ...account . options ,
200
+ entropySource : keyringId ,
201
+ } ,
202
+ } ) ,
203
+ ) as InternalAccount ;
204
+ }
205
+
183
206
/**
184
207
* Builds a new instance of the Messenger class for the AccountsController.
185
208
*
@@ -621,7 +644,7 @@ describe('AccountsController', () => {
621
644
622
645
expect ( accounts ) . toStrictEqual ( [
623
646
mockAccount ,
624
- setLastSelectedAsAny ( mockAccount2 ) ,
647
+ setLastSelectedAsAny ( populateEntropySource ( mockAccount2 , 'mock-id' ) ) ,
625
648
] ) ;
626
649
} ) ;
627
650
@@ -876,6 +899,9 @@ describe('AccountsController', () => {
876
899
name : 'Account 3' ,
877
900
address : mockAccount3 . address ,
878
901
keyringType : KeyringTypes . hd ,
902
+ options : {
903
+ entropySource : 'mock-id' ,
904
+ } ,
879
905
} ) ,
880
906
) ,
881
907
] ) ;
@@ -941,7 +967,9 @@ describe('AccountsController', () => {
941
967
name : 'Account 3' ,
942
968
address : mockAccount3 . address ,
943
969
keyringType : KeyringTypes . hd ,
944
- options : { } ,
970
+ options : {
971
+ entropySource : 'mock-id' ,
972
+ } ,
945
973
} ) ,
946
974
] ) ;
947
975
} ) ;
@@ -1044,7 +1072,7 @@ describe('AccountsController', () => {
1044
1072
1045
1073
expect ( accounts ) . toStrictEqual ( [
1046
1074
mockAccount ,
1047
- setLastSelectedAsAny ( mockAccount2 ) ,
1075
+ setLastSelectedAsAny ( populateEntropySource ( mockAccount2 , 'mock-id' ) ) ,
1048
1076
] ) ;
1049
1077
expect ( accountsController . getSelectedAccount ( ) . id ) . toBe ( mockAccount . id ) ;
1050
1078
} ) ;
@@ -1093,7 +1121,7 @@ describe('AccountsController', () => {
1093
1121
// 2. AccountsController:stateChange
1094
1122
3 ,
1095
1123
'AccountsController:accountAdded' ,
1096
- setLastSelectedAsAny ( mockAccount2 ) ,
1124
+ setLastSelectedAsAny ( populateEntropySource ( mockAccount2 , 'mock-id' ) ) ,
1097
1125
) ;
1098
1126
} ) ;
1099
1127
} ) ;
@@ -1407,6 +1435,9 @@ describe('AccountsController', () => {
1407
1435
name : 'Account 1' ,
1408
1436
address : '0x456' ,
1409
1437
keyringType : KeyringTypes . hd ,
1438
+ options : {
1439
+ entropySource : 'mock-id' ,
1440
+ } ,
1410
1441
} ) ;
1411
1442
1412
1443
mockUUIDWithNormalAccounts ( [
0 commit comments