import { useBalances } from '../hooks/useBalances' import useMangoStore, { mangoClient } from '../stores/useMangoStore' import Button from '../components/Button' import { notify } from '../utils/notifications' import { Table, Thead, Tbody, Tr, Th, Td } from 'react-super-responsive-table' import { InformationCircleIcon } from '@heroicons/react/outline' import Tooltip from './Tooltip' import { sleep } from '../utils' import { Market } from '@project-serum/serum' import { getTokenBySymbol, ZERO_I80F48, } from '@blockworks-foundation/mango-client' const BalancesTable = () => { const balances = useBalances() const actions = useMangoStore((s) => s.actions) const mangoGroupConfig = useMangoStore((s) => s.selectedMangoGroup.config) async function handleSettleAll() { const mangoAccount = useMangoStore.getState().selectedMangoAccount.current const mangoGroup = useMangoStore.getState().selectedMangoGroup.current const markets = useMangoStore.getState().selectedMangoGroup.markets const wallet = useMangoStore.getState().wallet.current try { const spotMarkets = Object.values(markets).filter( (mkt) => mkt instanceof Market ) as Market[] await mangoClient.settleAll(mangoGroup, mangoAccount, spotMarkets, wallet) notify({ title: 'Successfully settled funds' }) await sleep(250) actions.fetchMangoAccounts() } catch (e) { console.warn('Error settling all:', e) if (e.message === 'No unsettled funds') { notify({ title: 'There are no unsettled funds', type: 'error', }) } else { notify({ title: 'Error settling funds', description: e.message, txid: e.txid, type: 'error', }) } } } return (
{balances.length > 0 && (balances.find(({ unsettled }) => unsettled > 0) || balances.find( ({ borrows, marginDeposits }) => borrows.gt(ZERO_I80F48) && marginDeposits.gt(ZERO_I80F48) )) ? (
You have unsettled funds
) : null} {balances.length ? (
{balances.map((balance, index) => { const tokenConfig = getTokenBySymbol( mangoGroupConfig, balance.symbol.toUpperCase() ) return ( ) })}
Asset Deposits Borrows In Orders Unsettled Net
{balance.symbol} {balance.marginDeposits.toFixed(tokenConfig.decimals)} {balance.borrows.toFixed(tokenConfig.decimals)} {balance.orders} {balance.unsettled} {balance.net.toFixed(tokenConfig.decimals)}
) : (
No balances
)}
) } export default BalancesTable