Skip to content

Commit 7ac70e1

Browse files
committed
fix: update webwallet iframe
1 parent a6c1cc3 commit 7ac70e1

File tree

7 files changed

+59
-25
lines changed

7 files changed

+59
-25
lines changed

src/connectors/webwallet/helpers/openWebwallet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const openWebwallet = async (
7171
existingIframe.remove()
7272
existingModal.remove()
7373
}
74-
const { iframe } = await createModal(origin, false)
74+
const { iframe, backdrop } = await createModal(origin, false)
7575

7676
const iframeTrpcProxyClient = trpcProxyClient({
7777
iframe: iframe.contentWindow ?? undefined,
@@ -80,7 +80,7 @@ export const openWebwallet = async (
8080
const starknetWindowObject = await getWebWalletStarknetObject(
8181
origin,
8282
iframeTrpcProxyClient,
83-
{ iframe },
83+
{ iframe, backdrop },
8484
)
8585
return starknetWindowObject
8686
} else {

src/connectors/webwallet/helpers/popupSizes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ export const EXECUTE_POPUP_HEIGHT = 775
55
export const SIGN_MESSAGE_POPUP_WIDTH = 385
66
export const SIGN_MESSAGE_POPUP_HEIGHT = 440
77

8-
export const ENABLE_POPUP_WIDTH = 886
9-
export const ENABLE_POPUP_HEIGHT = 562
8+
export const ENABLE_POPUP_WIDTH = 420
9+
export const ENABLE_POPUP_HEIGHT = 438

src/connectors/webwallet/helpers/trpc.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
deployAccountContractSchema,
1212
} from "../../../types/window"
1313
import { DEFAULT_WEBWALLET_URL } from "../constants"
14+
import { iframeId } from "../starknetWindowObject/wormhole"
1415

1516
const t = initTRPC.create({
1617
isServer: false,
@@ -53,6 +54,14 @@ export const setPopupOptions = ({
5354
popupParams = `width=${width},height=${height},top=${y},left=${x},toolbar=no,menubar=no,scrollbars=no,location=no,status=no,popup=1`
5455
}
5556

57+
export const setIframeSize = (width: number, height: number) => {
58+
const iframe = document.getElementById(iframeId) as HTMLIFrameElement
59+
if (iframe) {
60+
iframe.style.minWidth = `${width}px`
61+
iframe.style.minHeight = `${height}px`
62+
}
63+
}
64+
5665
// TODO: abstract AppRouter in order to have one single source of truth
5766
// At the moment, this is needed
5867
const appRouter = t.router({
@@ -64,7 +73,6 @@ const appRouter = t.router({
6473
.input(
6574
z.object({
6675
theme: z.enum(["light", "dark", "auto"]).optional(),
67-
featureFlagIframeProtection: z.boolean().optional(),
6876
}),
6977
)
7078
.output(

src/connectors/webwallet/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ interface WebWalletConnectorOptions {
4141
theme?: Theme
4242
ssoToken?: string
4343
authorizedPartyId?: string
44-
featureFlagIframeProtection?: boolean
4544
}
4645

4746
export class WebWalletConnector extends Connector {
@@ -132,8 +131,6 @@ export class WebWalletConnector extends Connector {
132131
this._wallet as WebWalletStarknetWindowObject
133132
).connectWebwallet({
134133
theme: this._options.theme,
135-
featureFlagIframeProtection:
136-
this._options.featureFlagIframeProtection,
137134
})
138135
account = connectResponse.account
139136
chainId = connectResponse.chainId

src/connectors/webwallet/starknetWindowObject/argentStarknetWindowObject.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import type {
88
import type { CreateTRPCProxyClient } from "@trpc/client"
99
import type { constants } from "starknet"
1010
import {
11+
ENABLE_POPUP_WIDTH,
1112
EXECUTE_POPUP_HEIGHT,
1213
EXECUTE_POPUP_WIDTH,
1314
SIGN_MESSAGE_POPUP_HEIGHT,
1415
SIGN_MESSAGE_POPUP_WIDTH,
1516
} from "../helpers/popupSizes"
16-
import { setPopupOptions, type AppRouter } from "../helpers/trpc"
17+
import { setIframeSize, setPopupOptions, type AppRouter } from "../helpers/trpc"
1718

1819
export const userEventHandlers: WalletEvents[] = []
1920

@@ -37,7 +38,6 @@ export type Theme = "light" | "dark"
3738

3839
type ConnectWebwalletProps = {
3940
theme?: Theme
40-
featureFlagIframeProtection?: boolean
4141
}
4242

4343
export type WebWalletStarknetWindowObject = StarknetWindowObject & {
@@ -65,10 +65,10 @@ export const getArgentStarknetWindowObject = (
6565
return proxyLink.getLoginStatus.mutate()
6666
},
6767
connectWebwallet: (props = {}) => {
68-
const { theme, featureFlagIframeProtection } = props
68+
const { theme } = props
69+
setIframeSize(ENABLE_POPUP_WIDTH, ENABLE_POPUP_WIDTH)
6970
return proxyLink.connectWebwallet.mutate({
7071
theme,
71-
featureFlagIframeProtection,
7272
})
7373
},
7474
connectWebwalletSSO: (token, authorizedPartyId) => {
@@ -93,6 +93,9 @@ export const getArgentStarknetWindowObject = (
9393
height: SIGN_MESSAGE_POPUP_HEIGHT,
9494
location: isSession ? "/signSessionKeys" : "/signMessage",
9595
})
96+
97+
setIframeSize(SIGN_MESSAGE_POPUP_WIDTH, SIGN_MESSAGE_POPUP_HEIGHT)
98+
9699
const data = Array.isArray(call.params) ? call.params : [call.params]
97100
return proxyLink.signTypedData.mutate(data as any)
98101
}
@@ -110,6 +113,8 @@ export const getArgentStarknetWindowObject = (
110113
location: "/review",
111114
})
112115

116+
setIframeSize(EXECUTE_POPUP_WIDTH, EXECUTE_POPUP_HEIGHT)
117+
113118
const hash = await proxyLink.addInvokeTransaction.mutate(calls)
114119

115120
return { transaction_hash: hash }

src/connectors/webwallet/starknetWindowObject/getWebWalletStarknetObject.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { hideModal, showModal } from "./wormhole"
66

77
type IframeProps = {
88
iframe: HTMLIFrameElement
9+
backdrop: HTMLDivElement
910
}
1011

1112
export type ModalEvents =
@@ -38,15 +39,15 @@ export const getWebWalletStarknetObject = async (
3839
)
3940

4041
if (iframeProps) {
41-
const { iframe } = iframeProps
42+
const { iframe, backdrop } = iframeProps
4243
proxyLink.updateModal.subscribe(undefined, {
4344
onData(modalEvent: ModalEvents) {
4445
switch (modalEvent.action) {
4546
case "show":
46-
showModal(iframe)
47+
showModal(iframe, backdrop)
4748
break
4849
case "hide":
49-
hideModal(iframe)
50+
hideModal(iframe, backdrop)
5051
break
5152
}
5253
},

src/connectors/webwallet/starknetWindowObject/wormhole.ts

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,36 @@
11
const applyModalStyle = (iframe: HTMLIFrameElement) => {
22
iframe.style.display = "none"
3-
iframe.style.border = "none"
3+
iframe.style.borderRadius = "40px"
44
iframe.style.inset = "0"
55
iframe.style.position = "fixed"
6-
iframe.style.width = "100%"
7-
iframe.style.height = "100%"
8-
iframe.style.backgroundColor = "rgba(0,0,0,0.5);"
6+
iframe.style.top = "50%"
7+
iframe.style.left = "50%"
8+
iframe.style.transform = "translate(-50%, -50%)"
9+
iframe.style.backgroundColor = "transparent"
910
iframe.style.zIndex = "999999"
1011
}
1112

12-
export const showModal = (iframe: HTMLIFrameElement) => {
13+
export const showModal = (
14+
iframe: HTMLIFrameElement,
15+
backdrop: HTMLDivElement,
16+
) => {
1317
iframe.style.display = "block"
18+
backdrop.style.display = "block"
1419
}
1520

16-
export const hideModal = (iframe: HTMLIFrameElement) => {
21+
export const hideModal = (
22+
iframe: HTMLIFrameElement,
23+
backdrop: HTMLDivElement,
24+
) => {
1725
iframe.style.display = "none"
26+
backdrop.style.display = "none"
1827
}
1928

29+
export const iframeId = "argent-webwallet-iframe"
30+
2031
export const createModal = async (targetUrl: string, shouldShow: boolean) => {
2132
// make sure target url has always /iframes/comms as the path
22-
const iframeId = "argent-webwallet-iframe"
33+
const backdropId = "argent-webwallet-backdrop"
2334
const url = new URL(targetUrl)
2435
url.pathname = "/iframes/comms"
2536
targetUrl = url.toString()
@@ -34,20 +45,30 @@ export const createModal = async (targetUrl: string, shouldShow: boolean) => {
3445
"allow-top-navigation",
3546
"allow-popups",
3647
)
37-
iframe.allow = "clipboard-write allowtransparency"
48+
iframe.allow = "clipboard-write"
3849
iframe.id = iframeId
3950
iframe.setAttribute("allowtransparency", "true")
4051
iframe.setAttribute("transparent", "true")
4152

4253
applyModalStyle(iframe)
4354
iframe.style.display = shouldShow ? "block" : "none"
4455

45-
const existingElement = document.getElementById(iframeId)
56+
const backdrop = document.createElement("div")
57+
backdrop.id = backdropId
58+
backdrop.style.position = "fixed"
59+
backdrop.style.inset = "0"
60+
backdrop.style.backgroundColor = "rgba(0,0,0,0.5)"
61+
backdrop.style.zIndex = "999998"
62+
backdrop.style.width = "100dvw"
63+
backdrop.style.height = "100dvh"
64+
backdrop.style.backdropFilter = "blur(4px)"
4665

66+
const existingElement = document.getElementById(iframeId)
4767
if (existingElement) {
4868
// element exists but shadowRoot cannot be accessed
4969
// delete the element and create new
5070
existingElement.remove()
71+
document.getElementById(backdropId)?.remove()
5172
}
5273
window.document.body.appendChild(iframe)
5374

@@ -64,5 +85,7 @@ export const createModal = async (targetUrl: string, shouldShow: boolean) => {
6485
})
6586
})
6687

67-
return { iframe }
88+
window.document.body.appendChild(backdrop)
89+
90+
return { iframe, backdrop }
6891
}

0 commit comments

Comments
 (0)