Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function getInjectedConnectors(connectors: readonly Connector[]) {
}

type InjectableConnector = Connector & { isInjected?: boolean }

export function useOrderedConnections(): InjectableConnector[] {
const { connectors } = useConnect()

Expand Down Expand Up @@ -77,6 +78,35 @@ export function useOrderedConnections(): InjectableConnector[] {
return injectedConnectorsWithoutHardcoded.filter(c => c.id !== CONNECTION.PORTO)
}

// Special-case: On mobile inside an iframe (e.g. partner-swap), dApp browser wallets cannot
// inject window.ethereum or fire EIP-6963 events across cross-origin iframe boundaries.
// Without a real injected connector, hardcoded connectors just open install pages which is
// useless inside a dApp browser. Show only WalletConnect (+ fallback injected if ethereum
// is somehow available) so the user can connect via deep link.
let isInIframe = false
try {
isInIframe = window.self !== window.top
} catch {
// cross-origin iframe will throw on accessing window.top
isInIframe = true
}
if (isMobile && isInIframe) {
const hasRealInjected = injectedConnectorsWithoutHardcoded.some(
c => c.id !== CONNECTION.INJECTED_CONNECTOR_ID && c.id !== CONNECTION.PORTO,
)
if (!hasRealInjected) {
const result: InjectableConnector[] = []
if (Boolean(window.ethereum)) {
const fallbackInjector = injectedConnectorsWithoutHardcoded.find(
c => c.id === CONNECTION.INJECTED_CONNECTOR_ID,
)
if (fallbackInjector) result.push(fallbackInjector)
}
result.push(walletConnectConnector)
return result
}
}

// Special-case: Only display the Coinbase connector in the Coinbase Wallet.
if (isCoinbaseWalletBrowser) {
return [coinbaseSdkConnector]
Expand Down
Loading