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 Button, { LinkButton } from './Button' import Loading from './Loading' 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' import { usdFormatter } from '../utils' const OpenOrdersTable = () => { const { asPath } = useRouter() const openOrders = useOpenOrders() const { items, requestSort, sortConfig } = useSortableData(openOrders) const [cancelId, setCancelId] = useState(null) 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 selectedMangoAccount = useMangoStore.getState().selectedMangoAccount.current setCancelId(order.orderId) try { if (!selectedMangoGroup || !selectedMangoAccount) return if (market instanceof Market) { await mangoClient.cancelSpotOrder( selectedMangoGroup, selectedMangoAccount, wallet, market, order as Order ) } else if (market instanceof PerpMarket) { await mangoClient.cancelPerpOrder( selectedMangoGroup, selectedMangoAccount, wallet, market, order as PerpOrder ) } actions.updateOpenOrders() actions.fetchMangoAccounts() } catch (e) { notify({ title: '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} | {usdFormatter.format(order.price)} |
|