Skip to content

Commit 9d3bd86

Browse files
committed
zd
1 parent 46f1849 commit 9d3bd86

3 files changed

Lines changed: 23 additions & 23 deletions

File tree

app/layout.tsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,6 @@ export default function RootLayout({
3838
<html lang="en" suppressHydrationWarning>
3939
<body className={`font-sans ${GeistSans.variable} ${GeistMono.variable} pb-20 lg:pb-0`}>
4040
<Script src="https://sdk.minepi.com/pi-sdk.js" strategy="beforeInteractive" />
41-
<Script id="pi-init" strategy="afterInteractive">
42-
{`
43-
console.log('Pi initialization script running...');
44-
console.log('Pi SDK available:', !!window.Pi);
45-
46-
if (window.Pi) {
47-
console.log('Pi SDK loaded, initializing...');
48-
window.Pi.init({ version: "2.0" });
49-
console.log('Pi SDK initialized successfully');
50-
} else {
51-
console.warn('Pi SDK not available - this app requires Pi Browser');
52-
}
53-
`}
54-
</Script>
5541
<PiProvider>
5642
<BalanceRefreshProvider>
5743
<ThemeProvider attribute="class" defaultTheme="dark" enableSystem>

components/providers/pi-provider.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-nocheck
22
"use client"
33

4-
import { createContext, useContext, useEffect, useState, type ReactNode } from "react"
4+
import { createContext, useContext, useEffect, useRef, useState, type ReactNode } from "react"
55
import { approvePiPayment, completePiPayment, cancelPiPayment } from "@/lib/api/pi-payments"
66

77
interface PiUser {
@@ -42,11 +42,10 @@ export function PiProvider({ children }: { children: ReactNode }) {
4242
const [authResult, setAuthResult] = useState<PiAuthResult | null>(null)
4343
const [isAuthenticated, setIsAuthenticated] = useState(false)
4444
const [isLoading, setIsLoading] = useState(false)
45+
const autoAuthAttempted = useRef(false)
4546

4647
useEffect(() => {
4748
if (typeof window === "undefined") return
48-
// No auto-login: clear saved Pi auth so user must explicitly connect.
49-
// Do not clear zyradex-wallet-address - that can disrupt wallet display before re-auth.
5049
const savedToken = localStorage.getItem("pi_access_token")
5150
const savedUser = localStorage.getItem("pi_user")
5251
if (savedToken && savedUser) {
@@ -60,6 +59,22 @@ export function PiProvider({ children }: { children: ReactNode }) {
6059
}
6160
}, [])
6261

62+
useEffect(() => {
63+
if (autoAuthAttempted.current) return
64+
if (typeof window === "undefined") return
65+
if (!window.Pi) return
66+
67+
autoAuthAttempted.current = true
68+
69+
const timer = setTimeout(() => {
70+
authenticate().catch(() => {
71+
// silent — user can manually sign in via button
72+
})
73+
}, 500)
74+
75+
return () => clearTimeout(timer)
76+
}, [])
77+
6378
const authenticate = async (): Promise<PiAuthResult> => {
6479
if (typeof window === "undefined") {
6580
throw new Error("Window not available. Please refresh the page.")
@@ -71,17 +86,16 @@ export function PiProvider({ children }: { children: ReactNode }) {
7186

7287
setIsLoading(true)
7388
try {
74-
window.Pi.init({ version: "2.0" })
89+
await window.Pi.init({ version: "2.0" })
7590

7691
const onIncompletePaymentFound = (payment: any) => {
7792
console.log("Incomplete payment found:", payment)
78-
// Fire-and-forget: don't block authenticate if cancel fails
7993
cancelPiPayment(payment.identifier).catch((err) =>
8094
console.error("Error cancelling incomplete payment:", err)
8195
)
8296
}
8397

84-
const auth = await window.Pi.authenticate(["username", "payments", "wallet_address"], onIncompletePaymentFound)
98+
const auth = await window.Pi.authenticate(["username"], onIncompletePaymentFound)
8599

86100
if (!auth?.accessToken) {
87101
throw new Error("No access token received from Pi SDK")

next.config.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/** @type {import('next').NextConfig} */
22
const nextConfig = {
3-
eslint: {
4-
ignoreDuringBuilds: true,
5-
},
63
typescript: {
74
ignoreBuildErrors: true,
85
},
96
images: {
107
unoptimized: true,
118
},
9+
turbopack: {
10+
root: import.meta.dirname,
11+
},
1212
}
1313

1414
export default nextConfig

0 commit comments

Comments
 (0)