Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: poll messages based on messagesTag #2907

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading