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}
{t('asset')} | +{t('deposits')} | +{t('borrows')} | +{t('in-orders')} | +{t('unsettled')} | +{t('net-balance')} | +{t('value')} |
- |
- |
-
- |
-
- |
-
- |
-
- |
-
- |
-
- |
-
- |
@@ -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 (
+
+
+ {liquidationPrice &&
+ liquidationPrice.gt(ZERO_I80F48)
+ ? usdFormatter(liquidationPrice)
+ : '–'}
+
- {t('rates')}
+ {t('deposit')}
+ |
+ {`${t('borrow')} (APR)`}
-
+
{balance.depositRate.toFixed(2)}%
- /
-
+ |
+
{balance.borrowRate.toFixed(2)}%
- {t('estimated-liq-price')}
+
{liquidationPrice &&
liquidationPrice.gt(ZERO_I80F48)
|
---|