mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +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
390cf09b3f
commit
254e600d07
@ -2587,8 +2587,14 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
// Remove account from the account tracker controller
|
// Remove account from the account tracker controller
|
||||||
this.accountTracker.removeAccount([address]);
|
this.accountTracker.removeAccount([address]);
|
||||||
|
|
||||||
|
const keyring = await this.keyringController.getKeyringForAccount(address);
|
||||||
// Remove account from the keyring
|
// Remove account from the keyring
|
||||||
await this.keyringController.removeAccount(address);
|
await this.keyringController.removeAccount(address);
|
||||||
|
const updatedKeyringAccounts = keyring ? await keyring.getAccounts() : {};
|
||||||
|
if (updatedKeyringAccounts?.length === 0) {
|
||||||
|
keyring.destroy?.();
|
||||||
|
}
|
||||||
|
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -769,12 +769,20 @@ describe('MetaMaskController', function () {
|
|||||||
describe('#removeAccount', function () {
|
describe('#removeAccount', function () {
|
||||||
let ret;
|
let ret;
|
||||||
const addressToRemove = '0x1';
|
const addressToRemove = '0x1';
|
||||||
|
let mockKeyring;
|
||||||
|
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
|
mockKeyring = {
|
||||||
|
getAccounts: sinon.stub().returns(Promise.resolve([])),
|
||||||
|
destroy: sinon.stub(),
|
||||||
|
};
|
||||||
sinon.stub(metamaskController.preferencesController, 'removeAddress');
|
sinon.stub(metamaskController.preferencesController, 'removeAddress');
|
||||||
sinon.stub(metamaskController.accountTracker, 'removeAccount');
|
sinon.stub(metamaskController.accountTracker, 'removeAccount');
|
||||||
sinon.stub(metamaskController.keyringController, 'removeAccount');
|
sinon.stub(metamaskController.keyringController, 'removeAccount');
|
||||||
sinon.stub(metamaskController, 'removeAllAccountPermissions');
|
sinon.stub(metamaskController, 'removeAllAccountPermissions');
|
||||||
|
sinon
|
||||||
|
.stub(metamaskController.keyringController, 'getKeyringForAccount')
|
||||||
|
.returns(Promise.resolve(mockKeyring));
|
||||||
|
|
||||||
ret = await metamaskController.removeAccount(addressToRemove);
|
ret = await metamaskController.removeAccount(addressToRemove);
|
||||||
});
|
});
|
||||||
@ -784,6 +792,9 @@ describe('MetaMaskController', function () {
|
|||||||
metamaskController.accountTracker.removeAccount.restore();
|
metamaskController.accountTracker.removeAccount.restore();
|
||||||
metamaskController.preferencesController.removeAddress.restore();
|
metamaskController.preferencesController.removeAddress.restore();
|
||||||
metamaskController.removeAllAccountPermissions.restore();
|
metamaskController.removeAllAccountPermissions.restore();
|
||||||
|
|
||||||
|
mockKeyring.getAccounts.resetHistory();
|
||||||
|
mockKeyring.destroy.resetHistory();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call preferencesController.removeAddress', async function () {
|
it('should call preferencesController.removeAddress', async function () {
|
||||||
@ -817,6 +828,16 @@ describe('MetaMaskController', function () {
|
|||||||
it('should return address', async function () {
|
it('should return address', async function () {
|
||||||
assert.equal(ret, '0x1');
|
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 () {
|
describe('#newUnsignedMessage', function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user