diff --git a/app/scripts/controllers/permissions/index.js b/app/scripts/controllers/permissions/index.js index c10a950cb..c4b6eae79 100644 --- a/app/scripts/controllers/permissions/index.js +++ b/app/scripts/controllers/permissions/index.js @@ -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; } diff --git a/test/unit/app/controllers/permissions/permissions-controller-test.js b/test/unit/app/controllers/permissions/permissions-controller-test.js index 9fb2529a4..b36467566 100644 --- a/test/unit/app/controllers/permissions/permissions-controller-test.js +++ b/test/unit/app/controllers/permissions/permissions-controller-test.js @@ -1519,20 +1519,46 @@ 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'); - assert.ok( - _requestPermissions.calledOnceWithExactly( - sinon.match.object.and(sinon.match.has('origin')), - { eth_accounts: {} }, - sinon.match.string.and(sinon.match.truthy), - ), - ); - _requestPermissions.restore(); + const onResolved = async () => { + assert.ok( + _requestPermissions.calledOnceWithExactly( + sinon.match.object.and(sinon.match.has('origin')), + { eth_accounts: {} }, + sinon.match.string.and(sinon.match.truthy), + ), + ); + _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'); }); }); });