11'use client' ;
22
3- import { useCoinPrice } from '@/hooks/useCoinPrice' ;
43import { formatPrice , formatPercentage , cn } from '@/lib/utils' ;
54import Link from 'next/link' ;
65import Image from 'next/image' ;
76import { TrendingUp , TrendingDown } from 'lucide-react' ;
87import { Badge } from './ui/badge' ;
98
109export default function CoinCard ( {
11- coinId ,
10+ id ,
1211 name,
1312 symbol,
1413 image,
15- } : {
16- coinId : string ;
17- name : string ;
18- symbol : string ;
19- image : string ;
20- } ) {
21- const { prices, connected } = useCoinPrice ( [ coinId ] ) ;
22- const priceData = prices [ coinId ] ;
23-
24- const isTrendingUp = priceData
25- ? priceData . priceChangePercentage24h > 0
26- : false ;
14+ price,
15+ priceChangePercentage24h,
16+ volume24,
17+ rank,
18+ } : TopGainersLosers ) {
19+ const isTrendingUp = priceChangePercentage24h > 0 ;
2720
2821 return (
29- < Link href = { `/coins/${ coinId } ` } >
22+ < Link href = { `/coins/${ id } ` } >
3023 < div className = 'bg-dark-500 hover:bg-dark-400/50 transition-all rounded-lg p-5 border border-purple-600/20 hover:border-purple-600/50 cursor-pointer h-fit' >
3124 { /* Header */ }
3225 < div className = 'flex gap-3 mb-4' >
@@ -44,57 +37,37 @@ export default function CoinCard({
4437 </ div >
4538
4639 { /* Price */ }
47- { priceData ? (
48- < >
49- < div className = 'flex justify-between items-center mb-5' >
50- < p className = 'text-2xl font-bold' >
51- { formatPrice ( priceData . price ) }
52- </ p >
53- { /* 24h Change */ }
54- < div className = 'flex items-center gap-2' >
55- < Badge
56- className = { cn (
57- 'font-medium h-fit py-1 flex items-center gap-1' ,
58- isTrendingUp
59- ? 'bg-green-500/20 text-green-600'
60- : 'bg-red-500/20 text-red-500'
61- ) }
62- >
63- { formatPercentage ( priceData . priceChangePercentage24h ) }
64- { isTrendingUp ? < TrendingUp /> : < TrendingDown /> }
65- </ Badge >
66- </ div >
40+ < >
41+ < div className = 'flex justify-between items-center mb-5' >
42+ < p className = 'text-xl font-bold' > { formatPrice ( price , 7 ) } </ p >
43+ { /* 24h Change */ }
44+ < div className = 'flex items-center gap-2' >
45+ < Badge
46+ className = { cn (
47+ 'font-medium h-fit py-1 flex items-center gap-1' ,
48+ isTrendingUp
49+ ? 'bg-green-500/20 text-green-600'
50+ : 'bg-red-500/20 text-red-500'
51+ ) }
52+ >
53+ { formatPercentage ( priceChangePercentage24h ) }
54+ { isTrendingUp ? < TrendingUp /> : < TrendingDown /> }
55+ </ Badge >
6756 </ div >
57+ </ div >
6858
69- { /* Market Stats */ }
70- < div className = 'space-y-3 text-sm' >
71- < div className = 'flex flex-row lg:flex-col xl:flex-row gap-1 justify-between' >
72- < span className = 'text-gray-400' > Market Cap</ span >
73- < span className = 'font-medium' >
74- { formatPrice ( priceData . marketCap ) }
75- </ span >
76- </ div >
77- < div className = 'flex flex-row lg:flex-col xl:flex-row gap-1 justify-between' >
78- < span className = 'text-gray-400' > Volume 24h</ span >
79- < span className = 'font-medium' >
80- { formatPrice ( priceData . volume24h ) }
81- </ span >
82- </ div >
59+ { /* Market Stats */ }
60+ < div className = 'space-y-3' >
61+ < div className = 'flex gap-1 justify-between' >
62+ < span className = 'text-purple-100' > Market Cap Rank</ span >
63+ < span className = 'font-medium' > #{ rank } </ span >
8364 </ div >
84- </ >
85- ) : (
86- // Loading Skeleton
87- < >
88- < div className = 'flex justify-between items-center mb-5' >
89- < div className = 'h-8 w-32 bg-dark-400/50 rounded animate-pulse' />
90- < div className = 'h-7 w-24 bg-dark-400/50 rounded-full animate-pulse' />
65+ < div className = 'flex gap-1 justify-between' >
66+ < span className = 'text-purple-100' > Volume 24h: </ span >
67+ < span className = 'font-medium' > { formatPrice ( volume24 ) } </ span >
9168 </ div >
92- < div className = 'space-y-3 text-sm' >
93- < div className = 'h-5 w-full bg-dark-400/50 rounded animate-pulse' />
94- < div className = 'h-5 w-full bg-dark-400/50 rounded animate-pulse' />
95- </ div >
96- </ >
97- ) }
69+ </ div >
70+ </ >
9871 </ div >
9972 </ Link >
10073 ) ;
0 commit comments