mango-v4-ui/components/swap/TokenSelect.tsx

51 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-09-06 21:36:35 -07:00
import {
ChevronDownIcon,
QuestionMarkCircleIcon,
} from '@heroicons/react/20/solid'
2022-10-28 14:46:38 -07:00
import Image from 'next/legacy/image'
2022-11-18 11:11:06 -08:00
import useMangoGroup from 'hooks/useMangoGroup'
import useJupiterMints from 'hooks/useJupiterMints'
2022-11-21 20:20:05 -08:00
import { Bank } from '@blockworks-foundation/mango-v4'
2022-07-05 20:37:49 -07:00
type TokenSelectProps = {
2022-11-21 20:20:05 -08:00
bank: Bank | undefined
2022-07-16 04:22:59 -07:00
showTokenList: (x: any) => void
type: 'input' | 'output'
2022-07-05 20:37:49 -07:00
}
2022-11-21 20:20:05 -08:00
const TokenSelect = ({ bank, showTokenList, type }: TokenSelectProps) => {
2022-11-18 11:11:06 -08:00
const { group } = useMangoGroup()
const { mangoTokens } = useJupiterMints()
2022-07-05 20:37:49 -07:00
if (!group) return null
2022-08-15 19:41:06 -07:00
let logoURI
2022-11-18 11:11:06 -08:00
if (mangoTokens.length) {
2022-11-21 20:20:05 -08:00
logoURI = mangoTokens.find(
(t) => t.address === bank?.mint.toString()
)!.logoURI
2022-08-15 19:41:06 -07:00
}
2022-07-05 20:37:49 -07:00
return (
2022-07-22 23:15:51 -07:00
<div
onClick={() => showTokenList(type)}
2022-08-15 04:28:36 -07:00
className="default-transition flex h-full items-center rounded-lg rounded-r-none p-3 text-th-fgd-2 hover:cursor-pointer hover:bg-th-bkg-2 hover:text-th-fgd-1"
2022-07-22 23:15:51 -07:00
role="button"
>
<div className="mr-2.5 flex min-w-[24px] items-center">
2022-08-15 19:41:06 -07:00
{logoURI ? (
<Image alt="" width="24" height="24" src={logoURI} />
) : (
<QuestionMarkCircleIcon className="h-7 w-7 text-th-fgd-3" />
)}
</div>
2022-07-22 23:15:51 -07:00
<div className="flex w-full items-center justify-between">
2022-11-21 20:20:05 -08:00
<div className="text-xl font-bold text-th-fgd-1">{bank?.name}</div>
2022-07-22 23:15:51 -07:00
<ChevronDownIcon className="h-6 w-6" />
</div>
</div>
2022-07-05 20:37:49 -07:00
)
}
export default TokenSelect