diff --git a/app/modal.tsx b/app/modal.tsx index b6e4c51..9f4e9ce 100644 --- a/app/modal.tsx +++ b/app/modal.tsx @@ -1,40 +1,64 @@ import React, { useEffect, useState } from 'react'; import { motion } from 'framer-motion'; +import axios from 'axios'; interface Detail { token: string; gains: number; price_at_creation: number; price_now: number; + icon_url: string; + ca: string; // Add contract address to the Detail interface } -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 +const Modal: React.FC<{ + isOpen: boolean; + onClose: () => void; + item: { username: string; points: number; img_url: string }; // Include img_url in the item prop + period: string; +}> = ({ isOpen, onClose, item, period }) => { + const [details, setDetails] = useState(null); + const [urls, setUrls] = useState<{ [key: string]: string }>({}); // State to store Dexscreener URLs useEffect(() => { if (isOpen && item) { const fetchDetails = async () => { try { - let urlAddition = ""; - if(period == "Weekly"){ - urlAddition = "_weekly"; - }else if(period == "Monthly"){ - urlAddition = "_monthly"; + 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(); + const data: Detail[] = await response.json(); setDetails(data); + + // Fetch URLs for each detail + const newUrls: { [key: string]: string } = {}; + for (const detail of data) { + try { + const response = await axios.get(`https://api.dexscreener.com/latest/dex/tokens/${detail.ca}`); + if (response.data && response.data.pairs && response.data.pairs.length > 0) { + newUrls[detail.ca] = response.data.pairs[0].url; + } + } catch (error) { + console.error(`Failed to fetch URL for ${detail.ca}:`, error); + } + } + setUrls(newUrls); + } catch (error) { console.error('Failed to fetch user details:', error); } }; - + fetchDetails(); } - }, [isOpen, item]); + }, [isOpen, item, period]); if (!isOpen) return null; @@ -49,9 +73,9 @@ const Modal: React.FC<{ isOpen: boolean; onClose: () => void; item: { username:
-
+
{`${item.username}'s @@ -71,18 +95,30 @@ const Modal: React.FC<{ isOpen: boolean; onClose: () => void; item: { username: {details !== null ? (
{details.map((detail) => ( -

0 ? 'text-green-500' : 'text-red-400' - }`} + href={urls[detail.ca] || '#'} + target="_blank" + rel="noopener noreferrer" + className="block" > - {detail.token}: {parseFloat(detail.gains.toString()).toFixed(2)}x [ - {parseFloat(detail.price_at_creation.toString()).toFixed(8) + - ' => ' + - parseFloat(detail.price_now.toString()).toFixed(8)} - ] -

+

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

+ ))}
) : ( diff --git a/app/page.tsx b/app/page.tsx index 72a3fbb..419f347 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -11,6 +11,9 @@ import CalloutModal from './callout'; import { motion } from 'framer-motion'; import UserDetailModal from "@/components/UserDetailsModal"; +import Header from "@/components/Header"; +import Footer from "@/components/Footer"; + // Helper functions to generate pseudo data const generateRandomName = () => { const names = ["Alice", "Bob", "Charlie", "David", "Eva", "Frank", "Grace", "Hannah", "Ivan", "Judy"]; @@ -178,43 +181,8 @@ const Home: React.FC = () => { return (
-
-
-

CallFi

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

Loading...

- ) : ( - - )} -
-
- +
+ {ready && user?.twitter && !isJoined && (
@@ -285,7 +253,7 @@ const Home: React.FC = () => { className="w-12 h-12 rounded-full mr-4" />
-

openUserDetailModal(item["username"])}>{item["username"]}

+

{item["username"]}

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

@@ -295,13 +263,11 @@ const Home: React.FC = () => {
- + -
-

© 2024 CallFi. All rights reserved.

-
+