Skip to content

Commit

Permalink
feat: add iframe protection feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
bluecco committed Feb 11, 2025
1 parent 8256e26 commit 221ca24
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/connectors/webwallet/helpers/openWebwallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export const openWebwallet = async (
const modalId = "argent-webwallet-modal"
const iframeId = "argent-webwallet-iframe"

const existingIframe = document.getElementById(modalId)
const existingModal = document.getElementById(iframeId)
const existingModal = document.getElementById(modalId)
const existingIframe = document.getElementById(iframeId)

// avoid duplicate iframes
if (existingIframe && existingIframe && existingModal) {
Expand Down
1 change: 1 addition & 0 deletions src/connectors/webwallet/helpers/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const appRouter = t.router({
.input(
z.object({
theme: z.enum(["light", "dark", "auto"]).optional(),
featureFlagIframeProtection: z.boolean().optional(),
}),
)
.output(
Expand Down
11 changes: 8 additions & 3 deletions src/connectors/webwallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
} from "@starknet-io/types-js"
import {
Account,
AccountInterface,
ProviderInterface,
type AccountInterface,
type ProviderInterface,
type ProviderOptions,
} from "starknet"
import {
Expand Down Expand Up @@ -41,6 +41,7 @@ interface WebWalletConnectorOptions {
theme?: Theme
ssoToken?: string
authorizedPartyId?: string
featureFlagIframeProtection?: boolean
}

export class WebWalletConnector extends Connector {
Expand Down Expand Up @@ -129,7 +130,11 @@ export class WebWalletConnector extends Connector {
} else {
const connectResponse = await (
this._wallet as WebWalletStarknetWindowObject
).connectWebwallet({ theme: this._options.theme })
).connectWebwallet({
theme: this._options.theme,
featureFlagIframeProtection:
this._options.featureFlagIframeProtection,
})
account = connectResponse.account
chainId = connectResponse.chainId
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type Theme = "light" | "dark"

type ConnectWebwalletProps = {
theme?: Theme
featureFlagIframeProtection?: boolean
}

export type WebWalletStarknetWindowObject = StarknetWindowObject & {
Expand Down Expand Up @@ -64,8 +65,11 @@ export const getArgentStarknetWindowObject = (
return proxyLink.getLoginStatus.mutate()
},
connectWebwallet: (props = {}) => {
const { theme } = props
return proxyLink.connectWebwallet.mutate({ theme })
const { theme, featureFlagIframeProtection } = props
return proxyLink.connectWebwallet.mutate({
theme,
featureFlagIframeProtection,
})
},
connectWebwalletSSO: (token, authorizedPartyId) => {
return proxyLink.connectWebwalletSSO.mutate({ token, authorizedPartyId })
Expand Down
2 changes: 1 addition & 1 deletion src/connectors/webwallet/starknetWindowObject/wormhole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const createModal = async (targetUrl: string, shouldShow: boolean) => {
iframe.setAttribute("allowtransparency", "true")
iframe.setAttribute("transparent", "true")

applyModalStyle(/* modal, */ iframe)
applyModalStyle(iframe)
iframe.style.display = shouldShow ? "block" : "none"

const existingElement = document.getElementById(iframeId)
Expand Down

0 comments on commit 221ca24

Please sign in to comment.