From 955855b7d95562567791c78b049e267b07b42ec4 Mon Sep 17 00:00:00 2001 From: Erik Marks <25517051+rekmarks@users.noreply.github.com> Date: Fri, 14 Jan 2022 14:31:32 -0800 Subject: [PATCH] Fix manually connecting sites (#13320) --- .../controllers/permissions/background-api.js | 5 ++++- .../controllers/permissions/background-api.test.js | 14 ++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/scripts/controllers/permissions/background-api.js b/app/scripts/controllers/permissions/background-api.js index da8a9c4c8..0ed2354d1 100644 --- a/app/scripts/controllers/permissions/background-api.js +++ b/app/scripts/controllers/permissions/background-api.js @@ -1,3 +1,4 @@ +import nanoid from 'nanoid'; import { CaveatTypes, RestrictedMethods, @@ -59,11 +60,13 @@ export function getPermissionBackgroundApiMethods(permissionController) { }, requestAccountsPermissionWithId: async (origin) => { - const [, { id }] = await permissionController.requestPermissions( + const id = nanoid(); + permissionController.requestPermissions( { origin }, { eth_accounts: {}, }, + { id }, ); return id; }, diff --git a/app/scripts/controllers/permissions/background-api.test.js b/app/scripts/controllers/permissions/background-api.test.js index 39a96265a..8857835b4 100644 --- a/app/scripts/controllers/permissions/background-api.test.js +++ b/app/scripts/controllers/permissions/background-api.test.js @@ -160,9 +160,11 @@ describe('permission background API methods', () => { describe('requestAccountsPermissionWithId', () => { it('request an accounts permission and returns the request id', async () => { const permissionController = { - requestPermissions: jest.fn().mockImplementationOnce(async () => { - return [null, { id: 'arbitraryId' }]; - }), + requestPermissions: jest + .fn() + .mockImplementationOnce(async (_, __, { id }) => { + return [null, { id }]; + }), }; const id = await getPermissionBackgroundApiMethods( @@ -173,9 +175,13 @@ describe('permission background API methods', () => { expect(permissionController.requestPermissions).toHaveBeenCalledWith( { origin: 'foo.com' }, { 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, + ); }); }); });