Fix manually connecting sites (#13320)

feature/default_network_editable
Erik Marks 3 years ago committed by ryanml
parent 66ceeefae3
commit 955855b7d9
  1. 5
      app/scripts/controllers/permissions/background-api.js
  2. 12
      app/scripts/controllers/permissions/background-api.test.js

@ -1,3 +1,4 @@
import nanoid from 'nanoid';
import { import {
CaveatTypes, CaveatTypes,
RestrictedMethods, RestrictedMethods,
@ -59,11 +60,13 @@ export function getPermissionBackgroundApiMethods(permissionController) {
}, },
requestAccountsPermissionWithId: async (origin) => { requestAccountsPermissionWithId: async (origin) => {
const [, { id }] = await permissionController.requestPermissions( const id = nanoid();
permissionController.requestPermissions(
{ origin }, { origin },
{ {
eth_accounts: {}, eth_accounts: {},
}, },
{ id },
); );
return id; return id;
}, },

@ -160,8 +160,10 @@ describe('permission background API methods', () => {
describe('requestAccountsPermissionWithId', () => { describe('requestAccountsPermissionWithId', () => {
it('request an accounts permission and returns the request id', async () => { it('request an accounts permission and returns the request id', async () => {
const permissionController = { const permissionController = {
requestPermissions: jest.fn().mockImplementationOnce(async () => { requestPermissions: jest
return [null, { id: 'arbitraryId' }]; .fn()
.mockImplementationOnce(async (_, __, { id }) => {
return [null, { id }];
}), }),
}; };
@ -173,9 +175,13 @@ describe('permission background API methods', () => {
expect(permissionController.requestPermissions).toHaveBeenCalledWith( expect(permissionController.requestPermissions).toHaveBeenCalledWith(
{ origin: 'foo.com' }, { origin: 'foo.com' },
{ eth_accounts: {} }, { eth_accounts: {} },
{ id: expect.any(String) },
); );
expect(id).toStrictEqual('arbitraryId'); expect(id.length > 0).toBe(true);
expect(id).toStrictEqual(
permissionController.requestPermissions.mock.calls[0][2].id,
);
}); });
}); });
}); });

Loading…
Cancel
Save