import { Transition } from '@headlessui/react' import { ChevronDownIcon, QuestionMarkCircleIcon } from '@heroicons/react/solid' import { useTranslation } from 'next-i18next' import Image from 'next/image' import { Fragment, useMemo, useState } from 'react' import { useViewport } from '../../hooks/useViewport' import mangoStore from '../../store/mangoStore' import { formatDecimal, formatFixedDecimals } from '../../utils/numbers' import { breakpoints } from '../../utils/theme' import { IconButton } from '../shared/Button' import ContentBox from '../shared/ContentBox' import InfoTooltip from '../shared/InfoTooltip' const TokenList = () => { const { t } = useTranslation('common') const [showTokenDetails, setShowTokenDetails] = useState('') const group = mangoStore((s) => s.group) const jupiterTokens = mangoStore((s) => s.jupiterTokens) const { width } = useViewport() const showTableView = width ? width > breakpoints.md : false const banks = useMemo(() => { if (group) { const rawBanks = Array.from(group?.banksMapByName, ([key, value]) => ({ key, value, })) return rawBanks } return [] }, [group]) const handleShowTokenDetails = (name: string) => { showTokenDetails ? setShowTokenDetails('') : setShowTokenDetails(name) } return ( {showTableView ? ( {banks.map(({ key, value }) => { const bank = value[0] const oraclePrice = bank.uiPrice let logoURI if (jupiterTokens.length) { logoURI = jupiterTokens.find( (t) => t.address === bank.mint.toString() )!.logoURI } return ( ) })}
{t('token')} {t('price')} Total Deposits Total Borrows
Utilization
{t('rates')}
LTV
{logoURI ? ( ) : ( )}

{bank.name}

{formatFixedDecimals(oraclePrice, true)}

{formatFixedDecimals(bank.uiDeposits())}

{formatFixedDecimals(bank.uiBorrows())}

{bank.uiDeposits() > 0 ? formatDecimal( (bank.uiBorrows() / bank.uiDeposits()) * 100, 1, { fixed: true } ) : '0.0'} %

{formatDecimal(bank.getDepositRateUi(), 2, { fixed: true, })} %

|

{formatDecimal(bank.getBorrowRateUi(), 2, { fixed: true, })} %

{(bank.initAssetWeight.toNumber() * 100).toFixed()}%

) : (
{banks.map(({ key, value }) => { const bank = value[0] const oraclePrice = bank.uiPrice let logoURI if (jupiterTokens.length) { logoURI = jupiterTokens.find( (t) => t.address === bank.mint.toString() )!.logoURI } return (
{logoURI ? ( ) : ( )}

{bank.name}

handleShowTokenDetails(bank.name)} >

{t('price')}

${formatDecimal(oraclePrice, 2)}

{t('rates')}

{formatDecimal(bank.getDepositRate().toNumber(), 2)}% | {formatDecimal(bank.getBorrowRate().toNumber(), 2)}%

{t('liquidity')}

{formatDecimal( bank.uiDeposits() - bank.uiBorrows(), bank.mintDecimals )}

) })}
)}
) } export default TokenList