-
Notifications
You must be signed in to change notification settings - Fork 0
feature: Top Categories #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import React from 'react'; | ||
| import { fetcher, getPools } from '@/lib/coingecko.actions'; | ||
| import Link from 'next/link'; | ||
| import { ArrowUpRight } from 'lucide-react'; | ||
| import { formatCurrency } from '@/lib/utils'; | ||
| import LiveDataWrapper from '@/components/LiveDataWrapper'; | ||
| import Converter from '@/components/Converter'; | ||
| import TopGainersLosers from '@/components/TopGainersLosers'; | ||
| // import Converter from '@/components/Converter'; | ||
|
|
||
| const Page = async ({ params }: NextPageProps) => { | ||
| const { id } = await params; | ||
|
|
||
| const [coinData, coinOHLCData] = await Promise.all([ | ||
| fetcher<CoinDetailsData>(`/coins/${id}`, { | ||
| dex_pair_format: 'contract_address', | ||
| }), | ||
| fetcher<OHLCData>(`/coins/${id}/ohlc`, { | ||
| vs_currency: 'usd', | ||
| days: 1, | ||
| // interval: 'hourly', | ||
| precision: 'full', | ||
| }), | ||
| ]); | ||
|
|
||
| const platform = coinData.asset_platform_id | ||
| ? coinData.detail_platforms?.[coinData.asset_platform_id] | ||
| : null; | ||
| const network = platform?.geckoterminal_url.split('/')[3] || null; | ||
| const contractAddress = platform?.contract_address || null; | ||
|
|
||
| const pool = await getPools(id, network, contractAddress); | ||
|
|
||
| const coinDetails = [ | ||
| { | ||
| label: 'Market Cap', | ||
| value: formatCurrency(coinData.market_data.market_cap.usd), | ||
| }, | ||
| { | ||
| label: 'Market Cap Rank', | ||
| value: `# ${coinData.market_cap_rank}`, | ||
| }, | ||
| { | ||
| label: 'Total Volume', | ||
| value: formatCurrency(coinData.market_data.total_volume.usd), | ||
| }, | ||
| { | ||
| label: 'Website', | ||
| value: '-', | ||
| link: coinData.links.homepage[0], | ||
| linkText: 'Homepage', | ||
| }, | ||
| { | ||
| label: 'Explorer', | ||
| value: '-', | ||
| link: coinData.links.blockchain_site[0], | ||
| linkText: 'Explorer', | ||
| }, | ||
| { | ||
| label: 'Community', | ||
| value: '-', | ||
| link: coinData.links.subreddit_url, | ||
| linkText: 'Community', | ||
| }, | ||
| ]; | ||
|
|
||
| return ( | ||
| <main id="coin-details-page"> | ||
| <section className="primary"> | ||
| <LiveDataWrapper | ||
| coinId={id} | ||
| poolId={pool.id} | ||
| coin={coinData} | ||
| coinOHLCData={coinOHLCData} | ||
| > | ||
| <h4>Exchange Listings</h4> | ||
| </LiveDataWrapper> | ||
| </section> | ||
|
|
||
| <section className="secondary"> | ||
| <Converter | ||
| symbol={coinData.symbol} | ||
| icon={coinData.image.small} | ||
| priceList={coinData.market_data.current_price} | ||
| /> | ||
|
|
||
| <div className="details"> | ||
| <h4>Coin Details</h4> | ||
|
|
||
| <ul className="details-grid"> | ||
| {coinDetails.map(({ label, value, link, linkText }, index) => ( | ||
| <li key={index}> | ||
| <p className={label}>{label}</p> | ||
|
|
||
| {link ? ( | ||
| <div className="link"> | ||
| <Link href={link} target="_blank"> | ||
| {linkText || label} | ||
| </Link> | ||
| <ArrowUpRight size={16} /> | ||
| </div> | ||
| ) : ( | ||
| <p className="text-base font-medium">{value}</p> | ||
| )} | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| </div> | ||
| <TopGainersLosers /> | ||
| </section> | ||
| </main> | ||
| ); | ||
| }; | ||
| export default Page; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import { fetcher } from '@/lib/coingecko.actions'; | ||
| import Image from 'next/image'; | ||
| import Link from 'next/link'; | ||
|
|
||
| import { cn, formatPercentage, formatCurrency } from '@/lib/utils'; | ||
| import DataTable from '@/components/DataTable'; | ||
| import CoinsPagination from '@/components/CoinsPagination'; | ||
|
|
||
| const Coins = async ({ searchParams }: NextPageProps) => { | ||
| const { page } = await searchParams; | ||
|
|
||
| const currentPage = Number(page) || 1; | ||
| const perPage = 10; | ||
| const totalCoins = 1000; | ||
| const totalPages = totalCoins / perPage; | ||
|
|
||
| const coinsData = await fetcher<CoinMarketData[]>('/coins/markets', { | ||
| vs_currency: 'usd', | ||
| order: 'market_cap_desc', | ||
| per_page: perPage, | ||
| page: currentPage, | ||
| sparkline: 'false', | ||
| price_change_percentage: '24h', | ||
| }); | ||
|
|
||
| const columns: DataTableColumn<CoinMarketData>[] = [ | ||
| { | ||
| header: 'Rank', | ||
| cellClassName: 'rank-cell', | ||
| cell: (coin) => ( | ||
| <> | ||
| #{coin.market_cap_rank} | ||
| <Link href={`/coins/${coin.id}`} aria-label="View coin" /> | ||
| </> | ||
| ), | ||
| }, | ||
| { | ||
| header: 'Token', | ||
| cellClassName: 'token-cell', | ||
| cell: (coin) => ( | ||
| <div className="token-info"> | ||
| <Image src={coin.image} alt={coin.name} width={36} height={36} /> | ||
| <p> | ||
| {coin.name} ({coin.symbol.toUpperCase()}) | ||
| </p> | ||
| </div> | ||
| ), | ||
| }, | ||
| { | ||
| header: 'Price', | ||
| cellClassName: 'price-cell', | ||
| cell: (coin) => formatCurrency(coin.current_price), | ||
| }, | ||
| { | ||
| header: '24h Change', | ||
| cellClassName: 'change-cell', | ||
| cell: (coin) => { | ||
| const isTrendingUp = coin.price_change_percentage_24h > 0; | ||
|
|
||
| return ( | ||
| <span | ||
| className={cn('change-value', { | ||
| 'text-green-600': isTrendingUp, | ||
| 'text-red-500': !isTrendingUp, | ||
| })} | ||
| > | ||
| {isTrendingUp && '+'} | ||
| {formatPercentage(coin.price_change_percentage_24h)} | ||
| </span> | ||
| ); | ||
| }, | ||
| }, | ||
| { | ||
| header: 'Market Cap', | ||
| cellClassName: 'market-cap-cell', | ||
| cell: (coin) => formatCurrency(coin.market_cap), | ||
| }, | ||
| ]; | ||
|
|
||
| return ( | ||
| <main id="coins-page"> | ||
| <div className="content"> | ||
| <h4>All Coins</h4> | ||
|
|
||
| <DataTable | ||
| tableClassName="coins-table" | ||
| columns={columns} | ||
| data={coinsData} | ||
| rowKey={(coin) => coin.id} | ||
| /> | ||
|
|
||
| <CoinsPagination currentPage={currentPage} totalPages={totalPages} /> | ||
| </div> | ||
| </main> | ||
| ); | ||
| }; | ||
|
|
||
| export default Coins; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.