diff --git a/src/components/swapv2/LimitOrder/ListOrder/ActionButtons.tsx b/src/components/swapv2/LimitOrder/ListOrder/ActionButtons.tsx index dc442c43f7..afd007005e 100644 --- a/src/components/swapv2/LimitOrder/ListOrder/ActionButtons.tsx +++ b/src/components/swapv2/LimitOrder/ListOrder/ActionButtons.tsx @@ -44,17 +44,17 @@ const IconWrap = styled.div<{ color: string; isDisabled?: boolean }>` const CancelStatusButton = ({ expiredAt, style }: { expiredAt: number | undefined; style?: CSSProperties }) => { const theme = useTheme() - const [remain, setRemain] = useState(0) + useEffect(() => { - setRemain(expiredAt ? Math.floor(expiredAt - Date.now() / 1000) : 0) + setRemain(expiredAt && expiredAt - Date.now() > 0 ? Math.floor(expiredAt - Date.now() / 1000) : 0) }, [expiredAt]) const countdown = useCallback(() => { setRemain(v => v - 1) }, []) - useInterval(countdown, remain ? 1000 : null) + useInterval(countdown, remain > 0 ? 1000 : null) if (remain <= 0) return null return ( diff --git a/src/components/swapv2/LimitOrder/Modals/CancelStatusCountDown.tsx b/src/components/swapv2/LimitOrder/Modals/CancelStatusCountDown.tsx index b4a551b777..384c224357 100644 --- a/src/components/swapv2/LimitOrder/Modals/CancelStatusCountDown.tsx +++ b/src/components/swapv2/LimitOrder/Modals/CancelStatusCountDown.tsx @@ -66,8 +66,9 @@ export default function CancelStatusCountDown({ const notify = useNotify() const [remain, setRemain] = useState(0) + useEffect(() => { - setRemain(Math.floor(expiredTime - Date.now() / 1000)) + setRemain(expiredTime - Date.now() > 0 ? Math.floor(expiredTime - Date.now() / 1000) : 0) }, [expiredTime]) const countdown = useCallback(() => { @@ -80,11 +81,11 @@ export default function CancelStatusCountDown({ type: NotificationType.ERROR, }) } - return v - 1 + return Math.min(0, v - 1) }) }, [setCancelStatus, notify]) - useInterval(countdown, remain && cancelStatus === CancelStatus.COUNTDOWN ? 1000 : null) + useInterval(countdown, remain > 0 && cancelStatus === CancelStatus.COUNTDOWN ? 1000 : null) // todo docs link