import { useState } from 'react' import Link from 'next/link' import { useRouter } from 'next/router' import { useOpenOrders } from '../hooks/useOpenOrders' import Button from './Button' import Loading from './Loading' import useMangoStore, { mangoClient } from '../stores/useMangoStore' import { notify } from '../utils/notifications' import SideBadge from './SideBadge' import { Order, Market } from '@project-serum/serum/lib/market' import { PerpOrder, PerpMarket } from '@blockworks-foundation/mango-client' import { formatUsdValue, sleep } from '../utils' import { Table, Td, Th, TrBody, TrHead } from './TableElements' import { useViewport } from '../hooks/useViewport' import { breakpoints } from './TradePageGrid' import { Row } from './TableElements' import MobileTableHeader from './mobile/MobileTableHeader' const OpenOrdersTable = () => { const { asPath } = useRouter() const openOrders = useOpenOrders() const [cancelId, setCancelId] = useState(null) const actions = useMangoStore((s) => s.actions) const { width } = useViewport() const isMobile = width ? width < breakpoints.md : false 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) let txid try { if (!selectedMangoGroup || !selectedMangoAccount) return if (market instanceof Market) { txid = await mangoClient.cancelSpotOrder( selectedMangoGroup, selectedMangoAccount, wallet, market, order as Order ) } else if (market instanceof PerpMarket) { txid = await mangoClient.cancelPerpOrder( selectedMangoGroup, selectedMangoAccount, wallet, market, order as PerpOrder, false ) } notify({ title: 'Successfully cancelled order', txid }) } catch (e) { notify({ title: 'Error cancelling order', description: e.message, txid: e.txid, type: 'error', }) console.log('error', `${e}`) } finally { await sleep(600) actions.reloadMangoAccount() actions.updateOpenOrders() setCancelId(null) } } return (
Market | Side | Size | Price | Value | Edit |
{market.config.name}
|
|
{order.size} | {formatUsdValue(order.price)} | {formatUsdValue(order.price * order.size)} |
|
---|