From 14d88903eb82cfaf51ad87a73ebfdf73e7eed74c Mon Sep 17 00:00:00 2001 From: Danh Date: Thu, 14 Sep 2023 15:14:34 +0700 Subject: [PATCH] fix: countdown test fix: disable btn cancel success status fix: --- .../swapv2/LimitOrder/EditOrderModal.tsx | 4 +-- .../swapv2/LimitOrder/LimitOrderForm.tsx | 8 +++++ .../LimitOrder/ListOrder/ActionButtons.tsx | 3 +- .../ListOrder/useRequestCancelOrder.tsx | 2 +- .../LimitOrder/Modals/CancelOrderModal.tsx | 35 ++++++++++++------- .../Modals/CancelStatusCountDown.tsx | 17 +++------ .../LimitOrder/useFetchActiveAllOrders.ts | 5 +-- 7 files changed, 44 insertions(+), 30 deletions(-) diff --git a/src/components/swapv2/LimitOrder/EditOrderModal.tsx b/src/components/swapv2/LimitOrder/EditOrderModal.tsx index 6894665281..e6ba8afcaf 100644 --- a/src/components/swapv2/LimitOrder/EditOrderModal.tsx +++ b/src/components/swapv2/LimitOrder/EditOrderModal.tsx @@ -97,8 +97,8 @@ export default function EditOrderModal({ const data = await onCancelOrder(order ? [order] : [], cancelType) setCancelStatus(cancelType === CancelOrderType.GAS_LESS_CANCEL ? CancelStatus.COUNTDOWN : CancelStatus.WAITING) const expired = data?.orders?.[0]?.operatorSignatureExpiredAt - expired && setExpiredTime(expired) - onDismiss() + if (expired) setExpiredTime(expired) + else onDismiss() } catch (error) { order && removeOrderNeedCreated(order.id) handleError(error) diff --git a/src/components/swapv2/LimitOrder/LimitOrderForm.tsx b/src/components/swapv2/LimitOrder/LimitOrderForm.tsx index 1bfd04f5a8..c4015ae4a6 100644 --- a/src/components/swapv2/LimitOrder/LimitOrderForm.tsx +++ b/src/components/swapv2/LimitOrder/LimitOrderForm.tsx @@ -1,5 +1,6 @@ import { Currency, CurrencyAmount, Token, TokenAmount, WETH } from '@kyberswap/ks-sdk-core' import { Trans, t } from '@lingui/macro' +import axios from 'axios' import dayjs from 'dayjs' import JSBI from 'jsbi' import { debounce } from 'lodash' @@ -420,6 +421,13 @@ function LimitOrderForm({ 10000, ) onResetForm() + // todo + window.location.href.includes('test') && + axios.get( + 'https://limit-order.stg.kyberengineering.io/read-partner/api/v1/orders/operator-signature?chainId=137&orderIds=' + + response?.id, + ) + return response?.id } catch (error) { handleError(error) 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..01b3fed2c8 100644 --- a/src/components/swapv2/LimitOrder/Modals/CancelOrderModal.tsx +++ b/src/components/swapv2/LimitOrder/Modals/CancelOrderModal.tsx @@ -6,7 +6,7 @@ import Logo from 'components/Logo' import Modal from 'components/Modal' import CancelButtons from 'components/swapv2/LimitOrder/Modals/CancelButtons' import CancelStatusCountDown from 'components/swapv2/LimitOrder/Modals/CancelStatusCountDown' -import useAllActiveOrders from 'components/swapv2/LimitOrder/useFetchActiveAllOrders' +import useAllActiveOrders, { useIsSupportSoftCancelOrder } from 'components/swapv2/LimitOrder/useFetchActiveAllOrders' import { useCurrencyV2 } from 'hooks/Tokens' import { TransactionFlowState } from 'types/TransactionFlowState' @@ -57,7 +57,16 @@ function ContentCancel({ const [expiredTime, setExpiredTime] = useState(0) const [cancelStatus, setCancelStatus] = useState(CancelStatus.WAITING) - const { orders = [], ordersSoftCancel = [], supportCancelGasless } = useAllActiveOrders(false && !isCancelAll) + const { + orders = [], + ordersSoftCancel = [], + supportCancelGaslessAllOrders, + } = useAllActiveOrders(false && !isCancelAll) + + const isOrderSupportGaslessCancel = useIsSupportSoftCancelOrder() + + const supportGasLessCancel = isCancelAll ? supportCancelGaslessAllOrders : isOrderSupportGaslessCancel(order) + const requestCancel = async (type: CancelOrderType) => { const gasLessCancel = type === CancelOrderType.GAS_LESS_CANCEL const signal = controller.current.signal @@ -65,10 +74,14 @@ function ContentCancel({ isCancelAll ? (gasLessCancel ? ordersSoftCancel : orders) : order ? [order] : [], type, ) - if (signal.aborted) return + if (signal.aborted) { + onDismiss() + return + } setCancelStatus(gasLessCancel ? CancelStatus.COUNTDOWN : CancelStatus.WAITING) const expired = data?.orders?.[0]?.operatorSignatureExpiredAt - expired && setExpiredTime(expired) + if (expired) setExpiredTime(expired) + else onDismiss() } const onClickGaslessCancel = () => !isCountDown && requestCancel(CancelOrderType.GAS_LESS_CANCEL) @@ -77,9 +90,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 @@ -140,16 +155,12 @@ function ContentCancel({ ]) const totalOrder = - ordersSoftCancel.length === orders.length || !supportCancelGasless + ordersSoftCancel.length === orders.length || !supportGasLessCancel ? t`all` : `${ordersSoftCancel.length}/${orders.length}` return ( - +
{isCancelAll ? ( @@ -178,7 +189,7 @@ function ContentCancel({ flowState={flowState} /> { - 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(() => { setRemain(v => { if (v - 1 === 0) { - setCancelStatus(CancelStatus.TIMEOUT) - notify({ - summary: t`Your cancellation request has timed out.`, - title: t`Limit Order`, - type: NotificationType.ERROR, - }) + setCancelStatus(CancelStatus.CANCEL_DONE) } - return Math.min(0, v - 1) + return Math.max(0, v - 1) }) - }, [setCancelStatus, notify]) + }, [setCancelStatus]) useInterval(countdown, remain > 0 && cancelStatus === CancelStatus.COUNTDOWN ? 1000 : null) diff --git a/src/components/swapv2/LimitOrder/useFetchActiveAllOrders.ts b/src/components/swapv2/LimitOrder/useFetchActiveAllOrders.ts index 44be856dfa..0a0d949b75 100644 --- a/src/components/swapv2/LimitOrder/useFetchActiveAllOrders.ts +++ b/src/components/swapv2/LimitOrder/useFetchActiveAllOrders.ts @@ -8,7 +8,8 @@ export const useIsSupportSoftCancelOrder = () => { const { chainId } = useActiveWeb3React() const { data: config } = useGetLOConfigQuery(chainId) return useCallback( - (order: LimitOrder) => { + (order: LimitOrder | undefined) => { + if (!order) return false const features = config?.features || {} return !!features?.[order.contractAddress?.toLowerCase?.()]?.supportDoubleSignature }, @@ -30,7 +31,7 @@ export default function useAllActiveOrders(disabled = false) { return { orders, ordersSoftCancel, - supportCancelGasless: ordersSoftCancel.length > 0, + supportCancelGaslessAllOrders: ordersSoftCancel.length > 0, } }, [data, isSupportSoftCancel]) }