Skip to content

Commit

Permalink
fix negative countdown
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhoaidanh committed Sep 12, 2023
1 parent ea202aa commit beaa912
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/components/swapv2/LimitOrder/ListOrder/ActionButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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

Expand Down

0 comments on commit beaa912

Please sign in to comment.