fix tx and order cancel
This commit is contained in:
parent
98e9dc563a
commit
d7b1dad009
6 changed files with 32 additions and 15 deletions
|
|
@ -289,10 +289,7 @@ export function buildMyRequestsColumns({
|
|||
width: '80px',
|
||||
align: 'left',
|
||||
cell: (row) => (
|
||||
<CancelActionCell
|
||||
id={String(row.creator === 'sell' ? row.sell_order_id : row.buy_order_id)}
|
||||
onAfter={onAfter}
|
||||
/>
|
||||
<CancelActionCell type="cancel_tx" id={row.id.toString()} onAfter={onAfter} />
|
||||
),
|
||||
},
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { useState } from 'react';
|
||||
import { useAlert } from '@/hook/useAlert';
|
||||
import { cancelOrder } from '@/utils/methods';
|
||||
import { cancelOrder, cancelTransaction } from '@/utils/methods';
|
||||
import ActionBtn from '@/components/UI/ActionBtn';
|
||||
import { CancelActionCellProps } from './types';
|
||||
|
||||
|
|
@ -13,7 +13,7 @@ export default function CancelActionCell({ type = 'cancel', id, onAfter }: Cance
|
|||
|
||||
try {
|
||||
setLoading(true);
|
||||
const result = await cancelOrder(id);
|
||||
const result = type === 'cancel' ? await cancelOrder(id) : await cancelTransaction(id);
|
||||
if (!result.success) {
|
||||
setAlertState('error');
|
||||
setAlertSubtitle('Error while cancelling order');
|
||||
|
|
@ -35,7 +35,7 @@ export default function CancelActionCell({ type = 'cancel', id, onAfter }: Cance
|
|||
disabled={loading}
|
||||
onClick={() => onClick()}
|
||||
>
|
||||
{type === 'cancel' ? 'Cancel' : 'Reject'}
|
||||
{type === 'cancel' || type === 'cancel_tx' ? 'Cancel' : 'Reject'}
|
||||
</ActionBtn>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
export interface CancelActionCellProps {
|
||||
type?: 'cancel' | 'reject';
|
||||
type?: 'cancel' | 'reject' | 'cancel_tx';
|
||||
id: string;
|
||||
onAfter: () => Promise<void>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -165,13 +165,21 @@ function Orders() {
|
|||
setAlertState('loading');
|
||||
setAlertSubtitle('Canceling all orders...');
|
||||
|
||||
const results = await Promise.allSettled(
|
||||
activeOrders.map(async (e) => {
|
||||
await cancelOrder(e.id);
|
||||
}),
|
||||
);
|
||||
// const results = await Promise.allSettled(
|
||||
// activeOrders.map(async (e) => {
|
||||
// await cancelOrder(e.id);
|
||||
// }),
|
||||
// );
|
||||
|
||||
if (results.some((e) => e.status === 'rejected')) {
|
||||
const results = await (async () => {
|
||||
const res = [];
|
||||
for (const order of activeOrders) {
|
||||
res.push(await cancelOrder(order.id).catch(() => null));
|
||||
}
|
||||
return res;
|
||||
})();
|
||||
|
||||
if (results.some((e) => e === null)) {
|
||||
setAlertState('error');
|
||||
setAlertSubtitle('Some of the orders were not canceled');
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -116,7 +116,10 @@ function Trading() {
|
|||
setMyOrdersLoading(true);
|
||||
|
||||
try {
|
||||
await Promise.all(userOrders.map((order) => cancelOrder(order.id)));
|
||||
for (const order of userOrders) {
|
||||
await cancelOrder(order.id);
|
||||
}
|
||||
|
||||
await updateUserOrders();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
|
|
|
|||
|
|
@ -259,6 +259,15 @@ export async function cancelOrder(id: string): Promise<ErrorRes | { success: tru
|
|||
.then((res) => res.data);
|
||||
}
|
||||
|
||||
export async function cancelTransaction(id: string): Promise<ErrorRes | { success: true }> {
|
||||
return axios
|
||||
.post('/api/transactions/cancel', {
|
||||
token: sessionStorage.getItem('token'),
|
||||
transactionId: id,
|
||||
})
|
||||
.then((res) => res.data);
|
||||
}
|
||||
|
||||
export async function getCandles(
|
||||
pairId: string,
|
||||
period: Period,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue