From 1b55b6e90a4cd7420567f63161a6ff26fe87474a Mon Sep 17 00:00:00 2001 From: bluecco Date: Tue, 7 Nov 2023 15:24:26 +0100 Subject: [PATCH] fix: open webwallet with click --- src/connectors/webwallet/helpers/trpc.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/connectors/webwallet/helpers/trpc.ts b/src/connectors/webwallet/helpers/trpc.ts index 3351d2c..c4416e8 100644 --- a/src/connectors/webwallet/helpers/trpc.ts +++ b/src/connectors/webwallet/helpers/trpc.ts @@ -133,13 +133,25 @@ export const trpcProxyClient = ({ false: popupLink({ listenWindow: window, createPopup: () => { - // parent is the window that opened this window; if not detected then it falls back to the current screen + let popup: Window | null = null + const webwalletBtn = document.createElement("button") + webwalletBtn.style.display = "none" + webwalletBtn.addEventListener("click", () => { + popup = window.open( + `${popupOrigin}${popupLocation}`, + "popup", + popupParams, + ) + }) + webwalletBtn.click() - const popup = window.open( - `${popupOrigin}${popupLocation}`, - "popup", - popupParams, - ) + // make sure popup is defined + ;(async () => { + console.log(popup) + while (!popup) { + await new Promise((resolve) => setTimeout(resolve, 100)) + } + })() if (!popup) { throw new Error("Could not open popup")