Skip to content

Commit

Permalink
Improve useListBeforeDate comments
Browse files Browse the repository at this point in the history
  • Loading branch information
buberdds committed Oct 7, 2024
1 parent d974550 commit 48de54b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/app/hooks/useListBeforeDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Layer, useGetRuntimeStatus, useGetStatus } from '../../oasis-nexus/api'
import { AppError, AppErrors } from 'types/errors'
import { SearchScope } from 'types/searchScope'

// Workaround around "before" filter exclusive maximum transaction time.
function addOneSecond(timestamp: string | undefined) {
if (!timestamp) {
return undefined
Expand All @@ -20,14 +21,16 @@ const useListBeforeDate = (
const [beforeDate, setBeforeDate] = useState<string | undefined>(undefined)
const setBeforeDateFromCollection = (newDate: string | undefined) => {
const adjustedDate = addOneSecond(newDate)
// workaround around "before" filter exclusive maximum transaction time.
// Prevents React re-renders infinite loop
if (offset === 0 && beforeDate !== adjustedDate) {
setBeforeDate(adjustedDate)
}
}

useEffect(() => {
if (!beforeDate) {
// when view is init on page other than 1, we don't know the first tx timestamp
// we rely on status endpoint "latest_block_time" prop
setBeforeDate(addOneSecond(latestBlockTime))
setOffsetAssociatedWithDate(offset)
}
Expand Down

0 comments on commit 48de54b

Please sign in to comment.