add more insight data and buy button
This commit is contained in:
parent
ef12fb2b7c
commit
db2f507830
|
@ -349,9 +349,9 @@ const JupiterForm: FunctionComponent = () => {
|
|||
|
||||
return (
|
||||
<div className="grid grid-cols-12 lg:space-x-4">
|
||||
<div className="col-span-12 lg:col-span-10 lg:col-start-2 ">
|
||||
<div className="col-span-12 xl:col-span-10 xl:col-start-2 ">
|
||||
<div className="flex flex-col md:flex-row md:space-x-6">
|
||||
<div className="w-full md:w-1/2 xl:w-1/3">
|
||||
<div className="w-full md:w-1/2 lg:w-1/3">
|
||||
<div className="relative z-10">
|
||||
{connected &&
|
||||
walletTokensWithInfos.length &&
|
||||
|
@ -1172,7 +1172,7 @@ const JupiterForm: FunctionComponent = () => {
|
|||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
<div className="py-4 md:py-0 w-full md:w-1/2 xl:w-2/3">
|
||||
<div className="py-4 md:py-0 w-full md:w-1/2 lg:w-2/3">
|
||||
<Tabs
|
||||
activeTab={activeTab}
|
||||
onChange={handleTabChange}
|
||||
|
|
|
@ -1,7 +1,14 @@
|
|||
import { useEffect, useState } from 'react'
|
||||
import { PublicKey } from '@solana/web3.js'
|
||||
import { Disclosure } from '@headlessui/react'
|
||||
import dayjs from 'dayjs'
|
||||
import relativeTime from 'dayjs/plugin/relativeTime'
|
||||
import { ChevronDownIcon } from '@heroicons/react/solid'
|
||||
import ButtonGroup from './ButtonGroup'
|
||||
import { numberCompacter } from './SwapTokenInfo'
|
||||
import { numberCompacter, numberFormatter } from './SwapTokenInfo'
|
||||
import Button from './Button'
|
||||
|
||||
dayjs.extend(relativeTime)
|
||||
|
||||
const SwapTokenInsights = ({ formState, jupiterTokens, setOutputToken }) => {
|
||||
const [tokenInsights, setTokenInsights] = useState([])
|
||||
|
@ -23,8 +30,6 @@ const SwapTokenInsights = ({ formState, jupiterTokens, setOutputToken }) => {
|
|||
setTokenInsights(data)
|
||||
}
|
||||
|
||||
console.log(filteredTokenInsights)
|
||||
|
||||
useEffect(() => {
|
||||
if (filterBy === '24h Change') {
|
||||
setFilteredTokenInsights(
|
||||
|
@ -49,28 +54,6 @@ const SwapTokenInsights = ({ formState, jupiterTokens, setOutputToken }) => {
|
|||
}
|
||||
}, [filterBy, insightType, tokenInsights])
|
||||
|
||||
// useEffect(() => {
|
||||
// if (insightType === 'Best') {
|
||||
// setFilteredTokenInsights(
|
||||
// tokenInsights
|
||||
// .sort(
|
||||
// (a, b) =>
|
||||
// b.price_change_percentage_24h - a.price_change_percentage_24h
|
||||
// )
|
||||
// .slice(0, 10)
|
||||
// )
|
||||
// } else {
|
||||
// setFilteredTokenInsights(
|
||||
// tokenInsights
|
||||
// .sort(
|
||||
// (a, b) =>
|
||||
// a.price_change_percentage_24h - b.price_change_percentage_24h
|
||||
// )
|
||||
// .slice(0, 10)
|
||||
// )
|
||||
// }
|
||||
// }, [insightType, tokenInsights])
|
||||
|
||||
useEffect(() => {
|
||||
if (jupiterTokens) {
|
||||
getTokenInsights()
|
||||
|
@ -80,7 +63,7 @@ const SwapTokenInsights = ({ formState, jupiterTokens, setOutputToken }) => {
|
|||
return filteredTokenInsights ? (
|
||||
<div>
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
{/* <h2 className="font-bold text-base text-th-fgd-1">24h Change</h2> */}
|
||||
{/* <h2 className="font-bold text-th-fgd-1">24h Change</h2> */}
|
||||
<div className="w-48">
|
||||
<ButtonGroup
|
||||
activeValue={filterBy}
|
||||
|
@ -109,79 +92,205 @@ const SwapTokenInsights = ({ formState, jupiterTokens, setOutputToken }) => {
|
|||
(t) => t?.extensions?.coingeckoId === insight.id
|
||||
)
|
||||
return (
|
||||
<button
|
||||
className="border-b border-th-bkg-4 default-transition flex font-normal items-center justify-between p-2 text-th-fgd-1 w-full hover:bg-th-bkg-2"
|
||||
key={insight.symbol}
|
||||
onClick={() =>
|
||||
setOutputToken({
|
||||
...formState,
|
||||
outputMint: new PublicKey(jupToken.address),
|
||||
})
|
||||
}
|
||||
>
|
||||
<div className="flex items-center space-x-3">
|
||||
<div
|
||||
className={`text-xs ${
|
||||
insight.price_change_percentage_24h >= 0
|
||||
? 'text-th-green'
|
||||
: 'text-th-red'
|
||||
}`}
|
||||
>
|
||||
{insight.price_change_percentage_24h
|
||||
? `${insight.price_change_percentage_24h.toFixed(1)}%`
|
||||
: '?'}
|
||||
</div>
|
||||
{insight.image ? (
|
||||
<img
|
||||
src={insight.image}
|
||||
width="24"
|
||||
height="24"
|
||||
alt={insight.name}
|
||||
className="rounded-full"
|
||||
/>
|
||||
) : (
|
||||
<div className="bg-th-bkg-3 h-6 inline-flex items-center justify-center rounded-full text-th-fgd-3 text-xs w-6">
|
||||
?
|
||||
<Disclosure>
|
||||
{({ open }) => (
|
||||
<>
|
||||
<div
|
||||
className={`border-b default-transition flex items-center p-2 hover:bg-th-bkg-2 ${
|
||||
open
|
||||
? 'bg-th-bkg-2 border-transparent'
|
||||
: 'border-th-bkg-4'
|
||||
}`}
|
||||
>
|
||||
<Disclosure.Button
|
||||
className="flex font-normal items-center justify-between text-th-fgd-1 w-full"
|
||||
key={insight.symbol}
|
||||
>
|
||||
<div className="flex items-center space-x-3">
|
||||
<div
|
||||
className={`min-w-[48px] text-xs ${
|
||||
insight.price_change_percentage_24h >= 0
|
||||
? 'text-th-green'
|
||||
: 'text-th-red'
|
||||
}`}
|
||||
>
|
||||
{insight.price_change_percentage_24h
|
||||
? `${insight.price_change_percentage_24h.toFixed(
|
||||
1
|
||||
)}%`
|
||||
: '?'}
|
||||
</div>
|
||||
{insight.image ? (
|
||||
<img
|
||||
src={insight.image}
|
||||
width="24"
|
||||
height="24"
|
||||
alt={insight.name}
|
||||
className="hidden lg:block rounded-full"
|
||||
/>
|
||||
) : (
|
||||
<div className="bg-th-bkg-3 h-6 inline-flex items-center justify-center rounded-full text-th-fgd-3 text-xs w-6">
|
||||
?
|
||||
</div>
|
||||
)}
|
||||
<div className="text-left">
|
||||
<div className="font-bold">
|
||||
{insight.symbol.toUpperCase()}
|
||||
</div>
|
||||
<div className="text-th-fgd-3 text-xs">
|
||||
{insight.name}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center pl-2 space-x-3 text-right text-xs">
|
||||
<div>
|
||||
<div className="mb-0.5 text-th-fgd-4">Price</div>
|
||||
<div className="text-th-fgd-3">
|
||||
$
|
||||
{insight.current_price.toLocaleString(undefined, {
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 7,
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
<div className="border-l border-th-bkg-4" />
|
||||
<div>
|
||||
<div className="mb-0.5 text-th-fgd-4">Volume</div>
|
||||
<div className="text-th-fgd-3">
|
||||
{insight.total_volume > 0
|
||||
? `$${numberCompacter.format(
|
||||
insight.total_volume
|
||||
)}`
|
||||
: '?'}
|
||||
</div>
|
||||
</div>
|
||||
<ChevronDownIcon
|
||||
className={`default-transition h-5 text-th-fgd-3 w-5 ${
|
||||
open
|
||||
? 'transform rotate-180'
|
||||
: 'transform rotate-360'
|
||||
}`}
|
||||
/>
|
||||
</div>
|
||||
</Disclosure.Button>
|
||||
<Button
|
||||
className="ml-3 pl-3 pr-3 text-xs"
|
||||
onClick={() =>
|
||||
setOutputToken({
|
||||
...formState,
|
||||
outputMint: new PublicKey(jupToken.address),
|
||||
})
|
||||
}
|
||||
>
|
||||
Buy
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
<div className="text-left">
|
||||
<div className="font-bold">
|
||||
{insight.symbol.toUpperCase()}
|
||||
</div>
|
||||
<div className="text-th-fgd-3 text-xs">{insight.name}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex pl-2 space-x-3 text-right text-xs">
|
||||
<div>
|
||||
<div className="text-th-fgd-4">Price</div>
|
||||
<div className="text-th-fgd-3">
|
||||
$
|
||||
{insight.current_price.toLocaleString(undefined, {
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 7,
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
<div className="border-l border-th-bkg-4" />
|
||||
<div>
|
||||
<div className="text-th-fgd-4">M. Cap</div>
|
||||
<div className="text-th-fgd-3">
|
||||
{insight.market_cap > 0
|
||||
? `$${numberCompacter.format(insight.market_cap)}`
|
||||
: '?'}
|
||||
</div>
|
||||
</div>
|
||||
<div className="border-l border-th-bkg-4" />
|
||||
<div>
|
||||
<div className="text-th-fgd-4">Volume</div>
|
||||
<div className="text-th-fgd-3">
|
||||
{insight.total_volume > 0
|
||||
? `$${numberCompacter.format(insight.total_volume)}`
|
||||
: '?'}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
<Disclosure.Panel>
|
||||
<div className="bg-th-bkg-2 border-b border-th-bkg-4 grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-2 xl:grid-cols-3 grid-flow-row px-2 pb-2">
|
||||
{insight.market_cap_rank ? (
|
||||
<div className="border border-th-bkg-4 m-1 p-3 rounded-md">
|
||||
<div className="text-th-fgd-3 text-xs">
|
||||
Market Cap Rank
|
||||
</div>
|
||||
<div className="font-bold text-th-fgd-1">
|
||||
#{insight.market_cap_rank}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
{insight?.market_cap && insight?.market_cap !== 0 ? (
|
||||
<div className="border border-th-bkg-4 m-1 p-3 rounded-md">
|
||||
<div className="text-th-fgd-3 text-xs">
|
||||
Market Cap
|
||||
</div>
|
||||
<div className="font-bold text-th-fgd-1">
|
||||
${numberCompacter.format(insight.market_cap)}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
{insight?.circulating_supply ? (
|
||||
<div className="border border-th-bkg-4 m-1 p-3 rounded-md">
|
||||
<div className="text-th-fgd-3 text-xs">
|
||||
Token Supply
|
||||
</div>
|
||||
<div className="font-bold text-th-fgd-1">
|
||||
{numberCompacter.format(insight.circulating_supply)}
|
||||
</div>
|
||||
{insight?.max_supply ? (
|
||||
<div className="text-th-fgd-2 text-xs">
|
||||
Max Supply:{' '}
|
||||
{numberCompacter.format(insight.max_supply)}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
{insight?.ath ? (
|
||||
<div className="border border-th-bkg-4 m-1 p-3 rounded-md">
|
||||
<div className="text-th-fgd-3 text-xs">
|
||||
All-Time High
|
||||
</div>
|
||||
<div className="flex">
|
||||
<div className="font-bold text-th-fgd-1">
|
||||
${numberFormatter.format(insight.ath)}
|
||||
</div>
|
||||
{insight?.ath_change_percentage ? (
|
||||
<div
|
||||
className={`ml-1.5 mt-0.5 text-xs ${
|
||||
insight?.ath_change_percentage >= 0
|
||||
? 'text-th-green'
|
||||
: 'text-th-red'
|
||||
}`}
|
||||
>
|
||||
{insight.ath_change_percentage.toFixed(2)}%
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
{insight?.ath_date ? (
|
||||
<div className="text-th-fgd-2 text-xs">
|
||||
{dayjs(insight.ath_date).fromNow()}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
{insight?.atl ? (
|
||||
<div className="border border-th-bkg-4 m-1 p-3 rounded-md">
|
||||
<div className="text-th-fgd-3 text-xs">
|
||||
All-Time Low
|
||||
</div>
|
||||
<div className="flex">
|
||||
<div className="font-bold text-th-fgd-1">
|
||||
${numberFormatter.format(insight.atl)}
|
||||
</div>
|
||||
{insight?.atl_change_percentage ? (
|
||||
<div
|
||||
className={`ml-1.5 mt-0.5 text-xs ${
|
||||
insight?.atl_change_percentage >= 0
|
||||
? 'text-th-green'
|
||||
: 'text-th-red'
|
||||
}`}
|
||||
>
|
||||
{(insight?.atl_change_percentage).toLocaleString(
|
||||
undefined,
|
||||
{
|
||||
minimumFractionDigits: 0,
|
||||
maximumFractionDigits: 2,
|
||||
}
|
||||
)}
|
||||
%
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
{insight?.atl_date ? (
|
||||
<div className="text-th-fgd-2 text-xs">
|
||||
{dayjs(insight.atl_date).fromNow()}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</Disclosure.Panel>
|
||||
</>
|
||||
)}
|
||||
</Disclosure>
|
||||
)
|
||||
})
|
||||
)}
|
||||
|
|
|
@ -53,7 +53,7 @@ export default function Swap() {
|
|||
<TopBar />
|
||||
<PageBodyContainer>
|
||||
<div className="grid grid-cols-12">
|
||||
<div className="col-span-12 lg:col-span-10 lg:col-start-2 pt-8 pb-3 sm:pb-4 md:pt-10">
|
||||
<div className="col-span-12 xl:col-span-10 xl:col-start-2 pt-8 pb-3 sm:pb-4 md:pt-10">
|
||||
<div className="flex flex-col items-start md:flex-row md:items-end md:justify-between mb-1">
|
||||
<h1
|
||||
className={`mb-1.5 md:mb-0 text-th-fgd-1 text-2xl font-semibold`}
|
||||
|
|
Loading…
Reference in New Issue