import { useCallback, useState } from 'react' import { ExternalLinkIcon, InformationCircleIcon, } from '@heroicons/react/outline' import FloatingElement from './FloatingElement' import { ElementTitle } from './styles' import useMangoStore from '../stores/useMangoStore' import useMarketList from '../hooks/useMarketList' import { floorToDecimal, tokenPrecision } from '../utils/index' import DepositModal from './DepositModal' import WithdrawModal from './WithdrawModal' import Button from './Button' import Tooltip from './Tooltip' import MarginAccountSelect from './MarginAccountSelect' import { MarginAccount } from '@blockworks-foundation/mango-client' export default function MarginBalances() { const setMangoStore = useMangoStore((s) => s.set) const marginAccounts = useMangoStore((s) => s.marginAccounts) const selectedMangoGroup = useMangoStore((s) => s.selectedMangoGroup.current) const selectedMarginAccount = useMangoStore( (s) => s.selectedMarginAccount.current ) const connected = useMangoStore((s) => s.wallet.connected) const { symbols } = useMarketList() const [showDepositModal, setShowDepositModal] = useState(false) const [showWithdrawModal, setShowWithdrawModal] = useState(false) const handleCloseDeposit = useCallback(() => { setShowDepositModal(false) }, []) const handleCloseWithdraw = useCallback(() => { setShowWithdrawModal(false) }, []) const handleMarginAccountChange = (marginAccount: MarginAccount) => { setMangoStore((state) => { state.selectedMarginAccount.current = marginAccount }) } return ( <> Margin Account } >
{marginAccounts.length > 1 ? ( ) : null}
{selectedMangoGroup ? ( {Object.entries(symbols).map(([name], i) => ( ))}
Assets Deposits Borrows APY / APR
{name} {selectedMarginAccount ? floorToDecimal( selectedMarginAccount.getUiDeposit( selectedMangoGroup, i ), tokenPrecision[name] ).toFixed(tokenPrecision[name]) : (0).toFixed(tokenPrecision[name])} {selectedMarginAccount ? selectedMarginAccount .getUiBorrow(selectedMangoGroup, i) .toFixed(tokenPrecision[name]) : (0).toFixed(tokenPrecision[name])} +{(selectedMangoGroup.getDepositRate(i) * 100).toFixed(2)} % {' / '} -{(selectedMangoGroup.getBorrowRate(i) * 100).toFixed(2)}%
) : null}
Settle funds in the Balances tab
{showDepositModal && ( )} {showWithdrawModal && ( )} ) } const AddressTooltip = ({ owner, marginAccount, }: { owner?: string marginAccount?: string }) => { return ( <> {owner && marginAccount ? ( <>
Margin Account:
{marginAccount.toString().substr(0, 5) + '...' + marginAccount.toString().substr(-5)}
Account Owner:
{owner.toString().substr(0, 5) + '...' + owner.toString().substr(-5)}
) : ( 'Connect a wallet and deposit funds to start trading' )} ) }