Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: quick succession of submit password causing Accounts Controller state to be cleared #3802

Merged
merged 4 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion packages/accounts-controller/src/AccountsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,30 @@ describe('AccountsController', () => {
afterEach(() => {
jest.clearAllMocks();
});
it('should only update if the keyring is unlocked', async () => {
it('should not update state when only keyring is unlocked without any keyrings', async () => {
const messenger = buildMessenger();
const accountsController = setupAccountsController({
initialState: {
internalAccounts: {
accounts: {},
selectedAccount: '',
},
},
messenger,
});

messenger.publish(
'KeyringController:stateChange',
{ isUnlocked: true, keyrings: [] },
[],
);

const accounts = accountsController.listAccounts();

expect(accounts).toStrictEqual([]);
});

it('should only update if the keyring is unlocked and when there are keyrings', async () => {
const messenger = buildMessenger();

const mockNewKeyringState = {
Expand Down
5 changes: 4 additions & 1 deletion packages/accounts-controller/src/AccountsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,10 @@ export class AccountsController extends BaseController<
// check if there are any new accounts added
// TODO: change when accountAdded event is added to the keyring controller

if (keyringState.isUnlocked) {
// We check for keyrings length to be greater than 0 because the extension client may try execute
// submit password twice and clear the keyring state.
// https://github.com/MetaMask/KeyringController/blob/2d73a4deed8d013913f6ef0c9f5c0bb7c614f7d3/src/KeyringController.ts#L910
if (keyringState.isUnlocked && keyringState.keyrings.length > 0) {
const updatedNormalKeyringAddresses: AddressAndKeyringTypeObject[] = [];
const updatedSnapKeyringAddresses: AddressAndKeyringTypeObject[] = [];

Expand Down
Loading