import React, { useEffect, useState } from 'react'; import { motion } from 'framer-motion'; interface Detail { token: string; gains: number; price_at_creation: number; price_now: number; } const Modal: React.FC<{ isOpen: boolean; onClose: () => void; item: { username: string; points: number }; period:string; }> = ({ isOpen, onClose, item, period }) => { const [details, setDetails] = useState(null); // Specify null as the initial type useEffect(() => { if (isOpen && item) { const fetchDetails = async () => { try { let urlAddition = ""; if(period == "Weekly"){ urlAddition = "_weekly"; }else if(period == "Monthly"){ urlAddition = "_monthly"; } const response = await fetch(`https://api.callfi.io/get_user_callouts${urlAddition}.php?tag=${item.username}`); if (!response.ok) { throw new Error('Network response was not ok'); } const data = await response.json(); setDetails(data); } catch (error) { console.error('Failed to fetch user details:', error); } }; fetchDetails(); } }, [isOpen, item]); if (!isOpen) return null; return (
{`${item.username}'s

{item.username}s Callouts

0 ? 'text-green-500' : 'text-red-500' }`} > Total Gains : {parseFloat(item.points.toString()).toFixed(2)} x

{details !== null ? (
{details.map((detail) => (

0 ? 'text-green-500' : 'text-red-400' }`} > {detail.token}: {parseFloat(detail.gains.toString()).toFixed(2)}x [ {parseFloat(detail.price_at_creation.toString()).toFixed(8) + ' => ' + parseFloat(detail.price_now.toString()).toFixed(8)} ]

))}
) : (

Loading...

)}
); }; export default Modal;