import { Bank, Group } from '@blockworks-foundation/mango-v4' import { ArrowDownRightIcon, ArrowUpLeftIcon, ChevronDownIcon, NoSymbolIcon, } from '@heroicons/react/20/solid' import useMangoAccount from 'hooks/useMangoAccount' import { useViewport } from 'hooks/useViewport' import { useTranslation } from 'next-i18next' import { formatNumericValue } from 'utils/numbers' import { breakpoints } from 'utils/theme' import { Table, Td, Th, TrBody, TrHead } from '../shared/TableElements' import useMangoGroup from 'hooks/useMangoGroup' import ConnectEmptyState from '../shared/ConnectEmptyState' import { useWallet } from '@solana/wallet-adapter-react' import Decimal from 'decimal.js' import Button, { IconButton } from '@components/shared/Button' import { useCallback, useState } from 'react' import BorrowRepayModal from '@components/modals/BorrowRepayModal' import Tooltip from '@components/shared/Tooltip' import BankAmountWithValue from '@components/shared/BankAmountWithValue' import { BankWithBalance } from 'hooks/useBanksWithBalances' import { Disclosure, Transition } from '@headlessui/react' import TokenLogo from '@components/shared/TokenLogo' export const getAvailableToBorrow = ( bankWithBal: BankWithBalance, group: Group, ) => { const { balance, bank, maxBorrow } = bankWithBal const { mint, mintDecimals, minVaultToDepositsRatio } = bankWithBal.bank const deposits = bank.uiDeposits() const availableVaultBalance = group.getTokenVaultBalanceByMintUi(mint) - deposits * minVaultToDepositsRatio const availableAccountBorrow = balance > 0 ? maxBorrow - balance : maxBorrow const available = Decimal.min( availableAccountBorrow.toFixed(bank.mintDecimals), Decimal.max(0, availableVaultBalance.toFixed(mintDecimals)), ) return available } const YourBorrowsTable = ({ banks }: { banks: BankWithBalance[] }) => { const { t } = useTranslation(['common', 'trade']) const [showBorrowModal, setShowBorrowModal] = useState(false) const [showRepayModal, setShowRepayModal] = useState(false) const [selectedToken, setSelectedToken] = useState('') const { mangoAccount, mangoAccountAddress } = useMangoAccount() const { group } = useMangoGroup() const { width } = useViewport() const { connected } = useWallet() const showTableView = width ? width > breakpoints.md : false const handleShowActionModals = useCallback( (token: string, action: 'borrow' | 'repay') => { setSelectedToken(token) action === 'borrow' ? setShowBorrowModal(true) : setShowRepayModal(true) }, [], ) return ( <> {banks?.length ? ( showTableView ? (
{t('token')} | {t('borrow:borrowed-amount')} |
|
{t('rate')} |
|
|
|
{formatNumericValue(bank.getBorrowRateUi(), 2)}% |
|
---|
{bank.name}
{t('borrow:borrowed-amount')}
{t('rate')}
{formatNumericValue(bank.getBorrowRateUi(), 2)}%
{t('available')}
{t('borrow:no-borrows')}