|
| 1 | +import { Badge } from '@/components/ui/badge'; |
1 | 2 | import { Separator } from '@/components/ui/separator'; |
2 | 3 | import { getCoinDetails, getCoinOHLC } from '@/lib/ coingecko.actions'; |
3 | | -import { formatPrice, timeAgo } from '@/lib/utils'; |
4 | | -import { ArrowUpRight } from 'lucide-react'; |
| 4 | +import { cn, formatPercentage, formatPrice, timeAgo } from '@/lib/utils'; |
| 5 | +import { ArrowUpRight, TrendingDown, TrendingUp } from 'lucide-react'; |
5 | 6 |
|
| 7 | +import Image from 'next/image'; |
6 | 8 | import Link from 'next/link'; |
7 | 9 | import { |
8 | 10 | Table, |
@@ -44,11 +46,97 @@ const CoinDetails = async ({ params }: { params: Promise<{ id: string }> }) => { |
44 | 46 | tickers: coinData.tickers, |
45 | 47 | }; |
46 | 48 |
|
| 49 | + const isTrendingUp = coin.priceChangePercentage24h > 0; |
| 50 | + |
47 | 51 | return ( |
48 | 52 | <main className='py-12 container size-full grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 items-center gap-6 xl:gap-10 justify-center'> |
49 | 53 | <section className='size-full xl:col-span-2'> |
50 | | - {/* Coin Details - Live */} |
51 | | - <LiveCoinHeader coinId={coin.id} name={coin.name} image={coin.image} /> |
| 54 | + {/* Coin Details */} |
| 55 | + <div className='space-y-5 w-full'> |
| 56 | + <h3 className='text-3xl font-medium'>{coin.name}</h3> |
| 57 | + <div className='flex gap-3 items-center'> |
| 58 | + <Image |
| 59 | + src={coin.image} |
| 60 | + alt={coin.name} |
| 61 | + width={77} |
| 62 | + height={77} |
| 63 | + className='size-[45px] sm:size-[50px] xl:size-[77px]' |
| 64 | + /> |
| 65 | + <div className='flex gap-4'> |
| 66 | + <h1 className='text-3xl sm:text-5xl xl:text-6xl font-semibold'> |
| 67 | + {formatPrice(coin.price)} |
| 68 | + </h1> |
| 69 | + <Badge |
| 70 | + className={cn( |
| 71 | + 'font-medium mt-2 h-fit py-1 flex items-center gap-1', |
| 72 | + isTrendingUp |
| 73 | + ? 'bg-green-500/20 text-green-600' |
| 74 | + : 'bg-red-500/20 text-red-500' |
| 75 | + )} |
| 76 | + > |
| 77 | + {formatPercentage(coin.priceChangePercentage24h)} |
| 78 | + {isTrendingUp ? <TrendingUp /> : <TrendingDown />} |
| 79 | + (24h) |
| 80 | + </Badge> |
| 81 | + </div> |
| 82 | + </div> |
| 83 | + <div className='grid grid-cols-3 mt-8 gap-4 sm:gap-6 w-fit'> |
| 84 | + {/* Today */} |
| 85 | + <div className='text-base border-r border-purple-600 flex flex-col gap-2'> |
| 86 | + <p className='text-purple-100 max-sm:text-sm'>Today</p> |
| 87 | + <div |
| 88 | + className={cn( |
| 89 | + 'flex flex-1 gap-1 items-end text-sm font-medium', |
| 90 | + { |
| 91 | + 'text-green-500': coin.priceChangePercentage24h > 0, |
| 92 | + 'text-red-500': coin.priceChangePercentage24h < 0, |
| 93 | + } |
| 94 | + )} |
| 95 | + > |
| 96 | + <p>{formatPercentage(coin.priceChangePercentage24h)}</p> |
| 97 | + {isTrendingUp ? ( |
| 98 | + <TrendingUp width={16} height={16} /> |
| 99 | + ) : ( |
| 100 | + <TrendingDown width={16} height={16} /> |
| 101 | + )} |
| 102 | + </div> |
| 103 | + </div> |
| 104 | + {/* 30 Days */} |
| 105 | + <div className='text-base border-r border-purple-600 flex flex-col gap-2'> |
| 106 | + <p className='text-purple-100 max-sm:text-sm'>30 Days</p> |
| 107 | + <div |
| 108 | + className={cn( |
| 109 | + 'flex gap-1 flex-1 items-end text-sm font-medium', |
| 110 | + { |
| 111 | + 'text-green-500': coin.priceChangePercentage30d > 0, |
| 112 | + 'text-red-500': coin.priceChangePercentage30d < 0, |
| 113 | + } |
| 114 | + )} |
| 115 | + > |
| 116 | + <p>{formatPercentage(coin.priceChangePercentage30d)}</p> |
| 117 | + {isTrendingUp ? ( |
| 118 | + <TrendingUp width={16} height={16} /> |
| 119 | + ) : ( |
| 120 | + <TrendingDown width={16} height={16} /> |
| 121 | + )} |
| 122 | + </div> |
| 123 | + </div> |
| 124 | + {/* Rank */} |
| 125 | + <div className='text-base flex flex-col gap-2'> |
| 126 | + <p className='text-purple-100 max-sm:text-sm'> |
| 127 | + Price Change (24h) |
| 128 | + </p> |
| 129 | + <p |
| 130 | + className={cn('flex gap-1 items-center text-sm font-medium', { |
| 131 | + 'text-green-500': coin.priceChange24h > 0, |
| 132 | + 'text-red-500': coin.priceChange24h < 0, |
| 133 | + })} |
| 134 | + > |
| 135 | + {formatPrice(coin.priceChange24h)} |
| 136 | + </p> |
| 137 | + </div> |
| 138 | + </div> |
| 139 | + </div> |
52 | 140 |
|
53 | 141 | <Separator className='my-8 bg-purple-600' /> |
54 | 142 |
|
|
0 commit comments