import { useState } from 'react' import Link from 'next/link' import { ArrowSmDownIcon } from '@heroicons/react/solid' import { useRouter } from 'next/router' import { useOpenOrders } from '../hooks/useOpenOrders' // import { cancelOrderAndSettle } from '../utils/mango' import Button, { LinkButton } from './Button' import Loading from './Loading' // import { PublicKey } from '@solana/web3.js' // import useConnection from '../hooks/useConnection' import useMangoStore, { mangoClient } from '../stores/useMangoStore' import { notify } from '../utils/notifications' import { Table, Thead, Tbody, Tr, Th, Td } from 'react-super-responsive-table' import SideBadge from './SideBadge' import { useSortableData } from '../hooks/useSortableData' import { Order, Market } from '@project-serum/serum/lib/market' import { PerpOrder, PerpMarket } from '@blockworks-foundation/mango-client' const OpenOrdersTable = () => { const { asPath } = useRouter() const openOrders = useOpenOrders() const { items, requestSort, sortConfig } = useSortableData(openOrders) const [cancelId, setCancelId] = useState(null) // const { connection, programId } = useConnection() const actions = useMangoStore((s) => s.actions) const handleCancelOrder = async (order: Order | PerpOrder, market: Market | PerpMarket) => { 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 if (market instanceof Market) { await mangoClient.cancelSpotOrder( selectedMangoGroup, selectedMarginAccount, wallet, market, order as Order ) } else if (market instanceof PerpMarket) { await mangoClient.cancelPerpOrder( selectedMangoGroup, selectedMarginAccount, wallet, market, order as PerpOrder ) } actions.fetchMarginAccounts() } catch (e) { notify({ message: 'Error cancelling order', description: e.message, txid: e.txid, type: 'error', }) console.log('error', `${e}`) return } finally { setCancelId(null) } } return (
|
|
|
|
Edit |
---|---|---|---|---|
{market.config.name}
|
|
{order.size} | {order.price} |
{/* Todo: support order modification */}
{/* */}
|