Skip to content

Commit

Permalink
Increase before param to avoid exclusive filtering in Nexus
Browse files Browse the repository at this point in the history
  • Loading branch information
buberdds committed Oct 3, 2024
1 parent 17b03ca commit 913116f
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/app/hooks/useListBeforeDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,32 @@ import { Layer, useGetRuntimeStatus, useGetStatus } from '../../oasis-nexus/api'
import { AppError, AppErrors } from 'types/errors'
import { SearchScope } from 'types/searchScope'

function addOneSecond(timestamp: string | undefined) {
if (!timestamp) {
return undefined
}
const date = new Date(timestamp)
date.setSeconds(date.getSeconds() + 1)
return date.toISOString()
}

const useListBeforeDate = (
latestBlockTime: string | undefined,
offset: number,
setOffsetAssociatedWithDate: (offset: number) => void,
) => {
const [beforeDate, setBeforeDate] = useState<string | undefined>(undefined)
const setBeforeDateFromCollection = (newDate: string | undefined) => {
if (offset === 0 && beforeDate !== newDate) {
setBeforeDate(newDate)
const adjustedDate = addOneSecond(newDate)
// workaround around "before" filter exclusive maximum transaction time.
if (offset === 0 && beforeDate !== adjustedDate) {
setBeforeDate(adjustedDate)
}
}

useEffect(() => {
if (!beforeDate) {
setBeforeDate(latestBlockTime)
setBeforeDate(addOneSecond(latestBlockTime))
setOffsetAssociatedWithDate(offset)
}
}, [latestBlockTime, beforeDate, offset, setOffsetAssociatedWithDate])
Expand Down

0 comments on commit 913116f

Please sign in to comment.