import { useCallback, useState } from 'react' import { getTokenBySymbol, ZERO_I80F48, I80F48, } from '@blockworks-foundation/mango-client' import useMangoStore from '../../stores/useMangoStore' import { useBalances } from '../../hooks/useBalances' import { formatUsdValue, i80f48ToPercent, tokenPrecision, } from '../../utils/index' import WithdrawModal from '../WithdrawModal' import Button from '../Button' import DepositModal from '../DepositModal' import { useViewport } from '../../hooks/useViewport' import { breakpoints } from '../TradePageGrid' import { Table, Td, Th, TrBody, TrHead } from '../TableElements' import { ExpandableRow } from '../TableElements' import MobileTableHeader from '../mobile/MobileTableHeader' import { useTranslation } from 'next-i18next' export default function AccountBorrows() { const { t } = useTranslation('common') const balances = useBalances() const mangoGroup = useMangoStore((s) => s.selectedMangoGroup.current) const mangoCache = useMangoStore((s) => s.selectedMangoGroup.cache) const mangoConfig = useMangoStore((s) => s.selectedMangoGroup.config) const mangoAccount = useMangoStore((s) => s.selectedMangoAccount.current) const loadingMangoAccount = useMangoStore( (s) => s.selectedMangoAccount.initialLoad ) const connected = useMangoStore((s) => s.wallet.connected) const [borrowSymbol, setBorrowSymbol] = useState('') const [depositToSettle, setDepositToSettle] = useState(null) const [showBorrowModal, setShowBorrowModal] = useState(false) const [showDepositModal, setShowDepositModal] = useState(false) const { width } = useViewport() const isMobile = width ? width < breakpoints.sm : false const handleCloseWithdraw = useCallback(() => { setShowBorrowModal(false) }, []) const handleCloseDeposit = useCallback(() => { setShowDepositModal(false) setDepositToSettle(null) }, []) const handleShowBorrow = (symbol) => { setBorrowSymbol(symbol) setShowBorrowModal(true) } const handleShowDeposit = (symbol, amount) => { setDepositToSettle({ symbol: symbol, amount: amount }) setShowDepositModal(true) } return ( <>
{t('asset')} | {t('balance')} | {t('value')} | {t('borrow-rate')} (APR) |
{asset.symbol}
|
{asset.borrows.toFixed()} | {formatUsdValue( asset.borrows .mul( mangoGroup.getPrice( tokenIndex, mangoCache ) ) .toNumber() )} | {( mangoGroup .getBorrowRate(tokenIndex) .toNumber() * 100 ).toFixed(2)} % |
|
---|
{t('asset')} | {t('price')} | {t('borrow-rate')} (APR) | {t('max-borrow')} | {t('liquidity')} |
{token.symbol}
|
{formatUsdValue( mangoGroup .getPrice(tokenIndex, mangoCache) .toNumber() )} | {i80f48ToPercent( mangoGroup.getBorrowRate(tokenIndex) ).toFixed(2)} % | {mangoAccount .getMaxWithBorrowForToken( mangoGroup, mangoCache, tokenIndex ) .mul(I80F48.fromString('0.995')) .toNumber() > 0 ? mangoAccount .getMaxWithBorrowForToken( mangoGroup, mangoCache, tokenIndex ) .mul(I80F48.fromString('0.995')) .toNumber() .toLocaleString(undefined, { minimumFractionDigits: tokenPrecision[token.symbol], maximumFractionDigits: tokenPrecision[token.symbol], }) : 0} | {mangoGroup .getUiTotalDeposit(tokenIndex) .sub(mangoGroup.getUiTotalBorrow(tokenIndex)) .toNumber() .toLocaleString(undefined, { minimumFractionDigits: tokenPrecision[token.symbol], maximumFractionDigits: tokenPrecision[token.symbol], })} |
|
---|