Skip to content

Commit

Permalink
fix: cancel request
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhoaidanh committed Sep 12, 2023
1 parent beaa912 commit 5cda4c5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/components/swapv2/LimitOrder/Modals/CancelOrderModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Trans, t } from '@lingui/macro'
import { useEffect, useMemo, useState } from 'react'
import { useEffect, useMemo, useRef, useState } from 'react'
import { Text } from 'rebass'

import Logo from 'components/Logo'
Expand Down Expand Up @@ -53,15 +53,19 @@ function ContentCancel({
takerAssetDecimals,
} = order ?? ({} as LimitOrder)

const controller = useRef(new AbortController())

const [expiredTime, setExpiredTime] = useState(0)
const [cancelStatus, setCancelStatus] = useState<CancelStatus>(CancelStatus.WAITING)
const { orders = [], ordersSoftCancel = [], supportCancelGasless } = useFetchActiveAllOrders(false && !isCancelAll)
const requestCancel = async (type: CancelOrderType) => {
const gasLessCancel = type === CancelOrderType.GAS_LESS_CANCEL
const signal = controller.current.signal
const data: CancelOrderResponse = await onSubmit(
isCancelAll ? (gasLessCancel ? ordersSoftCancel : orders) : order ? [order] : [],
type,
)
if (signal.aborted) return
setCancelStatus(gasLessCancel ? CancelStatus.COUNTDOWN : CancelStatus.WAITING)
const expired = data?.orders?.[0]?.operatorSignatureExpiredAt
expired && setExpiredTime(expired)
Expand All @@ -73,8 +77,10 @@ function ContentCancel({
useEffect(() => {
if (!isOpen || flowState.errorMessage) {
setCancelStatus(CancelStatus.WAITING)
controller.current = new AbortController()
}
}, [isOpen, flowState.errorMessage])
return () => controller?.current?.abort()
}, [isOpen, flowState.errorMessage, isCancelAll])

const isCountDown = cancelStatus === CancelStatus.COUNTDOWN
const isCancelDone = cancelStatus === CancelStatus.CANCEL_DONE
Expand Down

0 comments on commit 5cda4c5

Please sign in to comment.