Skip to content

Commit

Permalink
fix: countdown
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhoaidanh committed Sep 14, 2023
1 parent f23c935 commit bf7ee92
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/components/swapv2/LimitOrder/ListOrder/ActionButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 => ({
Expand Down
10 changes: 4 additions & 6 deletions src/components/swapv2/LimitOrder/Modals/CancelOrderModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -145,11 +147,7 @@ function ContentCancel({
: `${ordersSoftCancel.length}/${orders.length}`

return (
<Modal
maxWidth={isCancelAll && !isCancelDone ? 600 : 480}
isOpen={flowState.showConfirm && isOpen}
onDismiss={onDismiss}
>
<Modal maxWidth={isCancelAll && !isCancelDone ? 600 : 480} isOpen={isOpen} onDismiss={onDismiss}>
<Container>
<Header title={isCancelAll ? t`Bulk Cancellation` : t`Cancel an order`} onDismiss={onDismiss} />
{isCancelAll ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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])

Expand Down

0 comments on commit bf7ee92

Please sign in to comment.