2022-10-02 20:14:26 -07:00
|
|
|
import { Serum3Market } from '@blockworks-foundation/mango-v4'
|
2022-10-10 19:16:13 -07:00
|
|
|
import { PerpMarket } from '@blockworks-foundation/mango-v4/dist/types/src/accounts/perp'
|
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-09-26 04:53:49 -07:00
|
|
|
import Image from 'next/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)
|
|
|
|
const jupiterTokens = mangoStore((s) => s.jupiterTokens)
|
|
|
|
|
|
|
|
const logos = useMemo(() => {
|
2022-10-10 19:16:13 -07:00
|
|
|
if (!group || !jupiterTokens.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)
|
|
|
|
|
|
|
|
jupiterBaseToken = jupiterTokens.find(
|
|
|
|
(t) => t.address === baseBank.mint.toString()
|
|
|
|
)
|
|
|
|
jupiterQuoteToken = jupiterTokens.find(
|
|
|
|
(t) => t.address === quoteBank.mint.toString()
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
jupiterBaseToken = jupiterTokens.find(
|
|
|
|
(t) => t.address === market.name.split('-')[0]
|
|
|
|
)
|
|
|
|
}
|
2022-10-02 20:14:26 -07:00
|
|
|
const baseLogoURI = jupiterBaseToken ? jupiterBaseToken.logoURI : ''
|
|
|
|
const quoteLogoURI = jupiterQuoteToken ? jupiterQuoteToken.logoURI : ''
|
|
|
|
return {
|
|
|
|
baseLogoURI,
|
|
|
|
quoteLogoURI,
|
|
|
|
}
|
2022-10-10 19:16:13 -07:00
|
|
|
}, [group, jupiterTokens, market])
|
|
|
|
|
2022-09-26 04:53:49 -07:00
|
|
|
return (
|
|
|
|
<div className="relative mr-1.5 h-5 w-[34px]">
|
|
|
|
<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
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<QuestionMarkCircleIcon className="h-5 w-5 text-th-fgd-3" />
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MarketLogos
|