Skip to content

Commit aa76fac

Browse files
committed
feat(accounts-controller): Add entropySource to new InternalAccount
`AccountsController:accountAdded` events were missing the `.options.entropySource` property, causing account syncing to misbehave. Relates to #5618 Relates to #5725 Relates to #5753
1 parent 1f8c7cc commit aa76fac

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

packages/accounts-controller/src/AccountsController.test.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ const mockGetState = jest.fn();
5656
const mockAccount: InternalAccount = {
5757
id: 'mock-id',
5858
address: '0x123',
59-
options: {},
59+
options: {
60+
entropySource: 'mock-id',
61+
},
6062
methods: [...ETH_EOA_METHODS],
6163
type: EthAccountType.Eoa,
6264
scopes: [EthScope.Eoa],
@@ -72,7 +74,9 @@ const mockAccount: InternalAccount = {
7274
const mockAccount2: InternalAccount = {
7375
id: 'mock-id2',
7476
address: '0x1234',
75-
options: {},
77+
options: {
78+
entropySource: 'mock-id',
79+
},
7680
methods: [...ETH_EOA_METHODS],
7781
type: EthAccountType.Eoa,
7882
scopes: [EthScope.Eoa],
@@ -87,7 +91,9 @@ const mockAccount2: InternalAccount = {
8791
const mockAccount3: InternalAccount = {
8892
id: 'mock-id3',
8993
address: '0x3333',
90-
options: {},
94+
options: {
95+
entropySource: 'mock-id',
96+
},
9197
methods: [...ETH_EOA_METHODS],
9298
type: EthAccountType.Eoa,
9399
scopes: [EthScope.Eoa],
@@ -695,6 +701,9 @@ describe('AccountsController', () => {
695701
address: mockAccount3.address,
696702
keyringType: mockAccount3.metadata.keyring.type as KeyringTypes,
697703
snap: mockAccount3.metadata.snap,
704+
options: {
705+
entropySource: 'mock-id2',
706+
}
698707
}),
699708
),
700709
]);
@@ -876,6 +885,9 @@ describe('AccountsController', () => {
876885
name: 'Account 3',
877886
address: mockAccount3.address,
878887
keyringType: KeyringTypes.hd,
888+
options: {
889+
entropySource: mockAccount3.options.entropySource,
890+
},
879891
}),
880892
),
881893
]);
@@ -941,7 +953,9 @@ describe('AccountsController', () => {
941953
name: 'Account 3',
942954
address: mockAccount3.address,
943955
keyringType: KeyringTypes.hd,
944-
options: {},
956+
options: {
957+
entropySource: mockAccount3.options.entropySource,
958+
},
945959
}),
946960
]);
947961
});
@@ -1407,6 +1421,9 @@ describe('AccountsController', () => {
14071421
name: 'Account 1',
14081422
address: '0x456',
14091423
keyringType: KeyringTypes.hd,
1424+
options: {
1425+
entropySource: 'mock-id',
1426+
},
14101427
});
14111428

14121429
mockUUIDWithNormalAccounts([
@@ -2042,6 +2059,9 @@ describe('AccountsController', () => {
20422059
address: mockSnapAccount2.address,
20432060
keyringType: KeyringTypes.snap,
20442061
snap: mockSnapAccount2.metadata.snap,
2062+
options: {
2063+
entropySource: 'mock-id',
2064+
},
20452065
}),
20462066
];
20472067

@@ -2114,6 +2134,9 @@ describe('AccountsController', () => {
21142134
address: mockSnapAccount2.address,
21152135
keyringType: KeyringTypes.snap,
21162136
snap: mockSnapAccount2.metadata.snap,
2137+
options: {
2138+
entropySource: 'mock-id',
2139+
},
21172140
}),
21182141
];
21192142

@@ -3034,18 +3057,27 @@ describe('AccountsController', () => {
30343057
name: 'Account 2',
30353058
address: '0x555',
30363059
keyringType: KeyringTypes.simple,
3060+
options: {
3061+
entropySource: 'mock-id2',
3062+
},
30373063
});
30383064
const mockSimpleKeyring2 = createMockInternalAccount({
30393065
id: 'mock-id3',
30403066
name: 'Account 3',
30413067
address: '0x666',
30423068
keyringType: KeyringTypes.simple,
3069+
options: {
3070+
entropySource: 'mock-id2',
3071+
},
30433072
});
30443073
const mockSimpleKeyring3 = createMockInternalAccount({
30453074
id: 'mock-id4',
30463075
name: 'Account 4',
30473076
address: '0x777',
30483077
keyringType: KeyringTypes.simple,
3078+
options: {
3079+
entropySource: 'mock-id2',
3080+
},
30493081
});
30503082

30513083
const mockNewKeyringStateWith = (simpleAddressess: string[]) => {

packages/accounts-controller/src/AccountsController.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,7 @@ export class AccountsController extends BaseController<
791791
added: [] as {
792792
address: string;
793793
type: string;
794+
entropySource: string;
794795
}[],
795796
updated: [] as InternalAccount[],
796797
removed: [] as InternalAccount[],
@@ -836,6 +837,7 @@ export class AccountsController extends BaseController<
836837
patch.added.push({
837838
address,
838839
type: keyring.type,
840+
entropySource: keyring.metadata.id,
839841
});
840842
}
841843

@@ -902,6 +904,10 @@ export class AccountsController extends BaseController<
902904
importTime: Date.now(),
903905
lastSelected,
904906
},
907+
options: {
908+
...account.options,
909+
entropySource: added.entropySource,
910+
},
905911
};
906912

907913
diff.added.push(internalAccounts.accounts[account.id]);

0 commit comments

Comments
 (0)