mango-v4-ui/components/trade/MarketLogos.tsx

77 lines
2.4 KiB
TypeScript
Raw Normal View History

2022-10-26 03:49:05 -07:00
import { Serum3Market, PerpMarket } from '@blockworks-foundation/mango-v4'
2022-11-18 11:11:06 -08:00
import useJupiterMints from 'hooks/useJupiterMints'
2022-09-26 04:53:49 -07:00
import { QuestionMarkCircleIcon } from '@heroicons/react/20/solid'
2022-10-02 20:14:26 -07:00
import mangoStore from '@store/mangoStore'
2022-10-28 14:46:38 -07:00
import Image from 'next/legacy/image'
2022-10-02 20:14:26 -07:00
import { useMemo } from 'react'
2022-09-26 04:53:49 -07:00
2022-10-10 19:16:13 -07:00
const MarketLogos = ({ market }: { market: Serum3Market | PerpMarket }) => {
2022-10-02 20:14:26 -07:00
const group = mangoStore((s) => s.group)
2022-11-18 11:11:06 -08:00
const { mangoTokens } = useJupiterMints()
2022-10-02 20:14:26 -07:00
const logos = useMemo(() => {
2022-11-18 11:11:06 -08:00
if (!group || !mangoTokens.length || !market)
2022-10-02 20:14:26 -07:00
return { baseLogoURI: '', quoteLogoURI: '' }
2022-10-10 19:16:13 -07:00
let jupiterBaseToken, jupiterQuoteToken
if (market instanceof Serum3Market) {
const baseBank = group.getFirstBankByTokenIndex(market.baseTokenIndex)
const quoteBank = group.getFirstBankByTokenIndex(market.quoteTokenIndex)
2022-11-18 11:11:06 -08:00
jupiterBaseToken = mangoTokens.find(
2022-10-10 19:16:13 -07:00
(t) => t.address === baseBank.mint.toString()
)
2022-11-18 11:11:06 -08:00
jupiterQuoteToken = mangoTokens.find(
2022-10-10 19:16:13 -07:00
(t) => t.address === quoteBank.mint.toString()
)
} else {
2022-11-19 12:10:32 -08:00
jupiterBaseToken =
mangoTokens.find((t) => t.symbol === market.name.split('-')[0]) ||
mangoTokens.find((t) => t.symbol.includes(market.name.split('-')[0]))
2022-10-10 19:16:13 -07:00
}
2022-10-02 20:14:26 -07:00
const baseLogoURI = jupiterBaseToken ? jupiterBaseToken.logoURI : ''
const quoteLogoURI = jupiterQuoteToken ? jupiterQuoteToken.logoURI : ''
return {
baseLogoURI,
quoteLogoURI,
}
2022-11-18 11:11:06 -08:00
}, [group, mangoTokens, market])
2022-10-10 19:16:13 -07:00
2022-09-26 04:53:49 -07:00
return (
2022-10-26 03:49:05 -07:00
<div
className={`relative mr-1.5 h-5 ${
market instanceof Serum3Market ? 'w-[34px]' : 'w-[20px]'
}`}
>
2022-09-26 04:53:49 -07:00
<div className="absolute left-0 top-0">
2022-10-02 20:14:26 -07:00
{logos.baseLogoURI ? (
2022-09-26 04:53:49 -07:00
<Image
alt=""
className="z-10 rounded-full drop-shadow-md"
width="20"
height="20"
2022-10-02 20:14:26 -07:00
src={logos.baseLogoURI}
2022-09-26 04:53:49 -07:00
/>
) : (
<QuestionMarkCircleIcon className="h-5 w-5 text-th-fgd-3" />
)}
</div>
<div className="absolute right-0 top-0">
2022-10-10 19:16:13 -07:00
{logos.quoteLogoURI && market instanceof Serum3Market ? (
2022-09-26 04:53:49 -07:00
<Image
alt=""
className="rounded-full opacity-60"
width="20"
height="20"
2022-10-02 20:14:26 -07:00
src={logos.quoteLogoURI}
2022-09-26 04:53:49 -07:00
/>
2022-10-26 03:49:05 -07:00
) : market instanceof PerpMarket ? null : (
2022-09-26 04:53:49 -07:00
<QuestionMarkCircleIcon className="h-5 w-5 text-th-fgd-3" />
)}
</div>
</div>
)
}
export default MarketLogos