diff --git a/components/BalancesTable.tsx b/components/BalancesTable.tsx index cedbef34..3cec701e 100644 --- a/components/BalancesTable.tsx +++ b/components/BalancesTable.tsx @@ -1,16 +1,24 @@ -import { useCallback, useState } from 'react' +import { useCallback, useMemo, useState } from 'react' import useMangoStore from '../stores/useMangoStore' -import Button, { LinkButton } from '../components/Button' +import Button from '../components/Button' import { notify } from '../utils/notifications' -import { ArrowSmDownIcon, ExclamationIcon } from '@heroicons/react/solid' +import { ExclamationIcon, InformationCircleIcon } from '@heroicons/react/solid' import { Market } from '@project-serum/serum' -import { getTokenBySymbol } from '@blockworks-foundation/mango-client' +import { + getMarketIndexBySymbol, + getTokenBySymbol, + ZERO_I80F48, +} from '@blockworks-foundation/mango-client' import Loading from './Loading' import { useViewport } from '../hooks/useViewport' import { breakpoints } from './TradePageGrid' -import { floorToDecimal, formatUsdValue, getPrecisionDigits } from '../utils' +import { + floorToDecimal, + formatUsdValue, + getPrecisionDigits, + usdFormatter, +} from '../utils' import { ExpandableRow, Table, Td, Th, TrBody, TrHead } from './TableElements' -import { useSortableData } from '../hooks/useSortableData' import DepositModal from './DepositModal' import WithdrawModal from './WithdrawModal' import MobileTableHeader from './mobile/MobileTableHeader' @@ -19,6 +27,7 @@ import { TransactionSignature } from '@solana/web3.js' import Link from 'next/link' import { useRouter } from 'next/router' import { useWallet } from '@solana/wallet-adapter-react' +import Tooltip from './Tooltip' const BalancesTable = ({ showZeroBalances = false, @@ -30,8 +39,9 @@ const BalancesTable = ({ const [showWithdrawModal, setShowWithdrawModal] = useState(false) const [actionSymbol, setActionSymbol] = useState('') const spotBalances = useMangoStore((s) => s.selectedMangoAccount.spotBalances) - const { items, requestSort, sortConfig } = useSortableData( - spotBalances?.length > 0 + + const balances = useMemo(() => { + return spotBalances?.length > 0 ? spotBalances .filter((bal) => { return ( @@ -48,10 +58,12 @@ const BalancesTable = ({ return bV - aV }) : [] - ) + }, [spotBalances]) + const actions = useMangoStore((s) => s.actions) const mangoGroup = useMangoStore((s) => s.selectedMangoGroup.current) const mangoGroupConfig = useMangoStore((s) => s.selectedMangoGroup.config) + const mangoCache = useMangoStore((s) => s.selectedMangoGroup.cache) const selectedMarket = useMangoStore((s) => s.selectedMarket.current) const marketConfig = useMangoStore((s) => s.selectedMarket.config) const setMangoStore = useMangoStore((s) => s.set) @@ -248,168 +260,35 @@ const BalancesTable = ({ ) : null}
- {items.length > 0 ? ( + {balances.length > 0 ? ( !isMobile ? ( + + + + + + + - - - - - - - - {items.map((balance, index) => { + {balances.map((balance, index) => { if ( !balance || typeof balance.decimals !== 'number' || @@ -422,6 +301,25 @@ const BalancesTable = ({ ) { return null } + + const marketIndex = getMarketIndexBySymbol( + mangoGroupConfig, + balance.symbol + ) + + const liquidationPrice = + mangoGroup && + mangoAccount && + marketIndex && + mangoGroup && + mangoCache + ? mangoAccount.getLiquidationPrice( + mangoGroup, + mangoCache, + marketIndex + ) + : undefined + return ( + -
{t('asset')}{t('deposits')}{t('borrows')}{t('in-orders')}{t('unsettled')}{t('net-balance')}{t('value')} - requestSort('symbol')} - > - {t('asset')} - - + + + {t('estimated-liq-price')} + + + - requestSort('deposits')} - > - {t('deposits')} - - - - requestSort('borrows')} - > - {t('borrows')} - - - - requestSort('orders')} - > - {t('in-orders')} - - - - requestSort('unsettled')} - > - {t('unsettled')} - - - - requestSort('net')} - > - {t('net-balance')} - - - - requestSort('value')} - > - {t('value')} - - - - requestSort('depositRate')} - > - {t('deposit-rate')} - - - - requestSort('borrowRate')} - > - {t('borrow-rate')} - - + {t('deposit')} + | + {t('borrow')} (APR)
@@ -498,12 +396,16 @@ const BalancesTable = ({ )} {formatUsdValue(balance.value.toNumber())} + {liquidationPrice && liquidationPrice.gt(ZERO_I80F48) + ? usdFormatter(liquidationPrice) + : '–'} + {balance.depositRate.toFixed(2)}% - + | {balance.borrowRate.toFixed(2)}% @@ -564,7 +466,7 @@ const BalancesTable = ({ colOneHeader={t('asset')} colTwoHeader={t('net-balance')} /> - {items.map((balance, index) => { + {balances.map((balance, index) => { if ( !balance || typeof balance.decimals !== 'number' || @@ -579,6 +481,23 @@ const BalancesTable = ({ ) { return null } + const marketIndex = getMarketIndexBySymbol( + mangoGroupConfig, + balance.symbol + ) + + const liquidationPrice = + mangoGroup && + mangoAccount && + marketIndex && + mangoGroup && + mangoCache + ? mangoAccount.getLiquidationPrice( + mangoGroup, + mangoCache, + marketIndex + ) + : undefined return ( {formatUsdValue(balance.value.toNumber())} +
+
+ + + {t('estimated-liq-price')} + + + +
+ {liquidationPrice && + liquidationPrice.gt(ZERO_I80F48) + ? usdFormatter(liquidationPrice) + : '–'} +
- {t('rates')} + {t('deposit')} + | + {`${t('borrow')} (APR)`}
- + {balance.depositRate.toFixed(2)}% - / - + | + {balance.borrowRate.toFixed(2)}%
@@ -666,6 +603,7 @@ const BalancesTable = ({ onClick={() => handleOpenWithdrawModal(balance.symbol) } + primary={false} > {t('withdraw')} diff --git a/components/PerpPositionsTable.tsx b/components/PerpPositionsTable.tsx index dc5d64dd..2801051c 100644 --- a/components/PerpPositionsTable.tsx +++ b/components/PerpPositionsTable.tsx @@ -559,7 +559,14 @@ const PositionsTable: React.FC = () => {
- {t('estimated-liq-price')} + + + {t('estimated-liq-price')} + + +
{liquidationPrice && liquidationPrice.gt(ZERO_I80F48)