2023-04-27 05:11:20 -07:00
|
|
|
import { Disclosure, Transition } from '@headlessui/react'
|
|
|
|
import {
|
2023-04-30 22:24:21 -07:00
|
|
|
ArrowTopRightOnSquareIcon,
|
2023-04-27 05:11:20 -07:00
|
|
|
ChevronDownIcon,
|
2023-05-02 18:00:32 -07:00
|
|
|
ChevronRightIcon,
|
2023-04-27 05:11:20 -07:00
|
|
|
QuestionMarkCircleIcon,
|
|
|
|
} from '@heroicons/react/20/solid'
|
|
|
|
import { useTranslation } from 'next-i18next'
|
|
|
|
import Image from 'next/legacy/image'
|
|
|
|
import { useViewport } from '../../hooks/useViewport'
|
|
|
|
import { breakpoints } from '../../utils/theme'
|
|
|
|
import ContentBox from '../shared/ContentBox'
|
|
|
|
import Tooltip from '@components/shared/Tooltip'
|
|
|
|
import { Bank } from '@blockworks-foundation/mango-v4'
|
|
|
|
import useJupiterMints from 'hooks/useJupiterMints'
|
|
|
|
import { Table, Td, Th, TrBody, TrHead } from '@components/shared/TableElements'
|
|
|
|
import useMangoGroup from 'hooks/useMangoGroup'
|
|
|
|
import useBanksWithBalances from 'hooks/useBanksWithBalances'
|
2023-04-30 22:24:21 -07:00
|
|
|
import { getOracleProvider } from 'hooks/useOracleProvider'
|
2023-05-02 18:00:32 -07:00
|
|
|
import { useRouter } from 'next/router'
|
|
|
|
import { goToTokenPage } from './TokenOverviewTable'
|
|
|
|
import { LinkButton } from '@components/shared/Button'
|
2023-04-27 05:11:20 -07:00
|
|
|
|
2023-05-02 10:47:26 -07:00
|
|
|
const TokenDetailsTable = () => {
|
2023-04-30 22:24:21 -07:00
|
|
|
const { t } = useTranslation(['common', 'activity', 'token', 'trade'])
|
2023-04-27 05:11:20 -07:00
|
|
|
const { group } = useMangoGroup()
|
|
|
|
const { mangoTokens } = useJupiterMints()
|
|
|
|
const { width } = useViewport()
|
|
|
|
const showTableView = width ? width > breakpoints.md : false
|
|
|
|
const banks = useBanksWithBalances()
|
2023-05-02 18:00:32 -07:00
|
|
|
const router = useRouter()
|
2023-04-27 05:11:20 -07:00
|
|
|
|
|
|
|
return group ? (
|
|
|
|
<ContentBox hideBorder hidePadding>
|
|
|
|
{showTableView ? (
|
|
|
|
<div className="thin-scroll overflow-x-auto">
|
|
|
|
<Table>
|
|
|
|
<thead>
|
|
|
|
<TrHead>
|
|
|
|
<Th className="text-left">{t('token')}</Th>
|
|
|
|
<Th>
|
|
|
|
<div className="flex justify-end text-right">
|
|
|
|
<Tooltip content={t('asset-liability-weight-desc')}>
|
|
|
|
<span className="tooltip-underline">
|
|
|
|
{t('asset-liability-weight')}
|
|
|
|
</span>
|
|
|
|
</Tooltip>
|
|
|
|
</div>
|
|
|
|
</Th>
|
|
|
|
<Th className="text-right">{t('borrow-fee')}</Th>
|
|
|
|
<Th className="text-right">{t('activity:liquidation-fee')}</Th>
|
2023-04-30 22:24:21 -07:00
|
|
|
<Th className="text-right">{t('trade:oracle')}</Th>
|
2023-05-02 10:41:55 -07:00
|
|
|
<Th className="text-right">
|
2023-04-27 05:11:20 -07:00
|
|
|
<Tooltip
|
2023-05-02 10:57:53 -07:00
|
|
|
content={
|
|
|
|
<div>
|
|
|
|
{t('trade:tooltip-insured', { tokenOrMarket: '' })}
|
|
|
|
<a
|
|
|
|
className="mt-2 flex items-center"
|
|
|
|
href="https://docs.mango.markets/mango-markets/insurance-fund"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
target="_blank"
|
|
|
|
>
|
|
|
|
Learn more
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
}
|
2023-04-27 05:11:20 -07:00
|
|
|
>
|
|
|
|
<span className="tooltip-underline">
|
|
|
|
{t('trade:insured', { token: '' })}
|
|
|
|
</span>
|
|
|
|
</Tooltip>
|
2023-05-02 10:41:55 -07:00
|
|
|
</Th>
|
2023-05-02 18:00:32 -07:00
|
|
|
<Th />
|
2023-04-27 05:11:20 -07:00
|
|
|
</TrHead>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{banks.map((b) => {
|
|
|
|
const bank: Bank = b.bank
|
|
|
|
|
|
|
|
let logoURI
|
|
|
|
if (mangoTokens?.length) {
|
|
|
|
logoURI = mangoTokens.find(
|
|
|
|
(t) => t.address === bank.mint.toString()
|
|
|
|
)?.logoURI
|
|
|
|
}
|
|
|
|
|
2023-05-01 03:55:22 -07:00
|
|
|
const [oracleProvider, oracleLinkPath] = getOracleProvider(bank)
|
2023-04-30 22:24:21 -07:00
|
|
|
|
2023-05-02 10:41:55 -07:00
|
|
|
const mintInfo = group.mintInfosMapByMint.get(
|
|
|
|
bank.mint.toString()
|
|
|
|
)
|
2023-04-27 05:11:20 -07:00
|
|
|
|
|
|
|
return (
|
2023-05-02 18:00:32 -07:00
|
|
|
<TrBody
|
|
|
|
className="md:hover:cursor-pointer md:hover:bg-th-bkg-2"
|
|
|
|
key={bank.name}
|
|
|
|
onClick={() =>
|
|
|
|
goToTokenPage(
|
|
|
|
bank.name.split(' ')[0].toUpperCase(),
|
|
|
|
router
|
|
|
|
)
|
|
|
|
}
|
|
|
|
>
|
2023-04-27 05:11:20 -07:00
|
|
|
<Td>
|
|
|
|
<div className="flex items-center">
|
|
|
|
<div className="mr-2.5 flex flex-shrink-0 items-center">
|
|
|
|
{logoURI ? (
|
|
|
|
<Image
|
|
|
|
alt=""
|
|
|
|
width="24"
|
|
|
|
height="24"
|
|
|
|
src={logoURI}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<QuestionMarkCircleIcon className="h-6 w-6 text-th-fgd-3" />
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<p className="font-body">{bank.name}</p>
|
|
|
|
</div>
|
|
|
|
</Td>
|
|
|
|
<Td>
|
|
|
|
<div className="flex justify-end space-x-1.5 text-right">
|
|
|
|
<p>{bank.initAssetWeight.toFixed(2)}</p>
|
|
|
|
<span className="text-th-fgd-4">|</span>
|
|
|
|
<p>{bank.initLiabWeight.toFixed(2)}</p>
|
|
|
|
</div>
|
|
|
|
</Td>
|
|
|
|
<Td>
|
|
|
|
<p className="text-right">
|
|
|
|
{(100 * bank.loanOriginationFeeRate.toNumber()).toFixed(
|
|
|
|
2
|
|
|
|
)}
|
|
|
|
%
|
|
|
|
</p>
|
|
|
|
</Td>
|
|
|
|
<Td>
|
|
|
|
<p className="text-right">
|
|
|
|
{(bank.liquidationFee.toNumber() * 100).toFixed(2)}%
|
|
|
|
</p>
|
|
|
|
</Td>
|
2023-04-30 22:24:21 -07:00
|
|
|
<Td>
|
|
|
|
{oracleLinkPath ? (
|
|
|
|
<a
|
|
|
|
className="flex items-center justify-end"
|
|
|
|
href={oracleLinkPath}
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
<span className="mr-1.5 font-body">
|
|
|
|
{oracleProvider}
|
|
|
|
</span>
|
|
|
|
<ArrowTopRightOnSquareIcon className="h-4 w-4" />
|
|
|
|
</a>
|
|
|
|
) : (
|
|
|
|
<p className="text-right font-body">{oracleProvider}</p>
|
|
|
|
)}
|
|
|
|
</Td>
|
2023-05-02 10:41:55 -07:00
|
|
|
<Td>
|
2023-04-27 05:11:20 -07:00
|
|
|
<p className="text-right">
|
|
|
|
{mintInfo?.groupInsuranceFund ? t('yes') : t('no')}
|
|
|
|
</p>
|
2023-05-02 10:41:55 -07:00
|
|
|
</Td>
|
2023-05-02 18:00:32 -07:00
|
|
|
<Td>
|
|
|
|
<div className="flex justify-end">
|
|
|
|
<ChevronRightIcon className="h-5 w-5 text-th-fgd-3" />
|
|
|
|
</div>
|
|
|
|
</Td>
|
2023-04-27 05:11:20 -07:00
|
|
|
</TrBody>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</tbody>
|
|
|
|
</Table>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className="border-b border-th-bkg-3">
|
|
|
|
{banks.map((b, i) => {
|
|
|
|
const bank = b.bank
|
|
|
|
let logoURI: string | undefined
|
|
|
|
if (mangoTokens?.length) {
|
|
|
|
logoURI = mangoTokens.find(
|
|
|
|
(t) => t.address === bank.mint.toString()
|
|
|
|
)?.logoURI
|
|
|
|
}
|
2023-05-01 03:55:22 -07:00
|
|
|
const [oracleProvider, oracleLinkPath] = getOracleProvider(bank)
|
2023-05-02 18:00:32 -07:00
|
|
|
const mintInfo = group.mintInfosMapByMint.get(bank.mint.toString())
|
2023-04-27 05:11:20 -07:00
|
|
|
return (
|
|
|
|
<Disclosure key={bank.name}>
|
|
|
|
{({ open }) => (
|
|
|
|
<>
|
|
|
|
<Disclosure.Button
|
|
|
|
className={`w-full border-t border-th-bkg-3 p-4 text-left focus:outline-none ${
|
|
|
|
i === 0 ? 'border-t-0' : ''
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
<div className="flex items-center">
|
|
|
|
<div className="mr-2.5 flex flex-shrink-0 items-center">
|
|
|
|
{logoURI ? (
|
|
|
|
<Image
|
|
|
|
alt=""
|
|
|
|
width="24"
|
|
|
|
height="24"
|
|
|
|
src={logoURI}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<QuestionMarkCircleIcon className="h-7 w-7 text-th-fgd-3" />
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<p className="text-th-fgd-1">{bank.name}</p>
|
|
|
|
</div>
|
|
|
|
<ChevronDownIcon
|
|
|
|
className={`${
|
|
|
|
open ? 'rotate-180' : 'rotate-360'
|
|
|
|
} h-6 w-6 flex-shrink-0 text-th-fgd-3`}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</Disclosure.Button>
|
|
|
|
<Transition
|
|
|
|
enter="transition ease-in duration-200"
|
|
|
|
enterFrom="opacity-0"
|
|
|
|
enterTo="opacity-100"
|
|
|
|
>
|
|
|
|
<Disclosure.Panel>
|
|
|
|
<div className="mx-4 grid grid-cols-2 gap-4 border-t border-th-bkg-3 pt-4 pb-4">
|
|
|
|
<div className="col-span-1">
|
|
|
|
<Tooltip content={t('asset-liability-weight-desc')}>
|
|
|
|
<p className="tooltip-underline text-xs text-th-fgd-3">
|
|
|
|
{t('asset-liability-weight')}
|
|
|
|
</p>
|
|
|
|
</Tooltip>
|
|
|
|
<div className="flex space-x-1.5 text-right font-mono">
|
|
|
|
<p className="text-th-fgd-1">
|
|
|
|
{bank.initAssetWeight.toFixed(2)}
|
|
|
|
</p>
|
|
|
|
<span className="text-th-fgd-4">|</span>
|
|
|
|
<p className="text-th-fgd-1">
|
|
|
|
{bank.initLiabWeight.toFixed(2)}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="col-span-1">
|
|
|
|
<p className="text-xs">{t('borrow-fee')}</p>
|
|
|
|
<p className="font-mono text-th-fgd-1">
|
|
|
|
{(
|
|
|
|
100 * bank.loanOriginationFeeRate.toNumber()
|
|
|
|
).toFixed(2)}
|
|
|
|
%
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div className="col-span-1">
|
|
|
|
<p className="text-xs">
|
|
|
|
{t('activity:liquidation-fee')}
|
|
|
|
</p>
|
|
|
|
<p className="font-mono text-th-fgd-1">
|
|
|
|
{(bank.liquidationFee.toNumber() * 100).toFixed(
|
|
|
|
2
|
|
|
|
)}
|
|
|
|
%
|
|
|
|
</p>
|
|
|
|
</div>
|
2023-04-30 22:24:21 -07:00
|
|
|
<div className="col-span-1">
|
|
|
|
<p className="text-xs">{t('trade:oracle')}</p>
|
|
|
|
{oracleLinkPath ? (
|
|
|
|
<a
|
|
|
|
className="flex items-center"
|
|
|
|
href={oracleLinkPath}
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
<span className="mr-1.5 font-body">
|
|
|
|
{oracleProvider}
|
|
|
|
</span>
|
|
|
|
<ArrowTopRightOnSquareIcon className="h-4 w-4" />
|
|
|
|
</a>
|
|
|
|
) : (
|
|
|
|
<p className="text-right font-body">
|
|
|
|
{oracleProvider}
|
|
|
|
</p>
|
|
|
|
)}
|
|
|
|
</div>
|
2023-05-02 18:00:32 -07:00
|
|
|
<div className="col-span-1">
|
|
|
|
<Tooltip
|
|
|
|
content={
|
|
|
|
<div>
|
|
|
|
{t('trade:tooltip-insured', {
|
|
|
|
tokenOrMarket: '',
|
|
|
|
})}
|
|
|
|
<a
|
|
|
|
className="mt-2 flex items-center"
|
|
|
|
href="https://docs.mango.markets/mango-markets/insurance-fund"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
target="_blank"
|
|
|
|
>
|
|
|
|
Learn more
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<span className="tooltip-underline text-xs">
|
|
|
|
{t('trade:insured', { token: '' })}
|
|
|
|
</span>
|
|
|
|
</Tooltip>
|
|
|
|
<p className="font-mono text-th-fgd-1">
|
|
|
|
{mintInfo?.groupInsuranceFund
|
|
|
|
? t('yes')
|
|
|
|
: t('no')}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div className="col-span-1">
|
|
|
|
<LinkButton
|
|
|
|
className="flex items-center"
|
|
|
|
onClick={() =>
|
|
|
|
goToTokenPage(
|
|
|
|
bank.name.split(' ')[0].toUpperCase(),
|
|
|
|
router
|
|
|
|
)
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{t('token:token-stats', { token: bank.name })}
|
|
|
|
<ChevronRightIcon className="ml-2 h-5 w-5" />
|
|
|
|
</LinkButton>
|
|
|
|
</div>
|
2023-04-27 05:11:20 -07:00
|
|
|
</div>
|
|
|
|
</Disclosure.Panel>
|
|
|
|
</Transition>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Disclosure>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</ContentBox>
|
|
|
|
) : null
|
|
|
|
}
|
|
|
|
|
2023-05-02 10:47:26 -07:00
|
|
|
export default TokenDetailsTable
|