@@ -2,64 +2,19 @@ import {
22 getCoinDetails ,
33 getCoinOHLC ,
44 fetchPools ,
5- getTopGainersLosers ,
65} from '@/lib/coingecko.actions' ;
7- import { formatPrice , timeAgo } from '@/lib/utils' ;
8- import Link from 'next/link' ;
9- import CoinDetailCard from '@/components/CoinDetailCard' ;
10- import { Tabs , TabsContent , TabsList , TabsTrigger } from '@/components/ui/tabs' ;
11- import {
12- Table ,
13- TableBody ,
14- TableCell ,
15- TableHead ,
16- TableHeader ,
17- TableRow ,
18- } from '@/components/ui/table' ;
196import { Converter } from '@/components/Converter' ;
207import LiveDataWrapper from '@/components/LiveDataWrapper' ;
21- import CoinCard from '@/components/CoinCard' ;
8+ import { ExchangeListings } from '@/components/ExchangeListings' ;
9+ import { CoinDetailsSection } from '@/components/CoinDetailsSection' ;
10+ import { TopGainersLosers } from '@/components/TopGainersLosers' ;
2211
2312const CoinDetails = async ( { params } : { params : Promise < { id : string } > } ) => {
2413 const { id } = await params ;
2514 const coinData = await getCoinDetails ( id ) ;
26- const topGainersLosers = await getTopGainersLosers ( ) ;
2715 const pool = await fetchPools ( id ) ;
2816 const coinOHLCData = await getCoinOHLC ( id , 1 , 'usd' , 'hourly' , 'full' ) ;
2917
30- const coinDetails = [
31- {
32- label : 'Market Cap' ,
33- value : formatPrice ( coinData . market_data . market_cap . usd ) ,
34- } ,
35- {
36- label : 'Market Cap Rank' ,
37- value : `# ${ coinData . market_cap_rank } ` ,
38- } ,
39- {
40- label : 'Total Volume' ,
41- value : formatPrice ( coinData . market_data . total_volume . usd ) ,
42- } ,
43- {
44- label : 'Website' ,
45- value : '-' ,
46- link : coinData . links . homepage [ 0 ] ,
47- linkText : 'Website' ,
48- } ,
49- {
50- label : 'Explorer' ,
51- value : '-' ,
52- link : coinData . links . blockchain_site [ 0 ] ,
53- linkText : 'Explorer' ,
54- } ,
55- {
56- label : 'Community Link' ,
57- value : '-' ,
58- link : coinData . links . subreddit_url ,
59- linkText : 'Community' ,
60- } ,
61- ] ;
62-
6318 return (
6419 < main className = 'coin-details-main' >
6520 < section className = 'size-full xl:col-span-2' >
@@ -69,147 +24,24 @@ const CoinDetails = async ({ params }: { params: Promise<{ id: string }> }) => {
6924 coin = { coinData }
7025 coinOHLCData = { coinOHLCData }
7126 >
72- { /* Exchange Listings - pass it as a child of a client component
73- // so it will be render server side */ }
74- < div className = 'w-full mt-8 space-y-4' >
75- < h4 className = 'section-title' > Exchange Listings</ h4 >
76- < div className = 'custom-scrollbar mt-5 exchange-container' >
77- < Table >
78- < TableHeader className = 'text-purple-100' >
79- < TableRow className = 'hover:bg-transparent' >
80- < TableHead className = 'exchange-header-left' >
81- Exchange
82- </ TableHead >
83- < TableHead className = 'text-purple-100' > Pair</ TableHead >
84- < TableHead className = 'text-purple-100' > Price</ TableHead >
85- < TableHead className = 'exchange-header-right' >
86- Last Traded
87- </ TableHead >
88- </ TableRow >
89- </ TableHeader >
90- < TableBody >
91- { coinData . tickers
92- . slice ( 0 , 7 )
93- . map ( ( ticker : Ticker , index : number ) => (
94- < TableRow
95- key = { index }
96- className = 'overflow-hidden rounded-lg hover:!bg-dark-400/30'
97- >
98- < TableCell className = ' text-green-500 font-bold' >
99- < Link
100- href = { ticker . trade_url }
101- target = '_blank'
102- className = 'exchange-link'
103- >
104- { ticker . market . name }
105- </ Link >
106- </ TableCell >
107- < TableCell >
108- < div className = 'exchange-pair' >
109- < p className = 'truncate max-w-[100px] h-full' >
110- { ticker . base }
111- </ p >
112- /
113- < p className = 'truncate max-w-[100px] h-full ml-2' >
114- { ticker . target }
115- </ p >
116- </ div >
117- </ TableCell >
118- < TableCell className = 'font-medium' >
119- { formatPrice ( ticker . converted_last . usd ) }
120- </ TableCell >
121- < TableCell className = 'exchange-timestamp' >
122- { timeAgo ( ticker . timestamp ) }
123- </ TableCell >
124- </ TableRow >
125- ) ) }
126- </ TableBody >
127- </ Table >
128- </ div >
129- </ div >
27+ { /* Exchange Listings - pass it as a child of a client componentso it will be render server side */ }
28+ < ExchangeListings coinData = { coinData } />
13029 </ LiveDataWrapper >
13130 </ section >
13231
13332 < section className = 'size-full max-lg:mt-8 lg:col-span-1' >
13433 { /* Converter */ }
135- < div className = 'w-full space-y-5' >
136- < h4 className = 'converter-title' >
137- { coinData . symbol . toUpperCase ( ) } Converter
138- </ h4 >
139- < Converter
140- symbol = { coinData . symbol }
141- icon = { coinData . image . small }
142- priceList = { coinData . market_data . current_price }
143- />
144- </ div >
34+ < Converter
35+ symbol = { coinData . symbol }
36+ icon = { coinData . image . small }
37+ priceList = { coinData . market_data . current_price }
38+ />
14539
14640 { /* Coin Details */ }
147- < div className = 'w-full mt-8 space-y-4' >
148- < h4 className = 'section-title pb-3' > Coin Details</ h4 >
149- < div className = 'coin-details-grid' >
150- { coinDetails . map ( ( detail , index ) => (
151- < CoinDetailCard
152- key = { index }
153- label = { detail . label }
154- value = { detail . value }
155- link = { detail . link }
156- linkText = { detail . linkText }
157- />
158- ) ) }
159- </ div >
160- </ div >
41+ < CoinDetailsSection coinData = { coinData } />
16142
16243 { /* Top Gainers / Losers */ }
163- < Tabs defaultValue = 'top-gainers' className = 'mt-8 w-full' >
164- < TabsList className = 'size-full p-1 bg-transparent border-b border-dark-500 rounded-none ' >
165- < TabsTrigger
166- value = 'top-gainers'
167- className = 'data-[state=active]:!border-none data-[state=active]:!bg-transparent flex justify-start !mb-0 py-2 text-lg font-semibold md:text-2xl'
168- >
169- Top Gainers
170- </ TabsTrigger >
171- < TabsTrigger
172- value = 'top-losers'
173- className = 'data-[state=active]:!border-none data-[state=active]:!bg-transparent flex justify-start !mb-0 py-2 text-lg font-semibold md:text-2xl'
174- >
175- Top Losers
176- </ TabsTrigger >
177- </ TabsList >
178- < TabsContent value = 'top-gainers' className = 'top-list' >
179- { topGainersLosers . top_gainers . map (
180- ( coin : TopGainersLosersResponse ) => (
181- < CoinCard
182- key = { coin . id }
183- id = { coin . id }
184- name = { coin . name }
185- symbol = { coin . symbol }
186- image = { coin . image }
187- price = { coin . usd }
188- priceChangePercentage24h = { coin . usd_24h_change }
189- volume24 = { coin . usd_24h_vol }
190- rank = { coin . market_cap_rank }
191- />
192- )
193- ) }
194- </ TabsContent >
195- < TabsContent value = 'top-losers' className = 'top-list' >
196- { topGainersLosers . top_losers . map (
197- ( coin : TopGainersLosersResponse ) => (
198- < CoinCard
199- key = { coin . id }
200- id = { coin . id }
201- name = { coin . name }
202- symbol = { coin . symbol }
203- image = { coin . image }
204- price = { coin . usd }
205- priceChangePercentage24h = { coin . usd_24h_change }
206- volume24 = { coin . usd_24h_vol }
207- rank = { coin . market_cap_rank }
208- />
209- )
210- ) }
211- </ TabsContent >
212- </ Tabs >
44+ < TopGainersLosers />
21345 </ section >
21446 </ main >
21547 ) ;
0 commit comments