From babbf3460e76c589bfc56c25dfcd93f8d367460a Mon Sep 17 00:00:00 2001 From: Jake <95890768+cb-jake@users.noreply.github.com> Date: Mon, 13 Jan 2025 14:40:05 -0700 Subject: [PATCH] move popup naming --- .../wallet-sdk/src/core/communicator/Communicator.test.ts | 5 +---- packages/wallet-sdk/src/core/communicator/Communicator.ts | 4 +--- packages/wallet-sdk/src/util/web.test.ts | 6 +++--- packages/wallet-sdk/src/util/web.ts | 5 +++-- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/packages/wallet-sdk/src/core/communicator/Communicator.test.ts b/packages/wallet-sdk/src/core/communicator/Communicator.test.ts index a267cb542d..6753365bc5 100644 --- a/packages/wallet-sdk/src/core/communicator/Communicator.test.ts +++ b/packages/wallet-sdk/src/core/communicator/Communicator.test.ts @@ -161,10 +161,7 @@ describe('Communicator', () => { const popup = await communicator.waitForPopupLoaded(); - expect(openPopup).toHaveBeenCalledWith( - new URL(CB_KEYS_URL), - expect.stringContaining('wallet_') - ); + expect(openPopup).toHaveBeenCalledWith(new URL(CB_KEYS_URL)); expect(mockPopup.postMessage).toHaveBeenNthCalledWith( 1, { diff --git a/packages/wallet-sdk/src/core/communicator/Communicator.ts b/packages/wallet-sdk/src/core/communicator/Communicator.ts index e95ac21482..bc7a1a1833 100644 --- a/packages/wallet-sdk/src/core/communicator/Communicator.ts +++ b/packages/wallet-sdk/src/core/communicator/Communicator.ts @@ -25,7 +25,6 @@ export class Communicator { private readonly metadata: AppMetadata; private readonly preference: Preference; private readonly url: URL; - private id: string | null = null; private popup: Window | null = null; private listeners = new Map<(_: MessageEvent) => void, { reject: (_: Error) => void }>(); @@ -100,8 +99,7 @@ export class Communicator { return this.popup; } - this.id = `wallet_${crypto.randomUUID()}`; - this.popup = openPopup(this.url, this.id); + this.popup = openPopup(this.url); this.onMessage(({ event }) => event === 'PopupUnload') .then(this.disconnect) diff --git a/packages/wallet-sdk/src/util/web.test.ts b/packages/wallet-sdk/src/util/web.test.ts index fbe6c12786..9af7ba9fd3 100644 --- a/packages/wallet-sdk/src/util/web.test.ts +++ b/packages/wallet-sdk/src/util/web.test.ts @@ -34,12 +34,12 @@ describe('PopupManager', () => { const url = new URL('https://example.com'); (window.open as Mock).mockReturnValue({ focus: vi.fn() }); - const popup = openPopup(url, mockId); + const popup = openPopup(url); expect(window.open).toHaveBeenNthCalledWith( 1, url, - mockId, + expect.stringContaining('wallet_'), 'width=420, height=540, left=302, top=114' ); expect(popup.focus).toHaveBeenCalledTimes(1); @@ -53,7 +53,7 @@ describe('PopupManager', () => { it('should throw an error if popup fails to open', () => { (window.open as Mock).mockReturnValue(null); - expect(() => openPopup(new URL('https://example.com'), mockId)).toThrow( + expect(() => openPopup(new URL('https://example.com'))).toThrow( standardErrors.rpc.internal('Pop up window failed to open') ); }); diff --git a/packages/wallet-sdk/src/util/web.ts b/packages/wallet-sdk/src/util/web.ts index 65a5137d1b..c02500d2f2 100644 --- a/packages/wallet-sdk/src/util/web.ts +++ b/packages/wallet-sdk/src/util/web.ts @@ -7,14 +7,15 @@ const POPUP_HEIGHT = 540; // Window Management -export function openPopup(url: URL, id: string): Window { +export function openPopup(url: URL): Window { const left = (window.innerWidth - POPUP_WIDTH) / 2 + window.screenX; const top = (window.innerHeight - POPUP_HEIGHT) / 2 + window.screenY; appendAppInfoQueryParams(url); + const popupId = `wallet_${crypto.randomUUID()}`; const popup = window.open( url, - id, + popupId, `width=${POPUP_WIDTH}, height=${POPUP_HEIGHT}, left=${left}, top=${top}` );