/ apps / web / src / App.tsx
App.tsx
 1  import { useEffect } from 'react'
 2  import { HashRouter as Router, Routes, Route, Navigate } from 'react-router-dom'
 3  import { litProtocolService } from './lib/litProtocol'
 4  import { HomePage } from './pages/HomePage'
 5  import { GeniusSongPage } from './pages/GeniusSongPage'
 6  import { PricingPage } from './pages/PricingPage'
 7  import { StudyPageV2 } from './pages/StudyPageV2'
 8  import { SongStudyPage } from './pages/SongStudyPage'
 9  import { AccountPage } from './pages/AccountPage'
10  import { ChatPage } from './components/Chat/ChatPage'
11  import { PGLiteProvider } from './contexts/PGLiteContext'
12  import { AltchaProtectionSimple } from './components/AltchaProtectionSimple'
13  import { Toaster } from './components/ui/sonner'
14  import { UmamiTracker } from './components/UmamiTracker'
15  
16  // Wildcard capacity delegation auth sig - works for ANY wallet address
17  // const CAPACITY_DELEGATION_AUTH_SIG = {
18  //   sig: "0xc4100824146920b590969df03a40c879d667307c8ef04897d183509a552f00865984d0562a36a26df40b806b72167321a5bb3492f49bae6e5917ea55bbd7a2421b",
19  //   derivedVia: "web3.eth.personal.sign",
20  //   signedMessage: "localhost wants you to sign in with your Ethereum account:\n0x0C6433789d14050aF47198B2751f6689731Ca79C\n\nThis is a test statement.  You can put anything you want here. I further authorize the stated URI to perform the following actions on my behalf: (1) 'Auth': 'Auth' for 'lit-ratelimitincrease://235258'.\n\nURI: lit:capability:delegation\nVersion: 1\nChain ID: 1\nNonce: 0x407060c7d34ab59697984f6a9048844d2633219e43823b6649a3f4c0df6c05c7\nIssued At: 2025-07-13T09:38:48.199Z\nExpiration Time: 2025-07-20T09:38:48.194Z\nResources:\n- urn:recap:eyJhdHQiOnsibGl0LXJhdGVsaW1pdGluY3JlYXNlOi8vMjM1MjU4Ijp7IkF1dGgvQXV0aCI6W3sibmZ0X2lkIjpbIjIzNTI1OCJdLCJ1c2VzIjoiMTAwMDAifV19fSwicHJmIjpbXX0",
21  //   address: "0x0C6433789d14050aF47198B2751f6689731Ca79C"
22  // }
23  
24  function App() {
25    // Lit Protocol will be initialized on-demand when needed
26    useEffect(() => {
27      return () => {
28        // Clean up on unmount if connected
29        if (litProtocolService.litNodeClient) {
30          litProtocolService.disconnect()
31        }
32      }
33    }, [])
34    
35    // Signal Farcaster Mini App ready after component mounts
36    useEffect(() => {
37      console.log('🎯 [v2] App mounted, checking for SDK...')
38      // Check if we have the Farcaster SDK
39      if (window.farcasterSDK) {
40        console.log('🎯 [v2] SDK found, waiting 100ms before calling ready()')
41        // Small delay to ensure all child components are rendered
42        const timer = setTimeout(() => {
43          console.log('🎯 [v2] Calling ready() now...')
44          window.farcasterSDK.actions.ready()
45            .then(() => {
46              console.log('🎯 [v2] Farcaster Mini App ready signal sent successfully!')
47            })
48            .catch((err: any) => {
49              console.error('🎯 [v2] Failed to send ready signal to Farcaster:', err)
50            })
51        }, 100)
52        
53        return () => clearTimeout(timer)
54      } else {
55        console.log('🎯 [v2] No SDK found, not calling ready()')
56      }
57    }, [])
58    
59  
60    return (
61      <AltchaProtectionSimple
62        logoSrc="/scarlett-wink.png"
63        title="Security Check"
64        subtitle="Scarlett is making sure you're a friend..."
65        onVerified={() => {
66          // Only log on initial verification to reduce noise
67          if (!sessionStorage.getItem('altcha_logged')) {
68            console.log('✅ ALTCHA verification complete');
69            sessionStorage.setItem('altcha_logged', 'true');
70          }
71        }}
72      >
73        <PGLiteProvider>
74          <Router>
75            <UmamiTracker />
76            <Routes>
77              <Route path="/" element={<HomePage />} />
78              <Route path="/pricing" element={<PricingPage />} />
79              <Route path="/study" element={<StudyPageV2 />} />
80              <Route path="/study/:songId" element={<SongStudyPage />} />
81              <Route path="/account" element={<AccountPage />} />
82              <Route path="/chat" element={<ChatPage />} />
83              <Route path="/gs/:geniusId" element={<GeniusSongPage />} />
84              {/* Catch all - redirect to home */}
85              <Route path="*" element={<Navigate to="/" replace />} />
86            </Routes>
87            </Router>
88            <Toaster />
89        </PGLiteProvider>
90      </AltchaProtectionSimple>
91    )
92  }
93  
94  export default App