diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d1af12a..68516ff 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,7 +4,7 @@ on: branches: - develop - main - - beta-braavos-mobile + - beta-trpc-link - hotfix\/v[0-9]+.[0-9]+.[0-9]+ jobs: diff --git a/.releaserc b/.releaserc index cdcb825..7e4bd5e 100644 --- a/.releaserc +++ b/.releaserc @@ -10,7 +10,7 @@ "prerelease": true }, { - "name": "beta-braavos-mobile", + "name": "beta-trpc-link", "prerelease": true } ], diff --git a/package.json b/package.json index f61806c..6abd78d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "starknetkit", - "version": "2.6.2", + "version": "2.6.3-beta-trpc-link.1", "repository": "github:argentlabs/starknetkit", "private": false, "browser": { diff --git a/src/connectors/webwallet/helpers/trpc.ts b/src/connectors/webwallet/helpers/trpc.ts index 9fe64c0..f729fa7 100644 --- a/src/connectors/webwallet/helpers/trpc.ts +++ b/src/connectors/webwallet/helpers/trpc.ts @@ -53,6 +53,36 @@ export const setPopupOptions = ({ popupParams = `width=${width},height=${height},top=${y},left=${x},toolbar=no,menubar=no,scrollbars=no,location=no,status=no,popup=1` } +const PopupManager = { + currentPopup: null as Window | null, + + createPopup(url: string, name: string, params: string): Window { + // Close any existing popup + if (this.currentPopup && !this.currentPopup.closed) { + this.currentPopup.close() + } + + // Create popup immediately + const popup = window.open(url, name, params) + + if (!popup) { + throw new Error("Popup blocked by browser") + } + + this.currentPopup = popup + + // Monitor popup state + const checkClosed = setInterval(() => { + if (popup.closed) { + clearInterval(checkClosed) + this.currentPopup = null + } + }, 500) + + return popup + }, +} + // TODO: abstract AppRouter in order to have one single source of truth // At the moment, this is needed const appRouter = t.router({ @@ -195,29 +225,35 @@ export const trpcProxyClient = ({ false: popupLink({ listenWindow: window, createPopup: () => { - 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() - - // make sure popup is defined - ;(async () => { - while (!popup) { - await new Promise((resolve) => setTimeout(resolve, 100)) - } - })() + try { + let popup: Window | null = null + const button = document.createElement("button") + button.style.position = "fixed" + button.style.top = "-999px" + button.style.left = "-999px" + button.style.opacity = "0" + button.style.pointerEvents = "none" // prevent click event - if (!popup) { - throw new Error("Could not open popup") + button.addEventListener("click", () => { + popup = PopupManager.createPopup( + `${popupOrigin}${popupLocation}`, + "popup", + popupParams, + ) + }) + + document.body.appendChild(button) + button.click() + button.remove() + + if (!popup) { + throw new Error("Could not open popup") + } + return popup + } catch (error) { + console.error("Failed to create popup:", error) + throw error } - return popup }, postOrigin: "*", }),