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 { ZERO_I80F48 } from '@blockworks-foundation/mango-client' const BalancesTable = () => { const balances = useBalances() const actions = useMangoStore((s) => s.actions) 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) await sleep(250) actions.fetchMangoAccounts() } catch (e) { console.warn('Error settling all:', e) if (e.message === 'No unsettled funds') { notify({ message: 'There are no unsettled funds', type: 'error', }) } else { notify({ message: '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) => ( ))}
Asset Deposits Borrows In Orders Unsettled Net
{balance.symbol} {balance.marginDeposits.toString()} {balance.borrows.toString()} {balance.orders} {balance.unsettled} {balance.net}
) : (
No balances
)}
) } export default BalancesTable