mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 01:39:44 +01:00
parent
fab22ee05f
commit
e3084b87cc
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user