mango-v4-ui/components/shared/TokenLogo.tsx

103 lines
2.9 KiB
TypeScript
Raw Normal View History

2023-07-04 21:40:47 -07:00
import { Bank } from '@blockworks-foundation/mango-v4'
import { QuestionMarkCircleIcon } from '@heroicons/react/20/solid'
import useJupiterMints from 'hooks/useJupiterMints'
import Image from 'next/image'
import { useMemo } from 'react'
import { CUSTOM_TOKEN_ICONS } from 'utils/constants'
2023-10-08 21:04:27 -07:00
import Tooltip from './Tooltip'
2023-07-04 21:40:47 -07:00
const TokenLogo = ({
bank,
2023-09-18 05:55:37 -07:00
logoUrl,
showRewardsLogo,
2023-07-04 21:40:47 -07:00
size,
}: {
bank: Bank | undefined
2023-09-18 05:55:37 -07:00
logoUrl?: string
showRewardsLogo?: boolean
2023-07-04 21:40:47 -07:00
size?: number
}) => {
const { mangoTokens } = useJupiterMints()
const logoUri = useMemo(() => {
2023-09-18 05:55:37 -07:00
if (logoUrl) return logoUrl
2023-07-04 21:40:47 -07:00
if (!bank) return ''
const tokenSymbol = bank.name.toLowerCase()
const hasCustomIcon = CUSTOM_TOKEN_ICONS[tokenSymbol]
if (hasCustomIcon) return `/icons/${tokenSymbol}.svg`
let jupiterLogoURI
if (mangoTokens?.length) {
jupiterLogoURI = mangoTokens.find(
2023-07-21 11:47:53 -07:00
(t) => t.address === bank?.mint.toString(),
2023-07-04 21:40:47 -07:00
)?.logoURI
}
return jupiterLogoURI
2023-09-18 05:55:37 -07:00
}, [mangoTokens, bank, logoUrl])
2023-07-04 21:40:47 -07:00
const logoSize = size ? size : 24
return logoUri ? (
2023-10-08 21:04:27 -07:00
<Tooltip
content={
showRewardsLogo ? (
bank?.name === 'MSOL' ? (
<>
<p className="mb-2">
Earn MNDE tokens for holding your mSOL on Mango
</p>
<a
2024-01-18 06:17:45 -08:00
href="https://marinade.finance/blog/let-marinade-earn-season-2-begin/"
target="_blank"
rel="noopener noreferrer"
>
View Details
</a>
</>
) : bank?.name === 'bSOL' ? (
<>
<p className="mb-2">
Earn BLZE tokens for holding your bSOL on Mango
</p>
<a
href="https://rewards.solblaze.org/"
target="_blank"
rel="noopener noreferrer"
>
View Details
</a>
</>
) : null
2023-10-08 21:04:27 -07:00
) : null
}
2023-07-06 05:08:10 -07:00
>
2023-10-08 21:04:27 -07:00
<div
className={`h-[${logoSize}px] w-[${logoSize}px] relative rounded-full bg-th-bkg-2 ${
2023-10-11 03:05:52 -07:00
bank?.name === 'MSOL' || bank?.name === 'bSOL' ? 'cursor-help' : ''
2023-10-08 21:04:27 -07:00
}`}
>
<Image alt="" width={logoSize} height={logoSize} src={logoUri} />
{showRewardsLogo ? (
<>
{bank?.name === 'MSOL' ? (
<div className="absolute -right-1.5 -top-1.5 shadow">
<Image alt="" width={16} height={16} src={'/icons/mnde.svg'} />
</div>
) : null}
{bank?.name === 'bSOL' ? (
<div className="absolute -right-1.5 -top-1.5 shadow">
<Image alt="" width={16} height={16} src={'/icons/blze.svg'} />
</div>
) : null}
</>
2023-10-11 03:05:52 -07:00
) : null}
2023-10-08 21:04:27 -07:00
</div>
</Tooltip>
2023-07-04 21:40:47 -07:00
) : (
<QuestionMarkCircleIcon
className={`h-[${logoSize}px] w-[${logoSize}px] text-th-fgd-3`}
/>
)
}
export default TokenLogo