diff --git a/src/components/swapv2/LimitOrder/ListOrder/ActionButtons.tsx b/src/components/swapv2/LimitOrder/ListOrder/ActionButtons.tsx index afd007005e..8ce7cc0f9c 100644 --- a/src/components/swapv2/LimitOrder/ListOrder/ActionButtons.tsx +++ b/src/components/swapv2/LimitOrder/ListOrder/ActionButtons.tsx @@ -47,7 +47,8 @@ const CancelStatusButton = ({ expiredAt, style }: { expiredAt: number | undefine const [remain, setRemain] = useState(0) useEffect(() => { - setRemain(expiredAt && expiredAt - Date.now() > 0 ? Math.floor(expiredAt - Date.now() / 1000) : 0) + const delta = Math.floor((expiredAt || 0) - Date.now() / 1000) + setRemain(Math.max(0, delta)) }, [expiredAt]) const countdown = useCallback(() => { diff --git a/src/components/swapv2/LimitOrder/ListOrder/useRequestCancelOrder.tsx b/src/components/swapv2/LimitOrder/ListOrder/useRequestCancelOrder.tsx index fe69ed3ad2..62b3d495a2 100644 --- a/src/components/swapv2/LimitOrder/ListOrder/useRequestCancelOrder.tsx +++ b/src/components/swapv2/LimitOrder/ListOrder/useRequestCancelOrder.tsx @@ -141,7 +141,7 @@ const useRequestCancelOrder = ({ const resp = await (cancelType === CancelOrderType.HARD_CANCEL ? requestHardCancelOrder(orders?.[0]) : requestGasLessCancelOrder(orders)) - setFlowState(state => ({ ...state, showConfirm: false })) + setFlowState(state => ({ ...state, attemptingTxn: false, showConfirm: false })) return resp } catch (error) { setFlowState(state => ({ diff --git a/src/components/swapv2/LimitOrder/Modals/CancelOrderModal.tsx b/src/components/swapv2/LimitOrder/Modals/CancelOrderModal.tsx index cb2d489cf4..00c61ccb9f 100644 --- a/src/components/swapv2/LimitOrder/Modals/CancelOrderModal.tsx +++ b/src/components/swapv2/LimitOrder/Modals/CancelOrderModal.tsx @@ -77,9 +77,11 @@ function ContentCancel({ useEffect(() => { if (!isOpen || flowState.errorMessage) { setCancelStatus(CancelStatus.WAITING) + } + return () => { + controller?.current?.abort() controller.current = new AbortController() } - return () => controller?.current?.abort() }, [isOpen, flowState.errorMessage, isCancelAll]) const isCountDown = cancelStatus === CancelStatus.COUNTDOWN @@ -145,11 +147,7 @@ function ContentCancel({ : `${ordersSoftCancel.length}/${orders.length}` return ( - +
{isCancelAll ? ( diff --git a/src/components/swapv2/LimitOrder/Modals/CancelStatusCountDown.tsx b/src/components/swapv2/LimitOrder/Modals/CancelStatusCountDown.tsx index 384c224357..c1783ed2b5 100644 --- a/src/components/swapv2/LimitOrder/Modals/CancelStatusCountDown.tsx +++ b/src/components/swapv2/LimitOrder/Modals/CancelStatusCountDown.tsx @@ -68,7 +68,8 @@ export default function CancelStatusCountDown({ const [remain, setRemain] = useState(0) useEffect(() => { - setRemain(expiredTime - Date.now() > 0 ? Math.floor(expiredTime - Date.now() / 1000) : 0) + const delta = Math.floor(expiredTime - Date.now() / 1000) + setRemain(Math.max(0, delta)) }, [expiredTime]) const countdown = useCallback(() => { @@ -81,7 +82,7 @@ export default function CancelStatusCountDown({ type: NotificationType.ERROR, }) } - return Math.min(0, v - 1) + return Math.max(0, v - 1) }) }, [setCancelStatus, notify])