|
| 1 | +import Link from 'next/link'; |
| 2 | +import { ArrowUpRight } from 'lucide-react'; |
| 3 | + |
1 | 4 | import { |
2 | 5 | getCoinDetails, |
3 | 6 | getCoinOHLC, |
4 | 7 | fetchPools, |
5 | 8 | fetchTopPool, |
6 | 9 | } from '@/lib/coingecko.actions'; |
7 | | -import { Converter } from '@/components/Converter'; |
| 10 | +import { Converter } from '@/components/coin-details/Converter'; |
8 | 11 | import LiveDataWrapper from '@/components/LiveDataWrapper'; |
9 | | -import { ExchangeListings } from '@/components/ExchangeListings'; |
10 | | -import { CoinDetailsSection } from '@/components/CoinDetailsSection'; |
11 | | -import { TopGainersLosers } from '@/components/TopGainersLosers'; |
| 12 | +import { TopGainersLosers } from '@/components/coin-details/TopGainersLosers'; |
| 13 | +import { DataTable } from '@/components/DataTable'; |
| 14 | +import { formatPrice, timeAgo } from '@/lib/utils'; |
12 | 15 |
|
13 | 16 | const CoinDetails = async ({ params }: { params: Promise<{ id: string }> }) => { |
14 | 17 | const { id } = await params; |
15 | 18 | const coinData = await getCoinDetails(id); |
| 19 | + |
16 | 20 | const pool = coinData.asset_platform_id |
17 | 21 | ? await fetchTopPool(coinData.asset_platform_id, coinData.contract_address) |
18 | 22 | : await fetchPools(id); |
| 23 | + |
19 | 24 | const coinOHLCData = await getCoinOHLC(id, 1, 'usd', 'hourly', 'full'); |
20 | 25 |
|
| 26 | + const coinDetails = [ |
| 27 | + { |
| 28 | + label: 'Market Cap', |
| 29 | + value: formatPrice(coinData.market_data.market_cap.usd), |
| 30 | + }, |
| 31 | + { |
| 32 | + label: 'Market Cap Rank', |
| 33 | + value: `# ${coinData.market_cap_rank}`, |
| 34 | + }, |
| 35 | + { |
| 36 | + label: 'Total Volume', |
| 37 | + value: formatPrice(coinData.market_data.total_volume.usd), |
| 38 | + }, |
| 39 | + { |
| 40 | + label: 'Website', |
| 41 | + value: '-', |
| 42 | + link: coinData.links.homepage[0], |
| 43 | + linkText: 'Website', |
| 44 | + }, |
| 45 | + { |
| 46 | + label: 'Explorer', |
| 47 | + value: '-', |
| 48 | + link: coinData.links.blockchain_site[0], |
| 49 | + linkText: 'Explorer', |
| 50 | + }, |
| 51 | + { |
| 52 | + label: 'Community Link', |
| 53 | + value: '-', |
| 54 | + link: coinData.links.subreddit_url, |
| 55 | + linkText: 'Community', |
| 56 | + }, |
| 57 | + ]; |
| 58 | + |
| 59 | + const exchangeColumns = [ |
| 60 | + { |
| 61 | + header: 'Exchange', |
| 62 | + cellClassName: 'exchange-name', |
| 63 | + cell: (ticker: Ticker) => ( |
| 64 | + <> |
| 65 | + {ticker.market.name} |
| 66 | + |
| 67 | + <Link |
| 68 | + href={ticker.trade_url} |
| 69 | + target='_blank' |
| 70 | + aria-label='View coin' |
| 71 | + /> |
| 72 | + </> |
| 73 | + ), |
| 74 | + }, |
| 75 | + { |
| 76 | + header: 'Pair', |
| 77 | + cell: (ticker: Ticker) => ( |
| 78 | + <div className='pair'> |
| 79 | + <p>{ticker.base}</p> |
| 80 | + <p>{ticker.target}</p> |
| 81 | + </div> |
| 82 | + ), |
| 83 | + }, |
| 84 | + { |
| 85 | + header: 'Price', |
| 86 | + cellClassName: 'price-cell', |
| 87 | + cell: (ticker: Ticker) => formatPrice(ticker.converted_last.usd), |
| 88 | + }, |
| 89 | + { |
| 90 | + header: 'Last Traded', |
| 91 | + headClassName: 'text-end', |
| 92 | + cellClassName: 'time-cell', |
| 93 | + cell: (ticker: Ticker) => timeAgo(ticker.timestamp), |
| 94 | + }, |
| 95 | + ]; |
| 96 | + |
21 | 97 | return ( |
22 | | - <main className='coin-details-main'> |
23 | | - <section className='size-full xl:col-span-2'> |
| 98 | + <main id='coin-details-page'> |
| 99 | + <section className='primary'> |
24 | 100 | <LiveDataWrapper |
25 | 101 | coinId={id} |
26 | 102 | poolId={pool.id} |
27 | 103 | coin={coinData} |
28 | 104 | coinOHLCData={coinOHLCData} |
29 | 105 | > |
30 | | - {/* Exchange Listings - pass it as a child of a client component so it will be render server side */} |
31 | | - <ExchangeListings coinData={coinData} /> |
| 106 | + <div className='exchange-section'> |
| 107 | + <h4>Exchange Listings</h4> |
| 108 | + |
| 109 | + <DataTable |
| 110 | + tableClassName='exchange-table' |
| 111 | + columns={exchangeColumns} |
| 112 | + data={coinData.tickers.slice(0, 7)} |
| 113 | + rowKey={(_, index) => index} |
| 114 | + bodyCellClassName='py-2!' |
| 115 | + /> |
| 116 | + </div> |
32 | 117 | </LiveDataWrapper> |
33 | 118 | </section> |
34 | 119 |
|
35 | | - <section className='size-full max-lg:mt-8 lg:col-span-1'> |
36 | | - {/* Converter */} |
| 120 | + <section className='secondary'> |
37 | 121 | <Converter |
38 | 122 | symbol={coinData.symbol} |
39 | 123 | icon={coinData.image.small} |
40 | 124 | priceList={coinData.market_data.current_price} |
41 | 125 | /> |
42 | 126 |
|
43 | | - {/* Coin Details */} |
44 | | - <CoinDetailsSection coinData={coinData} /> |
| 127 | + <div className='details'> |
| 128 | + <h4>Coin Details</h4> |
| 129 | + |
| 130 | + <ul className='details-grid'> |
| 131 | + {coinDetails.map(({ label, value, link, linkText }, index) => ( |
| 132 | + <li key={index}> |
| 133 | + <p className='label'>{label}</p> |
| 134 | + |
| 135 | + {link ? ( |
| 136 | + <div className='link'> |
| 137 | + <Link href={link} target='_blank'> |
| 138 | + {linkText || label} |
| 139 | + </Link> |
| 140 | + <ArrowUpRight size={16} /> |
| 141 | + </div> |
| 142 | + ) : ( |
| 143 | + <p className='text-base font-medium'>{value}</p> |
| 144 | + )} |
| 145 | + </li> |
| 146 | + ))} |
| 147 | + </ul> |
| 148 | + </div> |
45 | 149 |
|
46 | | - {/* Top Gainers / Losers */} |
47 | 150 | <TopGainersLosers /> |
48 | 151 | </section> |
49 | 152 | </main> |
|
0 commit comments