Skip to content

Commit

Permalink
Refactor: poll messages based on messagesTag
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Nov 28, 2023
1 parent ffbaa7b commit bc98e11
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions src/hooks/loadables/useLoadSafeMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,11 @@ import type { SafeMessageListPage } from '@safe-global/safe-gateway-typescript-s
import useAsync from '@/hooks/useAsync'
import { logError, Errors } from '@/services/exceptions'
import useSafeInfo from '@/hooks/useSafeInfo'
import { POLLING_INTERVAL } from '@/config/constants'
import useIntervalCounter from '@/hooks/useIntervalCounter'
import type { AsyncResult } from '@/hooks/useAsync'

export const useLoadSafeMessages = (): AsyncResult<SafeMessageListPage> => {
const { safe, safeAddress, safeLoaded } = useSafeInfo()

// TODO: Remove manual polling when messagesTag is no longer cached on the backend
const [pollCount, resetPolling] = useIntervalCounter(POLLING_INTERVAL)

// Reset the counter when safe address/chainId changes
useEffect(() => {
resetPolling()
}, [resetPolling, safeAddress, safe.chainId])

const [data, error, loading] = useAsync<SafeMessageListPage>(
() => {
if (!safeLoaded) {
Expand All @@ -28,13 +18,7 @@ export const useLoadSafeMessages = (): AsyncResult<SafeMessageListPage> => {
return getSafeMessages(safe.chainId, safeAddress)
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[
safeLoaded,
safe.chainId,
safeAddress,
// safe.messagesTag,
pollCount,
],
[safeLoaded, safe.chainId, safeAddress, safe.messagesTag],
false,
)

Expand Down

0 comments on commit bc98e11

Please sign in to comment.