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) {
|
async requestAccountsPermissionWithId(origin) {
|
||||||
const id = nanoid();
|
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;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1519,20 +1519,46 @@ describe('permissions controller', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('miscellanea and edge cases', 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 permController = initPermController();
|
||||||
const _requestPermissions = sinon
|
const _requestPermissions = sinon
|
||||||
.stub(permController, '_requestPermissions')
|
.stub(permController, '_requestPermissions')
|
||||||
.resolves();
|
.resolves();
|
||||||
await permController.requestAccountsPermissionWithId('example.com');
|
const onResolved = async () => {
|
||||||
assert.ok(
|
assert.ok(
|
||||||
_requestPermissions.calledOnceWithExactly(
|
_requestPermissions.calledOnceWithExactly(
|
||||||
sinon.match.object.and(sinon.match.has('origin')),
|
sinon.match.object.and(sinon.match.has('origin')),
|
||||||
{ eth_accounts: {} },
|
{ eth_accounts: {} },
|
||||||
sinon.match.string.and(sinon.match.truthy),
|
sinon.match.string.and(sinon.match.truthy),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
_requestPermissions.restore();
|
_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