"use client"; import React, { useState, useEffect } from "react"; import { SunIcon, MoonIcon } from "@heroicons/react/solid"; import { PrivyProvider, usePrivy } from "@privy-io/react-auth"; import { FaTwitter, FaWallet } from "react-icons/fa"; import { CheckIcon } from "@heroicons/react/outline"; import Modal from './modal'; import CalloutModal from './callout'; import { motion } from 'framer-motion'; // Helper functions to generate pseudo data const generateRandomName = () => { const names = ["Alice", "Bob", "Charlie", "David", "Eva", "Frank", "Grace", "Hannah", "Ivan", "Judy"]; return names[Math.floor(Math.random() * names.length)]; }; const generateRandomCoin = () => { const coins = ["Bitcoin", "Ethereum", "Litecoin", "Ripple", "Cardano", "Polkadot", "Solana", "Chainlink"]; return coins[Math.floor(Math.random() * coins.length)]; }; const generateRandomPoint = () => { return Math.floor(Math.random() * (100 - 10 + 1)) + 10; }; function Home() { const [modalOpen, setModalOpen] = useState(false); const { login, user, ready, logout, linkTwitter, unlinkTwitter, linkWallet, unlinkWallet } = usePrivy(); const [darkMode, setDarkMode] = useState(true); const [twitterConnected, setTwitterConnected] = useState(false); // State to track Twitter connection const [walletConnected, setWalletConnected] = useState(false); // State to track Wallet connection const [incrementNumber, setIncrementNumber] = useState(1); const [leaderboardData, setLeaderboardData] = useState([]); const [isJoined, setIsJoined] = useState(false); const [selectedItem, setSelectedItem] = useState(null); // State to store selected leaderboard item const [newCallModalOpen, setNewCallModalOpen] = useState(false); // Function to handle opening modal and setting selected item const openModal = (item) => { setSelectedItem(item); setModalOpen(true); }; // Function to handle closing modal const closeModal = () => { setSelectedItem(null); setModalOpen(false); }; const openNewCallModal = () => { setNewCallModalOpen(true); }; const closeNewCallModal = () => { setNewCallModalOpen(false); }; const handleNewCallSubmit = (tokenId) => { const twitterIntentURL = `https://x.com/intent/tweet?text=%24${tokenId}%20is%20Booming%20rn%21%20See%20ya%20on%20the%20moon%21%0A%0A%23CallFi%20%23CallingIt`; window.open(twitterIntentURL, '_blank'); }; useEffect(() => { if (darkMode) { document.documentElement.classList.add("dark"); } else { document.documentElement.classList.remove("dark"); } }, [darkMode]); useEffect(() => { const fetchData = async () => { try { const response = await fetch('https://api.callfi.io/get_leaderboard.php'); if (!response.ok) { throw new Error('Network response was not ok'); } const data = await response.json(); console.log('Leaderboard data:', data); setLeaderboardData(data); } catch (error) { console.error('Failed to fetch leaderboard data:', error); } }; // Fetch data immediately on mount fetchData(); // Set up the interval to fetch data every 5 seconds const intervalId = setInterval(() => { setIncrementNumber((prevNumber) => prevNumber + 1); fetchData(); }, 5000); // Clean up the interval on component unmount return () => clearInterval(intervalId); }, []); const toggleDarkMode = () => { setDarkMode(!darkMode); document.documentElement.classList.toggle("dark", !darkMode); }; const postLoginAPI = async (usertag) => { try { const response = await fetch('https://api.callfi.io/register_twitter_user.php?tag=' + usertag); if (!response.ok) { throw new Error('Network response was not ok'); } const data = await response.json(); console.log('API call successful:', data); setTwitterConnected(true); // Set Twitter connection state to true on successful API call } catch (error) { console.error('Error during API call:', error); } try{ const response = await fetch('https://api.callfi.io/check_user_approved.php?tag=' + usertag); const responseTxt = await response.text(); if(responseTxt == "1"){ setIsJoined(true); } }catch(error){ } }; useEffect(() => { if (ready && user) { const username = user.twitter?.username ? `@${user.twitter.username}` : '@unknownUser'; if (username !== "@unknownUser") { postLoginAPI(username); } // Assume we have a way to check if the wallet is connected const walletStatus = user.wallet; // This is an assumption; replace it with actual wallet connection check if (walletStatus) { setWalletConnected(true); } } }, [ready, user]); return ( // ${darkMode ? "bg-black text-white" : "bg-white text-black"}

CallFi

{ready && user ? (
) : !ready ? (

Loading...

) : ( )}
{/* Note card */} { ready && user?.twitter && !isJoined &&(

Join the Leaderboard

Get on the leaderboard by posting a tweet!

) } { ready && user?.twitter && isJoined &&(

Feeling Lucky?

Make a callout to a token you believe in!!

) } { ready && !user?.twitter && (

Join the Leaderboard

Start by linking your Twitter account!

{user ? ( ) : ( )}
) } {/* Leaderboard */}
{leaderboardData.map((item) => (
= 0 ? 'positive' : 'negative'} mx-auto mb-4`} onClick={() => openModal(item)}>

{item["username"]}

{parseFloat(item["points"]).toFixed(2)}x

))}
{/* Modal */} {/* Rest of your Home component */}
); } export default function App() { return ( ); }