Skip to content

Commit

Permalink
Updated FE transaction time estimation logic and interval check frequ…
Browse files Browse the repository at this point in the history
…ency

* Revised the logic for estimating transaction completion time in _Transaction.tsx. Now, the system starts checking for transaction completion a few minutes before the estimated completion time.
* Reduced the interval for checking the current time in _Transactions.tsx from 30 seconds to 5 seconds.
  • Loading branch information
aureliusbtc committed Jan 7, 2024
1 parent dffb9f7 commit d9ae90e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,18 @@ export const _Transaction = ({
const remainingTimeInMinutes: number = Math.ceil(remainingTime / 60) // add additional min for buffer

const isEstimatedTimeReached: boolean = useMemo(() => {
if (!currentTime || !estimatedTime || !timestamp) return false
return currentTime - timestamp > estimatedTime
// Define the interval in minutes before the estimated completion when we should start checking
const intervalBeforeCompletion = 1 // X minutes before completion
// Calculate the time in seconds when we should start checking
const startCheckingTime =
currentTime + estimatedTime - intervalBeforeCompletion * 60

// if current time is above startCheckingTime, return true to begin calling the SDK
return currentTime >= startCheckingTime

// TODO: OLD CODE BELOW:
// if (!currentTime || !estimatedTime || !timestamp) return false
// return currentTime - timestamp > estimatedTime
}, [estimatedTime, currentTime, timestamp])

const [isTxComplete, _kappa] = useBridgeTxStatus({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ export const _Transactions = ({
/** Update time to trigger transactions to recheck tx status */
useEffect(() => {
const interval = setInterval(() => {
setCurrentTime(getTimeMinutesFromNow(0))
}, 30000) // 30000 milliseconds = 30 seconds
let newCurrentTime = getTimeMinutesFromNow(0)
setCurrentTime(newCurrentTime)
}, 5000) // 5000 milliseconds = 5 seconds

return () => {
clearInterval(interval) // Clear the interval when the component unmounts
Expand Down

0 comments on commit d9ae90e

Please sign in to comment.