import { useState } from 'react' import { TrashIcon } from '@heroicons/react/solid' import { useOpenOrders } from '../hooks/useOpenOrders' import { cancelOrderAndSettle } from '../utils/mango' import Button from './Button' import Loading from './Loading' import { PublicKey } from '@solana/web3.js' import useConnection from '../hooks/useConnection' import useMangoStore from '../stores/useMangoStore' import { notify } from '../utils/notifications' const OpenOrdersTable = () => { const openOrders = useOpenOrders() const [cancelId, setCancelId] = useState(null) const { connection, programId } = useConnection() const handleCancelOrder = async (order) => { const wallet = useMangoStore.getState().wallet.current const selectedMangoGroup = useMangoStore.getState().selectedMangoGroup .current const selectedMarginAccount = useMangoStore.getState().selectedMarginAccount .current setCancelId(order?.orderId) try { if (!selectedMangoGroup || !selectedMarginAccount) return await cancelOrderAndSettle( connection, new PublicKey(programId), selectedMangoGroup, selectedMarginAccount, wallet, order.market, order ) notify({ message: 'Order cancelled', type: 'success', }) } catch (e) { notify({ message: 'Error cancelling order', description: e.message, type: 'error', }) return } finally { setCancelId(null) } } return (
{openOrders && openOrders.length > 0 ? (
{openOrders.map((order, index) => ( ))}
Market Side Size Price Edit
{order.marketName}
{order.side.toUpperCase()}
{order.size} {order.price}
) : (
No open orders
)}
) } export default OpenOrdersTable