1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00

fix: manually connect accountsChanged (#10477)

fixes #9933
This commit is contained in:
Shane 2021-02-19 09:48:49 -08:00 committed by GitHub
parent fab22ee05f
commit e3084b87cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 11 deletions

View File

@ -126,7 +126,12 @@ export class PermissionsController {
*/
async requestAccountsPermissionWithId(origin) {
const id = nanoid();
this._requestPermissions({ origin }, { eth_accounts: {} }, id);
this._requestPermissions({ origin }, { eth_accounts: {} }, id).then(
async () => {
const permittedAccounts = await this.getAccounts(origin);
this.notifyAccountsChanged(origin, permittedAccounts);
},
);
return id;
}

View File

@ -1519,12 +1519,30 @@ describe('permissions controller', function () {
});
describe('miscellanea and edge cases', function () {
it('requestAccountsPermissionWithId calls _requestAccountsPermission with an explicit request ID', async function () {
it('requestAccountsPermissionWithId calls _requestPermissions and notifyAccounts', function (done) {
const notifications = initNotifications();
const permController = initPermController(notifications);
const _requestPermissions = sinon
.stub(permController, '_requestPermissions')
.resolves();
const notifyAccountsChanged = sinon
.stub(permController, 'notifyAccountsChanged')
.callsFake(() => {
assert.ok(
notifyAccountsChanged.calledOnceWithExactly('example.com', []),
);
notifyAccountsChanged.restore();
_requestPermissions.restore();
done();
});
permController.requestAccountsPermissionWithId('example.com');
});
it('requestAccountsPermissionWithId calls _requestAccountsPermission with an explicit request ID', function (done) {
const permController = initPermController();
const _requestPermissions = sinon
.stub(permController, '_requestPermissions')
.resolves();
await permController.requestAccountsPermissionWithId('example.com');
const onResolved = async () => {
assert.ok(
_requestPermissions.calledOnceWithExactly(
sinon.match.object.and(sinon.match.has('origin')),
@ -1533,6 +1551,14 @@ describe('permissions controller', function () {
),
);
_requestPermissions.restore();
// eslint-disable-next-line no-use-before-define
notifyAccountsChanged.restore();
done();
};
const notifyAccountsChanged = sinon
.stub(permController, 'notifyAccountsChanged')
.callsFake(onResolved);
permController.requestAccountsPermissionWithId('example.com');
});
});
});