mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 01:39:44 +01:00
Destroy ledger keyring when removing last account in ledger keyring (#14993)
* Destroy ledger keyring when removing last account in ledger keyring * Update unit tests
This commit is contained in:
parent
051254dffd
commit
ac7245b50c
@ -2673,8 +2673,14 @@ export default class MetamaskController extends EventEmitter {
|
||||
// Remove account from the account tracker controller
|
||||
this.accountTracker.removeAccount([address]);
|
||||
|
||||
const keyring = await this.keyringController.getKeyringForAccount(address);
|
||||
// Remove account from the keyring
|
||||
await this.keyringController.removeAccount(address);
|
||||
const updatedKeyringAccounts = keyring ? await keyring.getAccounts() : {};
|
||||
if (updatedKeyringAccounts?.length === 0) {
|
||||
keyring.destroy?.();
|
||||
}
|
||||
|
||||
return address;
|
||||
}
|
||||
|
||||
|
@ -782,12 +782,20 @@ describe('MetaMaskController', function () {
|
||||
describe('#removeAccount', function () {
|
||||
let ret;
|
||||
const addressToRemove = '0x1';
|
||||
let mockKeyring;
|
||||
|
||||
beforeEach(async function () {
|
||||
mockKeyring = {
|
||||
getAccounts: sinon.stub().returns(Promise.resolve([])),
|
||||
destroy: sinon.stub(),
|
||||
};
|
||||
sinon.stub(metamaskController.preferencesController, 'removeAddress');
|
||||
sinon.stub(metamaskController.accountTracker, 'removeAccount');
|
||||
sinon.stub(metamaskController.keyringController, 'removeAccount');
|
||||
sinon.stub(metamaskController, 'removeAllAccountPermissions');
|
||||
sinon
|
||||
.stub(metamaskController.keyringController, 'getKeyringForAccount')
|
||||
.returns(Promise.resolve(mockKeyring));
|
||||
|
||||
ret = await metamaskController.removeAccount(addressToRemove);
|
||||
});
|
||||
@ -797,6 +805,9 @@ describe('MetaMaskController', function () {
|
||||
metamaskController.accountTracker.removeAccount.restore();
|
||||
metamaskController.preferencesController.removeAddress.restore();
|
||||
metamaskController.removeAllAccountPermissions.restore();
|
||||
|
||||
mockKeyring.getAccounts.resetHistory();
|
||||
mockKeyring.destroy.resetHistory();
|
||||
});
|
||||
|
||||
it('should call preferencesController.removeAddress', async function () {
|
||||
@ -830,6 +841,16 @@ describe('MetaMaskController', function () {
|
||||
it('should return address', async function () {
|
||||
assert.equal(ret, '0x1');
|
||||
});
|
||||
it('should call keyringController.getKeyringForAccount', async function () {
|
||||
assert(
|
||||
metamaskController.keyringController.getKeyringForAccount.calledWith(
|
||||
addressToRemove,
|
||||
),
|
||||
);
|
||||
});
|
||||
it('should call keyring.destroy', async function () {
|
||||
assert(mockKeyring.destroy.calledOnce);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#newUnsignedMessage', function () {
|
||||
|
Loading…
Reference in New Issue
Block a user