lev-stake-sol/components/TokenButton.tsx

77 lines
2.4 KiB
TypeScript
Raw Normal View History

2023-09-15 11:53:40 -07:00
import useStakeRates from 'hooks/useStakeRates'
2023-09-12 17:37:41 -07:00
import Image from 'next/image'
2023-09-14 21:24:29 -07:00
import { formatTokenSymbol } from 'utils/tokens'
2023-09-14 22:57:39 -07:00
import SheenLoader from './shared/SheenLoader'
2023-09-12 17:37:41 -07:00
2023-09-22 06:33:36 -07:00
const TokenButton = (
{
handleTokenSelect,
selectedToken,
tokenName,
}: {
tokenName: string
selectedToken: string
handleTokenSelect: (v: string) => void
},
) => {
const { data: stakeRates, isLoading } = useStakeRates()
2023-09-14 20:48:49 -07:00
2023-09-12 17:37:41 -07:00
return (
2023-09-14 06:18:39 -07:00
<button
2023-09-22 06:33:36 -07:00
className={`col-span-1 flex items-center justify-center border-r border-th-fgd-1 p-4 first:rounded-tl-[13px] last:rounded-tr-[13px] last:border-r-0 hover:cursor-pointer ${
selectedToken === tokenName
? 'inner-shadow-top bg-th-primary-2'
: 'inner-shadow-bottom default-transition bg-th-bkg-1 md:hover:bg-th-bkg-2'
2023-09-14 06:18:39 -07:00
}`}
onClick={() => handleTokenSelect(tokenName)}
>
<div className="flex flex-col items-center">
2023-09-22 06:33:36 -07:00
<div
className={`flex h-12 w-12 items-center justify-center rounded-full border ${
selectedToken === tokenName
? 'inner-shadow-top-sm border-th-primary-1 bg-gradient-to-b from-th-primary-2 to-th-primary-3'
: 'inner-shadow-bottom-sm border-th-bkg-2 bg-gradient-to-b from-th-bkg-1 to-th-bkg-2'
}`}
>
<Image
src={`/icons/${tokenName.toLowerCase()}.svg`}
width={24}
height={24}
alt="Select a token"
/>
</div>
<span
className={`mt-1 font-display text-xl ${
selectedToken === tokenName
? 'text-shadow text-th-active'
: 'text-th-fgd-1'
}`}
>
2023-09-14 21:24:29 -07:00
{formatTokenSymbol(tokenName)}
2023-09-14 06:18:39 -07:00
</span>
2023-09-22 06:33:36 -07:00
<span
className={`-mt-1 font-mono ${
selectedToken === tokenName ? 'text-th-bkg-1' : 'text-th-fgd-4'
}`}
>
{isLoading ? (
2023-09-22 06:33:36 -07:00
<SheenLoader>
<div
className={`h-5 w-10 ${
selectedToken === tokenName
? 'bg-th-primary-1'
: 'bg-th-bkg-2'
}`}
/>
2023-09-14 22:57:39 -07:00
</SheenLoader>
2023-09-15 11:53:40 -07:00
) : stakeRates?.[tokenName.toLowerCase()] ? (
`${(stakeRates?.[tokenName.toLowerCase()] * 100).toFixed(2)}%`
2023-09-14 22:57:39 -07:00
) : null}
2023-09-14 20:48:49 -07:00
</span>
2023-09-12 17:37:41 -07:00
</div>
</button>
)
}
export default TokenButton