Skip to content

Commit 054cb9c

Browse files
committed
Logging, debugging, events
1 parent e8a20ae commit 054cb9c

File tree

8 files changed

+140
-10
lines changed

8 files changed

+140
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,4 @@ ia/bayes_general_parameters.py
104104
ia/bayes_profecia_parameters.py
105105
ia/bayes_profecia_destinatario_parameters.py
106106
ia/bayes_profecia_sintetica_parameters.py
107+
apps/nextjs/scripts/html-snapshots

apps/nextjs/app/[lang]/profile/page.tsx

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,17 @@ export default function ProfileForm({ params }: PageProps) {
282282
e.preventDefault()
283283
setSaving(true)
284284

285+
// DEBUG: Log información crítica
286+
console.log('=== PROFILE SAVE DEBUG ===')
287+
console.log('1. Session address:', session?.address)
288+
console.log('2. Wallet address:', address)
289+
console.log('3. Are they equal?', session?.address === address)
290+
console.log('4. User Agent:', navigator.userAgent)
291+
console.log('5. Is OKX Browser?', navigator.userAgent.includes('OKX'))
292+
293+
const csrfToken = await getCsrfToken()
294+
console.log('6. CSRF Token length:', csrfToken?.length)
295+
285296
try {
286297
if (!process.env.NEXT_PUBLIC_API_UPDATE_USER) {
287298
alert('Undefined NEXT_PUBLIC_API_UPDATE_USER')
@@ -294,8 +305,6 @@ export default function ProfileForm({ params }: PageProps) {
294305
religion_id: profile.religion,
295306
pais_id: profile.country,
296307
}
297-
298-
const csrfToken = await getCsrfToken()
299308
let url = process.env.NEXT_PUBLIC_API_UPDATE_USER.replace(
300309
'usuario_id',
301310
profile.userId,
@@ -312,9 +321,31 @@ export default function ProfileForm({ params }: PageProps) {
312321
})
313322

314323
if (!response.ok) {
315-
throw new Error('Failed to save profile')
324+
const errorText = await response.text()
325+
console.log('❌ Profile save failed:', {
326+
status: response.status,
327+
statusText: response.statusText,
328+
error: errorText.substring(0, 500), // Primeros 500 caracteres
329+
url: url,
330+
is_okx: navigator.userAgent.includes('OKX')
331+
})
332+
throw new Error(`Failed to save profile: ${response.status} ${response.statusText}`)
316333
}
317334

335+
// Intentar parsear respuesta JSON para logging
336+
let responseData = null
337+
try {
338+
responseData = await response.json()
339+
} catch (e) {
340+
// No es JSON, usar texto plano
341+
responseData = await response.text()
342+
}
343+
console.log('✅ Profile save successful:', {
344+
status: response.status,
345+
url: url,
346+
is_okx: navigator.userAgent.includes('OKX'),
347+
response: typeof responseData === 'string' ? responseData.substring(0, 200) : responseData
348+
})
318349
alert('Profile updated successfully')
319350
} catch (error) {
320351
alert('Failed to save profile')

apps/nextjs/app/api

Submodule api updated from 40a99db to 6299ab7

apps/nextjs/components/CourseStatistics.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ export function CourseStatistics({
3535
<div className="flex justify-between items-center p-4 mt-auto">
3636
<div>
3737
{
38-
(+scholarshipPerGuide > 0 && address &&
38+
(scholarshipPerGuide !== null && profileScore !== null &&
39+
+scholarshipPerGuide > 0 && address &&
3940
+profileScore > 0) ? (
4041
<div className="p-2">
4142
<span>
4243
{lang === 'es'
4344
? 'Beca de '
4445
: 'Scholarship of '}
45-
{(
46+
{(
4647
(scholarshipPerGuide * 100) /
4748
profileScore
4849
).toFixed(2)}{' '}
@@ -60,7 +61,8 @@ export function CourseStatistics({
6061
</div>
6162
)
6263
}
63-
{+scholarshipPerGuide > 0 && address &&
64+
{scholarshipPerGuide !== null && percentagePaid !== null &&
65+
+scholarshipPerGuide > 0 && address &&
6466
+percentagePaid < 100 && !canSubmit && (
6567
<div className="p-2">
6668
<span className="text-red-500">
@@ -71,7 +73,8 @@ export function CourseStatistics({
7173
</div>
7274
)
7375
}
74-
{scholarshipPerGuide != null && scholarshipPerGuide > 0 && canSubmit &&
76+
{scholarshipPerGuide != null && percentagePaid !== null &&
77+
scholarshipPerGuide > 0 && canSubmit &&
7578
+percentagePaid < 100 && (
7679
<div className="p-2 text-green-600">
7780
<span className="text-green-600">
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
'use client'
2+
3+
import { useAccount } from 'wagmi'
4+
import { useEffect, useState } from 'react'
5+
6+
export default function OKXNetworkCheck() {
7+
const { chainId, address } = useAccount()
8+
const [isOKXBrowser, setIsOKXBrowser] = useState(false)
9+
const [showHelp, setShowHelp] = useState(false)
10+
11+
useEffect(() => {
12+
// Detectar si es navegador interno de OKX
13+
const ua = navigator.userAgent.toLowerCase()
14+
const isOKX = ua.includes('okx') || ua.includes('web3wallet')
15+
setIsOKXBrowser(isOKX)
16+
17+
// Si es OKX y está en red incorrecta, mostrar ayuda
18+
if (isOKX && chainId && chainId !== 42220 && chainId !== 11142220) {
19+
console.log('OKX on wrong network:', chainId)
20+
console.log('User Agent:', navigator.userAgent)
21+
console.log('Address:', address)
22+
setShowHelp(true)
23+
}
24+
}, [chainId])
25+
26+
if (!showHelp) return null
27+
28+
return (
29+
<div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4">
30+
<div className="bg-white rounded-lg p-6 max-w-md w-full">
31+
<h3 className="text-lg font-bold mb-3 text-red-600">
32+
❌ Wrong Network Detected
33+
</h3>
34+
35+
<div className="space-y-3 mb-4">
36+
<p className="text-gray-700">
37+
Your OKX Wallet is connected to the wrong network. Please switch to <strong>Celo</strong> network.
38+
</p>
39+
40+
<div className="bg-yellow-50 border border-yellow-200 rounded p-3">
41+
<h4 className="font-medium mb-1">How to switch in OKX:</h4>
42+
<ol className="list-decimal pl-5 space-y-1 text-sm">
43+
<li>Tap the network name at the top of OKX browser</li>
44+
<li>Select <strong>"Celo"</strong> from the list</li>
45+
<li>If Celo is not listed, tap "Add Network" and enter:</li>
46+
</ol>
47+
<div className="mt-2 text-xs bg-gray-100 p-2 rounded">
48+
<p>Network: <strong>Celo</strong></p>
49+
<p>RPC URL: <strong>https://forno.celo.org</strong></p>
50+
<p>Chain ID: <strong>42220</strong></p>
51+
</div>
52+
</div>
53+
</div>
54+
55+
<div className="flex gap-3">
56+
<button
57+
onClick={() => {
58+
console.log('User clicked "I\'ve switched"')
59+
setShowHelp(false)
60+
}}
61+
className="flex-1 bg-blue-600 text-white py-2 rounded hover:bg-blue-700"
62+
>
63+
I've switched
64+
</button>
65+
<button
66+
onClick={() => {
67+
console.log('User clicked "Open in Chrome"')
68+
window.open(window.location.href, '_blank')
69+
}}
70+
className="flex-1 bg-gray-200 py-2 rounded hover:bg-gray-300"
71+
>
72+
Open in Chrome
73+
</button>
74+
</div>
75+
</div>
76+
</div>
77+
)
78+
}

apps/nextjs/providers/AppProvider.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
'use client'
88

99
import { SessionProvider } from 'next-auth/react'
10+
import { useEffect } from 'react'
11+
import OKXNetworkCheck from '@/components/OKXNetworkCheck'
1012

1113
interface ExtendedWindow extends Window {
1214
ethereum?: {
@@ -85,6 +87,21 @@ const queryClient = new QueryClient()
8587
// Taking ideas of
8688
// https://github.com/0xRowdy/nextauth-siwe-route-handlers/blob/main/src/app/providers/web3-providers.tsx
8789
export function AppProvider(props: RainbowKitProviderProps) {
90+
useEffect(() => {
91+
console.log('=== OKX DIAGNOSTIC INFO ===')
92+
console.log('1. User Agent:', navigator.userAgent)
93+
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
101+
})
102+
}
103+
}, [])
104+
88105
return (
89106
<WagmiProvider config={config}>
90107
<SessionProvider>
@@ -102,6 +119,7 @@ export function AppProvider(props: RainbowKitProviderProps) {
102119
})}
103120
>
104121
{props.children}
122+
<OKXNetworkCheck />
105123
</RainbowKitProvider>
106124
</RainbowKitSiweNextAuthProvider>
107125
</QueryClientProvider>

apps/nextjs/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"allowJs": true,
66
"allowImportingTsExtensions": true,
77
"skipLibCheck": true,
8+
"skipDefaultLibCheck": true,
89
"strict": true,
910
"noEmit": true,
1011
"esModuleInterop": true,
@@ -28,7 +29,6 @@
2829
"next-env.d.ts",
2930
"**/*.ts",
3031
"**/*.tsx",
31-
".next/types/**/*.ts",
3232
"types/**/*.d.ts"
3333
],
3434
"exclude": [

apps/nextjs/tsconfig.test.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"next-env.d.ts",
2828
"**/*.ts",
2929
"**/*.tsx",
30-
".next/types/**/*.ts",
3130
"types/**/*.d.ts",
3231
"**/*.test.ts",
3332
"**/*.test.tsx",

0 commit comments

Comments
 (0)