Skip to content

Commit

Permalink
move popup naming
Browse files Browse the repository at this point in the history
  • Loading branch information
cb-jake committed Jan 13, 2025
1 parent 4759b97 commit babbf34
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
{
Expand Down
4 changes: 1 addition & 3 deletions packages/wallet-sdk/src/core/communicator/Communicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }>();

Expand Down Expand Up @@ -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<ConfigMessage>(({ event }) => event === 'PopupUnload')
.then(this.disconnect)
Expand Down
6 changes: 3 additions & 3 deletions packages/wallet-sdk/src/util/web.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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')
);
});
Expand Down
5 changes: 3 additions & 2 deletions packages/wallet-sdk/src/util/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
);

Expand Down

0 comments on commit babbf34

Please sign in to comment.