import { Transition } from '@headlessui/react' import { ChevronDownIcon, QuestionMarkCircleIcon, } from '@heroicons/react/20/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' import FlipNumbers from 'react-flip-numbers' 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) } const [totalDepositValue, totalBorrowValue] = useMemo(() => { if (banks.length) { return [ banks.reduce( (a, c) => a + c.value[0].uiPrice! * c.value[0].uiDeposits(), 0 ), banks.reduce( (a, c) => a + c.value[0].uiPrice! * c.value[0].uiBorrows(), 0 ), ] } return [] }, [banks]) return (

{t('total-deposit-value')}

{t('total-borrow-value')}

{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')} {t('total-deposits')} {t('total-borrows')}
{t('rates')}
{t('utilization')}
{t('asset-weight')}
{t('liability-weight')}
{logoURI ? ( ) : ( )}

{bank.name}

{formatFixedDecimals(oraclePrice!, true)}

{formatFixedDecimals(bank.uiDeposits())}

{formatFixedDecimals(bank.uiBorrows())}

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

|

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

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

{bank.initAssetWeight.toFixed(2)}

{bank.initLiabWeight.toFixed(2)}

) : (
{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}

{t('total-deposits')}

{formatFixedDecimals(bank.uiDeposits())}

{t('total-borrows')}

{formatFixedDecimals(bank.uiBorrows())}

handleShowTokenDetails(bank.name)} >

{t('price')}

${formatDecimal(oraclePrice!, 2)}

{t('rates')}

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

{t('utilization')}

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

{t('asset-weight')}

{bank.initAssetWeight.toFixed(2)}

{t('liability-weight')}

{bank.initLiabWeight.toFixed(2)}

) })}
)}
) } export default TokenList