Skip to content

Commit 963ecf5

Browse files
committed
Mejora diagnóstico OKX Web3 Wallet: detección de extensión y monitoreo de conexión
- Amplía detección de OKX: window.okxwallet, window.okex, propiedades isOKX/isOkxWallet - Log de propiedades enumerables de window.ethereum - Monitoreo de estado de conexión (address, chainId, connector) - Mejora detección en componente OKXNetworkCheck para extensiones - Mantiene logging para diagnóstico en consola del navegador
1 parent d9066ec commit 963ecf5

File tree

2 files changed

+66
-9
lines changed

2 files changed

+66
-9
lines changed

apps/nextjs/components/OKXNetworkCheck.tsx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,38 @@ export default function OKXNetworkCheck() {
99
const [showHelp, setShowHelp] = useState(false)
1010

1111
useEffect(() => {
12-
// Detectar si es navegador interno de OKX
12+
const win = window as any
13+
// Detectar OKX Wallet (navegador interno o extensión)
14+
let isOKX = false
15+
let detectionMethod = 'none'
16+
1317
const ua = navigator.userAgent.toLowerCase()
14-
const isOKX = ua.includes('okx') || ua.includes('web3wallet')
18+
if (ua.includes('okx') || ua.includes('web3wallet')) {
19+
isOKX = true
20+
detectionMethod = 'userAgent'
21+
} else if (win.ethereum?.isOKX) {
22+
isOKX = true
23+
detectionMethod = 'window.ethereum.isOKX'
24+
} else if (win.ethereum?.isOkxWallet) {
25+
isOKX = true
26+
detectionMethod = 'window.ethereum.isOkxWallet'
27+
} else if (win.okxwallet) {
28+
isOKX = true
29+
detectionMethod = 'window.okxwallet'
30+
} else if (win.okex) {
31+
isOKX = true
32+
detectionMethod = 'window.okex'
33+
}
34+
35+
console.log('OKX Detection:', { isOKX, detectionMethod })
1536
setIsOKXBrowser(isOKX)
1637

1738
// Si es OKX y está en red incorrecta, mostrar ayuda
1839
if (isOKX && chainId && chainId !== 42220 && chainId !== 11142220) {
1940
console.log('OKX on wrong network:', chainId)
2041
console.log('User Agent:', navigator.userAgent)
2142
console.log('Address:', address)
43+
console.log('Detection method:', detectionMethod)
2244
setShowHelp(true)
2345
}
2446
}, [chainId])

apps/nextjs/providers/AppProvider.tsx

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@ import OKXNetworkCheck from '@/components/OKXNetworkCheck'
1313
interface ExtendedWindow extends Window {
1414
ethereum?: {
1515
selectedAddress?: string
16+
isOKX?: boolean
17+
isOkxWallet?: boolean
18+
isMetaMask?: boolean
19+
isRabby?: boolean
20+
isTrust?: boolean
21+
isCoinbaseWallet?: boolean
22+
chainId?: string
23+
networkVersion?: string
1624
}
25+
okxwallet?: any
26+
okex?: any
1727
}
1828
import { AppProps } from 'next/app'
1929
import {
@@ -88,20 +98,45 @@ const queryClient = new QueryClient()
8898
// https://github.com/0xRowdy/nextauth-siwe-route-handlers/blob/main/src/app/providers/web3-providers.tsx
8999
export function AppProvider(props: RainbowKitProviderProps) {
90100
useEffect(() => {
101+
const win = window as ExtendedWindow
91102
console.log('=== OKX DIAGNOSTIC INFO ===')
92103
console.log('1. User Agent:', navigator.userAgent)
93104
console.log('2. Is OKX Browser?', navigator.userAgent.toLowerCase().includes('okx'))
94-
console.log('3. Ethereum provider:', window.ethereum ? 'Present' : 'Absent')
95-
if (window.ethereum) {
96-
console.log('4. Provider details:', {
97-
isOKX: window.ethereum.isOKX,
98-
isMetaMask: window.ethereum.isMetaMask,
99-
chainId: window.ethereum.chainId,
100-
networkVersion: window.ethereum.networkVersion
105+
console.log('3. Ethereum provider:', win.ethereum ? 'Present' : 'Absent')
106+
console.log('4. window.okxwallet:', win.okxwallet ? 'Present' : 'Absent')
107+
console.log('5. window.okex:', win.okex ? 'Present' : 'Absent')
108+
if (win.ethereum) {
109+
console.log('6. Provider details:', {
110+
isOKX: win.ethereum.isOKX,
111+
isOkxWallet: win.ethereum.isOkxWallet,
112+
isMetaMask: win.ethereum.isMetaMask,
113+
isRabby: win.ethereum.isRabby,
114+
isTrust: win.ethereum.isTrust,
115+
isCoinbaseWallet: win.ethereum.isCoinbaseWallet,
116+
chainId: win.ethereum.chainId,
117+
networkVersion: win.ethereum.networkVersion
101118
})
119+
// Log all enumerable properties of window.ethereum
120+
try {
121+
const props = Object.keys(win.ethereum)
122+
console.log('7. window.ethereum properties:', props)
123+
} catch (e) {
124+
console.log('7. Failed to enumerate window.ethereum properties:', e)
125+
}
102126
}
103127
}, [])
104128

129+
// Monitor wallet connection state
130+
const { address, chainId, isConnected, connector } = useAccount()
131+
useEffect(() => {
132+
console.log('=== WALLET CONNECTION STATE ===')
133+
console.log('Address:', address)
134+
console.log('Chain ID:', chainId)
135+
console.log('Is connected:', isConnected)
136+
console.log('Connector:', connector?.name)
137+
console.log('Connector ID:', connector?.id)
138+
}, [address, chainId, isConnected, connector])
139+
105140
return (
106141
<WagmiProvider config={config}>
107142
<SessionProvider>

0 commit comments

Comments
 (0)