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 { floorToDecimal, 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' export default function AccountBorrows() { 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) => { setDepositToSettle({ symbol: symbol }) setShowDepositModal(true) } return ( <>
Asset | Balance | Value | Borrow Rate (APR) |
{asset.symbol}
|
{asset.borrows.toFixed( tokenPrecision[asset.symbol] )} | {formatUsdValue( asset.borrows.mul( mangoGroup.getPrice(tokenIndex, mangoCache) ) )} | {( mangoGroup .getBorrowRate(tokenIndex) .toNumber() * 100 ).toFixed(2)} % |
|
---|
Asset | Price | Borrow Rate (APR) | Max Borrow Amount | Liquidity |
{token.symbol}
|
{formatUsdValue( mangoGroup.getPrice(tokenIndex, mangoCache) )} | {i80f48ToPercent( mangoGroup.getBorrowRate(tokenIndex) ).toFixed(2)} % | {mangoAccount .getMaxWithBorrowForToken( mangoGroup, mangoCache, tokenIndex ) .mul(I80F48.fromString('0.995')) .toNumber() > 0 ? floorToDecimal( mangoAccount .getMaxWithBorrowForToken( mangoGroup, mangoCache, tokenIndex ) .mul(I80F48.fromString('0.995')) .toNumber(), mangoGroup.tokens[tokenIndex].decimals ) : 0} {/* floorToDecimal(parseFloat(maxWithdraw.toFixed()), token.decimals) */} | {mangoGroup .getUiTotalDeposit(tokenIndex) .sub(mangoGroup.getUiTotalBorrow(tokenIndex)) .toNumber() .toLocaleString(undefined, { minimumFractionDigits: tokenPrecision[token.symbol], maximumFractionDigits: tokenPrecision[token.symbol], })} |
|
---|