mango-v4-ui/components/trade/OpenOrders.tsx

641 lines
25 KiB
TypeScript
Raw Normal View History

2023-06-15 05:18:44 -07:00
import { Bank, U64_MAX_BN } from '@blockworks-foundation/mango-v4'
2022-10-31 11:26:17 -07:00
import {
PerpMarket,
PerpOrder,
2022-12-14 06:20:51 -08:00
PerpOrderType,
2022-10-31 11:26:17 -07:00
Serum3Market,
2022-12-15 02:27:08 -08:00
Serum3OrderType,
Serum3SelfTradeBehavior,
2022-10-31 11:26:17 -07:00
Serum3Side,
} from '@blockworks-foundation/mango-v4'
2022-12-12 21:00:31 -08:00
import Input from '@components/forms/Input'
2022-09-26 04:53:49 -07:00
import { IconButton } from '@components/shared/Button'
2023-01-19 17:45:08 -08:00
import ConnectEmptyState from '@components/shared/ConnectEmptyState'
2023-01-24 16:54:24 -08:00
import FormatNumericValue from '@components/shared/FormatNumericValue'
2022-10-03 17:45:43 -07:00
import Loading from '@components/shared/Loading'
import SheenLoader from '@components/shared/SheenLoader'
2022-09-13 23:24:26 -07:00
import SideBadge from '@components/shared/SideBadge'
2022-11-20 02:44:14 -08:00
import { Table, Td, Th, TrBody, TrHead } from '@components/shared/TableElements'
2022-09-26 04:33:07 -07:00
import Tooltip from '@components/shared/Tooltip'
2022-12-12 21:00:31 -08:00
import {
CheckIcon,
NoSymbolIcon,
PencilIcon,
TrashIcon,
XMarkIcon,
} from '@heroicons/react/20/solid'
2022-09-13 23:24:26 -07:00
import { Order } from '@project-serum/serum/lib/market'
2023-01-03 18:32:42 -08:00
import { useWallet } from '@solana/wallet-adapter-react'
import { PublicKey } from '@solana/web3.js'
2022-09-13 23:24:26 -07:00
import mangoStore from '@store/mangoStore'
import useMangoAccount from 'hooks/useMangoAccount'
2023-03-16 03:44:00 -07:00
import useSelectedMarket from 'hooks/useSelectedMarket'
import useUnownedAccount from 'hooks/useUnownedAccount'
import useFilledOrders from 'hooks/useFilledOrders'
2022-10-03 20:19:27 -07:00
import { useViewport } from 'hooks/useViewport'
2022-09-13 23:24:26 -07:00
import { useTranslation } from 'next-i18next'
2023-03-16 03:44:00 -07:00
import Link from 'next/link'
2022-12-12 21:00:31 -08:00
import { ChangeEvent, useCallback, useState } from 'react'
2023-02-27 23:20:11 -08:00
import { isMangoError } from 'types'
2022-09-13 23:24:26 -07:00
import { notify } from 'utils/notifications'
2023-01-24 16:54:24 -08:00
import { getDecimalCount } from 'utils/numbers'
2022-10-03 20:19:27 -07:00
import { breakpoints } from 'utils/theme'
2023-03-16 03:44:00 -07:00
import MarketLogos from './MarketLogos'
import PerpSideBadge from './PerpSideBadge'
2022-12-11 18:43:16 -08:00
import TableMarketName from './TableMarketName'
2022-09-13 23:24:26 -07:00
export const findSerum3MarketPkInOpenOrders = (
2023-07-21 11:47:53 -07:00
o: Order,
): string | undefined => {
2023-03-08 16:34:13 -08:00
const openOrders = mangoStore.getState().mangoAccount.openOrders
let foundedMarketPk: string | undefined = undefined
for (const [marketPk, orders] of Object.entries(openOrders)) {
for (const order of orders) {
if (order.orderId.eq(o.orderId)) {
foundedMarketPk = marketPk
break
}
}
if (foundedMarketPk) {
break
}
}
return foundedMarketPk
}
2022-09-13 23:24:26 -07:00
const OpenOrders = () => {
2022-10-03 03:38:05 -07:00
const { t } = useTranslation(['common', 'trade'])
2022-09-13 23:24:26 -07:00
const openOrders = mangoStore((s) => s.mangoAccount.openOrders)
2022-10-03 17:45:43 -07:00
const [cancelId, setCancelId] = useState<string>('')
2022-12-12 21:00:31 -08:00
const [modifyOrderId, setModifyOrderId] = useState<string | undefined>(
2023-07-21 11:47:53 -07:00
undefined,
2022-12-12 21:00:31 -08:00
)
2022-12-20 19:36:40 -08:00
const [loadingModifyOrder, setLoadingModifyOrder] = useState(false)
2022-12-12 21:00:31 -08:00
const [modifiedOrderSize, setModifiedOrderSize] = useState('')
const [modifiedOrderPrice, setModifiedOrderPrice] = useState('')
2022-10-03 20:19:27 -07:00
const { width } = useViewport()
const showTableView = width ? width > breakpoints.md : false
2023-01-19 19:10:15 -08:00
const { mangoAccountAddress } = useMangoAccount()
2023-01-03 18:32:42 -08:00
const { connected } = useWallet()
const { isUnownedAccount } = useUnownedAccount()
2023-03-16 03:44:00 -07:00
const { selectedMarket } = useSelectedMarket()
const { filledOrders, fetchingFilledOrders } = useFilledOrders()
2022-09-13 23:24:26 -07:00
2022-10-31 11:26:17 -07:00
const handleCancelSerumOrder = useCallback(
2022-09-13 23:24:26 -07:00
async (o: Order) => {
const client = mangoStore.getState().client
const group = mangoStore.getState().group
const mangoAccount = mangoStore.getState().mangoAccount.current
const actions = mangoStore.getState().actions
2022-09-13 23:24:26 -07:00
if (!group || !mangoAccount) return
2022-12-15 02:27:08 -08:00
const marketPk = findSerum3MarketPkInOpenOrders(o)
if (!marketPk) return
const market = group.getSerum3MarketByExternalMarket(
2023-07-21 11:47:53 -07:00
new PublicKey(marketPk),
2022-12-15 02:27:08 -08:00
)
2022-10-03 17:45:43 -07:00
setCancelId(o.orderId.toString())
2022-09-13 23:24:26 -07:00
try {
const { signature: tx } = await client.serum3CancelOrder(
2022-12-15 02:27:08 -08:00
group,
mangoAccount,
market!.serumMarketExternal,
o.side === 'buy' ? Serum3Side.bid : Serum3Side.ask,
2023-07-21 11:47:53 -07:00
o.orderId,
2022-12-15 02:27:08 -08:00
)
2022-12-14 08:01:45 -08:00
2022-12-15 02:27:08 -08:00
actions.fetchOpenOrders()
notify({
type: 'success',
title: 'Transaction successful',
txid: tx,
})
2023-02-27 23:20:11 -08:00
} catch (e) {
2022-09-13 23:24:26 -07:00
console.error('Error canceling', e)
2023-02-27 23:20:11 -08:00
if (isMangoError(e)) {
notify({
title: t('trade:cancel-order-error'),
description: e.message,
txid: e.txid,
type: 'error',
})
}
2022-10-03 17:45:43 -07:00
} finally {
setCancelId('')
2022-09-13 23:24:26 -07:00
}
},
2023-07-21 11:47:53 -07:00
[t],
2022-09-13 23:24:26 -07:00
)
2022-12-15 02:27:08 -08:00
const modifyOrder = useCallback(
async (o: PerpOrder | Order) => {
2022-10-31 11:26:17 -07:00
const client = mangoStore.getState().client
const group = mangoStore.getState().group
const mangoAccount = mangoStore.getState().mangoAccount.current
const actions = mangoStore.getState().actions
2022-12-15 02:27:08 -08:00
const baseSize = modifiedOrderSize ? Number(modifiedOrderSize) : o.size
const price = modifiedOrderPrice ? Number(modifiedOrderPrice) : o.price
2022-10-31 11:26:17 -07:00
if (!group || !mangoAccount) return
2022-12-20 19:36:40 -08:00
setLoadingModifyOrder(true)
2022-10-31 11:26:17 -07:00
try {
let tx
2022-12-15 02:27:08 -08:00
if (o instanceof PerpOrder) {
tx = await client.modifyPerpOrder(
2022-10-31 11:26:17 -07:00
group,
mangoAccount,
o.perpMarketIndex,
2022-12-15 02:27:08 -08:00
o.orderId,
o.side,
price,
Math.abs(baseSize),
undefined, // maxQuoteQuantity
Date.now(),
PerpOrderType.limit,
undefined,
2023-07-21 11:47:53 -07:00
undefined,
2022-12-15 02:27:08 -08:00
)
} else {
const marketPk = findSerum3MarketPkInOpenOrders(o)
if (!marketPk) return
const market = group.getSerum3MarketByExternalMarket(
2023-07-21 11:47:53 -07:00
new PublicKey(marketPk),
2022-12-15 02:27:08 -08:00
)
tx = await client.modifySerum3Order(
group,
o.orderId,
mangoAccount,
market.serumMarketExternal,
o.side === 'buy' ? Serum3Side.bid : Serum3Side.ask,
price,
baseSize,
Serum3SelfTradeBehavior.decrementTake,
Serum3OrderType.limit,
Date.now(),
2023-07-21 11:47:53 -07:00
10,
2022-10-31 11:26:17 -07:00
)
}
2022-12-15 02:27:08 -08:00
actions.fetchOpenOrders()
notify({
type: 'success',
title: 'Transaction successful',
txid: tx.signature,
2022-12-15 02:27:08 -08:00
})
2023-02-27 23:20:11 -08:00
} catch (e) {
2022-10-31 11:26:17 -07:00
console.error('Error canceling', e)
2023-02-27 23:20:11 -08:00
if (isMangoError(e)) {
notify({
title: 'Unable to modify order',
description: e.message,
txid: e.txid,
type: 'error',
})
}
2022-10-31 11:26:17 -07:00
} finally {
2022-12-15 02:27:08 -08:00
cancelEditOrderForm()
2022-10-31 11:26:17 -07:00
}
},
2023-07-21 11:47:53 -07:00
[t, modifiedOrderSize, modifiedOrderPrice],
2022-10-31 11:26:17 -07:00
)
2022-12-15 02:27:08 -08:00
const handleCancelPerpOrder = useCallback(
async (o: PerpOrder) => {
2022-12-14 06:20:51 -08:00
const client = mangoStore.getState().client
const group = mangoStore.getState().group
const mangoAccount = mangoStore.getState().mangoAccount.current
const actions = mangoStore.getState().actions
if (!group || !mangoAccount) return
2022-12-15 02:27:08 -08:00
setCancelId(o.orderId.toString())
2022-12-14 06:20:51 -08:00
try {
const { signature: tx } = await client.perpCancelOrder(
2022-12-15 02:27:08 -08:00
group,
mangoAccount,
o.perpMarketIndex,
2023-07-21 11:47:53 -07:00
o.orderId,
2022-12-15 02:27:08 -08:00
)
2023-09-12 06:32:09 -07:00
actions.fetchOpenOrders(true)
2022-12-15 02:27:08 -08:00
notify({
type: 'success',
title: 'Transaction successful',
txid: tx,
})
2023-02-27 23:20:11 -08:00
} catch (e) {
2022-12-14 06:20:51 -08:00
console.error('Error canceling', e)
2023-02-27 23:20:11 -08:00
if (isMangoError(e)) {
notify({
title: t('trade:cancel-order-error'),
description: e.message,
txid: e.txid,
type: 'error',
})
}
2022-12-14 06:20:51 -08:00
} finally {
2022-12-15 02:27:08 -08:00
setCancelId('')
2022-12-14 06:20:51 -08:00
}
},
2023-07-21 11:47:53 -07:00
[t],
2022-12-14 06:20:51 -08:00
)
2022-12-15 22:19:54 -08:00
const showEditOrderForm = (order: Order | PerpOrder, tickSize: number) => {
2022-12-12 21:00:31 -08:00
setModifyOrderId(order.orderId.toString())
2022-12-18 13:05:00 -08:00
setModifiedOrderSize(order.size.toString())
2022-12-15 22:19:54 -08:00
setModifiedOrderPrice(order.price.toFixed(getDecimalCount(tickSize)))
2022-12-12 21:00:31 -08:00
}
2022-12-14 08:01:45 -08:00
const cancelEditOrderForm = () => {
setModifyOrderId(undefined)
2022-12-20 19:36:40 -08:00
setLoadingModifyOrder(false)
2022-12-14 08:01:45 -08:00
setModifiedOrderSize('')
setModifiedOrderPrice('')
}
2022-12-12 21:00:31 -08:00
2023-01-19 19:10:15 -08:00
return mangoAccountAddress && Object.values(openOrders).flat().length ? (
showTableView ? (
<Table>
<thead>
<TrHead>
<Th className="w-[14.28%] text-left">{t('market')}</Th>
<Th className="w-[14.28%] text-right">{t('trade:size')}</Th>
<Th className="w-[14.28%] text-right">{t('price')}</Th>
2023-08-31 04:40:25 -07:00
<Th className="w-[14.28%] text-right">{t('trade:filled')}</Th>
<Th className="w-[14.28%] text-right">{t('value')}</Th>
{!isUnownedAccount ? (
<Th className="w-[14.28%] text-right" />
) : null}
</TrHead>
</thead>
<tbody>
{Object.entries(openOrders)
2023-03-08 16:34:13 -08:00
.sort()
.map(([marketPk, orders]) => {
return orders.map((o) => {
const group = mangoStore.getState().group!
let market: PerpMarket | Serum3Market
let tickSize: number
let minOrderSize: number
let expiryTimestamp: number | undefined
2023-06-15 05:18:44 -07:00
let value: number
let filledQuantity = 0
if (o instanceof PerpOrder) {
market = group.getPerpMarketByMarketIndex(o.perpMarketIndex)
tickSize = market.tickSize
minOrderSize = market.minOrderSize
2023-02-21 14:25:45 -08:00
expiryTimestamp =
o.expiryTimestamp === U64_MAX_BN
? 0
: o.expiryTimestamp.toNumber()
2023-06-15 05:18:44 -07:00
value = o.size * o.price
// Find the filled perp order,
// the api returns client order ids for perps, but PerpOrder[] only has orderId
const mangoAccount =
mangoStore.getState().mangoAccount.current
const perpClientId = mangoAccount?.perpOpenOrders?.find((p) =>
p.id.eq(o.orderId),
)?.clientId
if (perpClientId) {
const filledOrder = filledOrders?.fills?.find(
(f) => f.order_id == perpClientId.toString(),
)
filledQuantity = filledOrder ? filledOrder.quantity : 0
}
} else {
market = group.getSerum3MarketByExternalMarket(
2023-07-21 11:47:53 -07:00
new PublicKey(marketPk),
2022-10-04 18:59:04 -07:00
)
const serumMarket = group.getSerum3ExternalMarket(
2023-07-21 11:47:53 -07:00
market.serumMarketExternal,
)
2023-06-15 05:18:44 -07:00
const quoteBank = group.getFirstBankByTokenIndex(
2023-07-21 11:47:53 -07:00
market.quoteTokenIndex,
2023-06-15 05:18:44 -07:00
)
tickSize = serumMarket.tickSize
minOrderSize = serumMarket.minOrderSize
2023-06-15 05:18:44 -07:00
value = o.size * o.price * quoteBank.uiPrice
const filledOrder = filledOrders?.fills?.find(
(f) => o.orderId.toString() === f.order_id,
)
filledQuantity = filledOrder ? filledOrder.quantity : 0
}
2023-06-28 18:04:53 -07:00
const side =
o instanceof PerpOrder
? 'bid' in o.side
2023-07-01 03:07:15 -07:00
? 'long'
: 'short'
2023-06-28 18:04:53 -07:00
: o.side
return (
<TrBody
2023-03-08 16:34:13 -08:00
key={`${o.side}${o.size}${o.price}${o.orderId.toString()}`}
className="my-1 p-2"
>
<Td className="w-[14.28%]">
2023-06-28 18:04:53 -07:00
<TableMarketName market={market} side={side} />
</Td>
2022-12-20 19:36:40 -08:00
{modifyOrderId !== o.orderId.toString() ? (
<>
<Td className="w-[14.28%] text-right font-mono">
2023-02-12 21:08:32 -08:00
<FormatNumericValue
value={o.size}
decimals={getDecimalCount(minOrderSize)}
/>
</Td>
<Td className="w-[14.28%] whitespace-nowrap text-right font-mono">
2023-02-12 21:08:32 -08:00
<FormatNumericValue
value={o.price}
decimals={getDecimalCount(tickSize)}
/>
</Td>
</>
2022-12-20 19:36:40 -08:00
) : (
<>
<Td className="w-[14.28%]">
2023-01-19 20:06:14 -08:00
<input
2023-04-19 18:12:45 -07:00
className="h-8 w-full rounded-l-none rounded-r-none border-b-2 border-l-0 border-r-0 border-t-0 border-th-bkg-4 bg-transparent px-0 text-right font-mono text-sm hover:border-th-fgd-3 focus:border-th-fgd-3 focus:outline-none"
2022-12-20 19:36:40 -08:00
type="text"
value={modifiedOrderSize}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
setModifiedOrderSize(e.target.value)
}
/>
</Td>
<Td className="w-[14.28%]">
2023-01-19 20:06:14 -08:00
<input
2022-12-20 19:36:40 -08:00
autoFocus
2023-04-19 18:12:45 -07:00
className="h-8 w-full rounded-l-none rounded-r-none border-b-2 border-l-0 border-r-0 border-t-0 border-th-bkg-4 bg-transparent px-0 text-right font-mono text-sm hover:border-th-fgd-3 focus:border-th-fgd-3 focus:outline-none"
2022-12-20 19:36:40 -08:00
type="text"
value={modifiedOrderPrice}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
setModifiedOrderPrice(e.target.value)
}
/>
</Td>
</>
2022-12-20 19:36:40 -08:00
)}
<Td className="w-[14.28%] text-right font-mono">
2023-08-31 04:40:25 -07:00
{fetchingFilledOrders ? (
<div className="items flex justify-end">
<SheenLoader className="flex justify-end">
<div className="h-4 w-8 bg-th-bkg-2" />
</SheenLoader>
</div>
) : (
<FormatNumericValue
value={filledQuantity}
decimals={getDecimalCount(minOrderSize)}
/>
)}
</Td>
<Td className="w-[14.28%] text-right font-mono">
2023-06-15 05:18:44 -07:00
<FormatNumericValue value={value} isUsd />
{expiryTimestamp ? (
<div className="h-min text-xxs leading-tight text-th-fgd-4">{`Expires ${new Date(
2023-07-21 11:47:53 -07:00
expiryTimestamp * 1000,
).toLocaleTimeString()}`}</div>
) : null}
</Td>
{!isUnownedAccount ? (
<Td className="w-[14.28%]">
<div className="flex justify-end space-x-2">
{modifyOrderId !== o.orderId.toString() ? (
<>
<IconButton
onClick={() => showEditOrderForm(o, tickSize)}
size="small"
>
<PencilIcon className="h-4 w-4" />
</IconButton>
<Tooltip content={t('cancel')}>
<IconButton
disabled={cancelId === o.orderId.toString()}
onClick={() =>
o instanceof PerpOrder
? handleCancelPerpOrder(o)
: handleCancelSerumOrder(o)
}
size="small"
>
{cancelId === o.orderId.toString() ? (
<Loading className="h-4 w-4" />
) : (
<TrashIcon className="h-4 w-4" />
)}
</IconButton>
</Tooltip>
</>
) : (
<>
<IconButton
onClick={() => modifyOrder(o)}
size="small"
>
{loadingModifyOrder ? (
<Loading className="h-4 w-4" />
) : (
<CheckIcon className="h-4 w-4" />
)}
</IconButton>
<IconButton
onClick={cancelEditOrderForm}
size="small"
>
<XMarkIcon className="h-4 w-4" />
</IconButton>
</>
)}
</div>
</Td>
) : null}
</TrBody>
)
})
})
.flat()}
</tbody>
</Table>
) : (
<div>
{Object.entries(openOrders).map(([marketPk, orders]) => {
return orders.map((o) => {
const group = mangoStore.getState().group!
let market: PerpMarket | Serum3Market
let tickSize: number
let minOrderSize: number
2023-06-15 05:18:44 -07:00
let quoteBank: Bank | undefined
if (o instanceof PerpOrder) {
market = group.getPerpMarketByMarketIndex(o.perpMarketIndex)
tickSize = market.tickSize
minOrderSize = market.minOrderSize
} else {
market = group.getSerum3MarketByExternalMarket(
2023-07-21 11:47:53 -07:00
new PublicKey(marketPk),
)
const serumMarket = group.getSerum3ExternalMarket(
2023-07-21 11:47:53 -07:00
market.serumMarketExternal,
)
2023-06-15 05:18:44 -07:00
quoteBank = group.getFirstBankByTokenIndex(market.quoteTokenIndex)
tickSize = serumMarket.tickSize
minOrderSize = serumMarket.minOrderSize
}
return (
<div
className="flex items-center justify-between border-b border-th-bkg-3 p-4"
key={`${o.side}${o.size}${o.price}`}
>
<div>
{modifyOrderId !== o.orderId.toString() ? (
<div className="flex items-center">
<MarketLogos market={market} size="large" />
<div>
<div className="flex space-x-1 text-th-fgd-2">
2023-03-16 03:44:00 -07:00
{selectedMarket?.name === market.name ? (
<span className="whitespace-nowrap">
{market.name}
</span>
) : (
<Link href={`/trade?name=${market.name}`}>
<span className="whitespace-nowrap">
{market.name}
</span>
2023-03-16 03:44:00 -07:00
</Link>
)}
{o instanceof PerpOrder ? (
<PerpSideBadge
basePosition={'bid' in o.side ? 1 : -1}
/>
) : (
<SideBadge side={o.side} />
)}
</div>
<p className="text-th-fgd-4">
<span className="font-mono text-th-fgd-2">
2023-03-16 03:44:00 -07:00
<FormatNumericValue
value={o.size}
decimals={getDecimalCount(minOrderSize)}
/>
</span>
{' at '}
<span className="font-mono text-th-fgd-2">
2023-03-16 03:44:00 -07:00
<FormatNumericValue
value={o.price}
decimals={getDecimalCount(tickSize)}
isUsd={
quoteBank?.name === 'USDC' ||
o instanceof PerpOrder
}
2023-06-15 05:18:44 -07:00
/>{' '}
{quoteBank && quoteBank.name !== 'USDC' ? (
<span className="font-body text-th-fgd-3">
{quoteBank.name}
</span>
) : null}
2023-03-16 03:44:00 -07:00
</span>
</p>
<span className="font-mono text-xs text-th-fgd-3">
<FormatNumericValue value={o.price * o.size} isUsd />
</span>
</div>
2022-12-12 21:00:31 -08:00
</div>
2023-03-16 03:44:00 -07:00
) : (
<>
<p className="text-th-fgd-2">{`${t('edit')} ${
market.name
} ${t('order')}`}</p>
<div className="mt-2 flex space-x-4">
<div>
<p className="text-xs">{t('trade:size')}</p>
<Input
2023-04-19 18:12:45 -07:00
className="w-full rounded-l-none rounded-r-none border-b-2 border-l-0 border-r-0 border-t-0 border-th-bkg-4 bg-transparent px-0 text-right font-mono hover:border-th-fgd-3 focus:border-th-fgd-3 focus:outline-none"
2023-03-16 03:44:00 -07:00
type="text"
value={modifiedOrderSize}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
setModifiedOrderSize(e.target.value)
}
/>
</div>
<div>
<p className="text-xs">{t('price')}</p>
<Input
autoFocus
2023-04-19 18:12:45 -07:00
className="w-full rounded-l-none rounded-r-none border-b-2 border-l-0 border-r-0 border-t-0 border-th-bkg-4 bg-transparent px-0 text-right font-mono hover:border-th-fgd-3 focus:border-th-fgd-3 focus:outline-none"
2023-03-16 03:44:00 -07:00
type="text"
value={modifiedOrderPrice}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
setModifiedOrderPrice(e.target.value)
}
/>
</div>
</div>
</>
)}
</div>
{!isUnownedAccount ? (
<div className="flex items-center space-x-3 pl-8">
<div className="flex items-center space-x-2">
{modifyOrderId !== o.orderId.toString() ? (
<>
<IconButton
onClick={() => showEditOrderForm(o, tickSize)}
2023-03-16 03:44:00 -07:00
size="small"
>
<PencilIcon className="h-4 w-4" />
</IconButton>
<IconButton
disabled={cancelId === o.orderId.toString()}
onClick={() =>
o instanceof PerpOrder
? handleCancelPerpOrder(o)
: handleCancelSerumOrder(o)
}
2023-03-16 03:44:00 -07:00
size="small"
>
{cancelId === o.orderId.toString() ? (
<Loading className="h-4 w-4" />
) : (
<TrashIcon className="h-4 w-4" />
)}
</IconButton>
</>
) : (
<>
2023-01-19 15:49:49 -08:00
<IconButton
onClick={() => modifyOrder(o)}
2023-03-16 03:44:00 -07:00
size="small"
2023-01-19 15:49:49 -08:00
>
{loadingModifyOrder ? (
<Loading className="h-4 w-4" />
) : (
<CheckIcon className="h-4 w-4" />
)}
</IconButton>
2023-01-19 15:49:49 -08:00
<IconButton
onClick={cancelEditOrderForm}
2023-03-16 03:44:00 -07:00
size="small"
2023-01-19 15:49:49 -08:00
>
<XMarkIcon className="h-4 w-4" />
</IconButton>
</>
)}
</div>
2022-10-03 20:19:27 -07:00
</div>
) : null}
</div>
)
})
})}
2022-09-19 04:32:59 -07:00
</div>
)
2023-01-19 19:10:15 -08:00
) : mangoAccountAddress || connected ? (
2023-10-17 04:28:43 -07:00
<div className="flex flex-1 flex-col items-center justify-center">
<div className="flex flex-col items-center p-8">
<NoSymbolIcon className="mb-2 h-6 w-6 text-th-fgd-4" />
<p>{t('trade:no-orders')}</p>
</div>
2022-09-19 04:32:59 -07:00
</div>
2023-01-19 17:45:08 -08:00
) : (
2023-10-17 04:28:43 -07:00
<div className="flex flex-1 flex-col items-center justify-center p-8">
2023-01-19 17:45:08 -08:00
<ConnectEmptyState text={t('trade:connect-orders')} />
</div>
2022-09-13 23:24:26 -07:00
)
}
export default OpenOrders