From d2711a1f45f864244020605357b3b50f115a50c6 Mon Sep 17 00:00:00 2001 From: bluecco Date: Wed, 20 Mar 2024 19:58:19 +0100 Subject: [PATCH 1/2] fix: argent webwallet iframes --- .../webwallet/helpers/openWebwallet.ts | 33 +++++++++++++------ .../starknetWindowObject/wormhole.ts | 2 ++ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/connectors/webwallet/helpers/openWebwallet.ts b/src/connectors/webwallet/helpers/openWebwallet.ts index 885b88d..fac8c07 100644 --- a/src/connectors/webwallet/helpers/openWebwallet.ts +++ b/src/connectors/webwallet/helpers/openWebwallet.ts @@ -60,17 +60,30 @@ export const openWebwallet = async ( const { allowedDapps } = await fetchAllowedDapps(network) if (allowedDapps.includes(window.location.hostname)) { - const { iframe, modal } = await createModal(origin, false) - const windowProxyClient = trpcProxyClient({}) - const isConnected = await windowProxyClient.authorize.mutate() - if (isConnected) { - const starknetWindowObject = await getWebWalletStarknetObject( - origin, - trpcProxyClient({ iframe: iframe.contentWindow ?? undefined }), - { modal, iframe }, - ) - return starknetWindowObject + const modalId = "argent-webwallet-modal" + const iframeId = "argent-webwallet-iframe" + + const existingIframe = document.getElementById(modalId) + const existingModal = document.getElementById(iframeId) + + // avoid duplicate iframes + if (existingIframe && existingIframe && existingModal) { + existingIframe.remove() + existingModal.remove() } + const { iframe, modal } = await createModal(origin, false) + + const iframeTrpcProxyClient = trpcProxyClient({ + iframe: iframe.contentWindow ?? undefined, + }) + await iframeTrpcProxyClient.authorize.mutate() + const starknetWindowObject = await getWebWalletStarknetObject( + origin, + iframeTrpcProxyClient, + { modal, iframe }, + ) + return starknetWindowObject + /* } */ } else { const windowProxyClient = trpcProxyClient({}) return await getWebWalletStarknetObject( diff --git a/src/connectors/webwallet/starknetWindowObject/wormhole.ts b/src/connectors/webwallet/starknetWindowObject/wormhole.ts index 2564177..e70e27e 100644 --- a/src/connectors/webwallet/starknetWindowObject/wormhole.ts +++ b/src/connectors/webwallet/starknetWindowObject/wormhole.ts @@ -58,9 +58,11 @@ export const createModal = async (targetUrl: string, shouldShow: boolean) => { "allow-popups", ) iframe.allow = "clipboard-write" + iframe.id = "argent-webwallet-iframe" const modal = applyModalStyle(iframe) modal.style.display = shouldShow ? "block" : "none" + modal.id = "argent-webwallet-modal" // append the modal to the body window.document.body.appendChild(modal) From ce4548b51112f0c9384bb0bda54bd9017e38917f Mon Sep 17 00:00:00 2001 From: bluecco Date: Wed, 20 Mar 2024 19:58:34 +0100 Subject: [PATCH 2/2] fix: argent mobile qr url --- src/connectors/argentMobile/modal/argentModal.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/connectors/argentMobile/modal/argentModal.ts b/src/connectors/argentMobile/modal/argentModal.ts index 4ccc07a..204830f 100644 --- a/src/connectors/argentMobile/modal/argentModal.ts +++ b/src/connectors/argentMobile/modal/argentModal.ts @@ -72,7 +72,9 @@ class ArgentModal { const wcParam = encodeURIComponent(wcUri) const href = encodeURIComponent(window.location.href) - const desktopWcParam = `${this.mobileUrl}app/wc?uri=${wcParam}` + const desktopWcParam = encodeURIComponent( + `${this.mobileUrl}app/wc?uri=${wcParam}`, + ) this.showModal({ desktop: `${this.bridgeUrl}?wc=${desktopWcParam}&device=desktop`,