Skip to content

Commit

Permalink
useSynapsePauseData hook (#2921)
Browse files Browse the repository at this point in the history
  • Loading branch information
bigboydiamonds authored Jul 25, 2024
1 parent 4a0dc8d commit b48c8fc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fetchJsonData } from './fetchJsonData'

const mockUrl =
'https://raw.githubusercontent.com/synapsecns/sanguine/test/maintenance/packages/synapse-interface/public/pauses/v1/paused-chains.json'
'https://synapsecns.github.io/sanguine/packages/synapse-interface/public/pauses/v1/paused-chains.json'

// Mock the global fetch function
global.fetch = jest.fn()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { useState, useCallback } from 'react'

import { useAppDispatch } from '@/store/hooks'
import {
setPausedChainsData,
setPausedModulesData,
} from '@/slices/maintenance/reducer'
import { fetchJsonData } from './fetchJsonData'
import { fetchJsonData } from '../functions/fetchJsonData'
import pausedChains from '@/public/pauses/v1/paused-chains.json'
import pausedBridgeModules from '@/public/pauses/v1/paused-bridge-modules.json'

Expand All @@ -12,16 +14,15 @@ const PAUSED_CHAINS_URL =
const PAUSED_MODULES_URL =
'https://synapsecns.github.io/sanguine/packages/synapse-interface/public/pauses/v1/paused-bridge-modules.json'

let isFetching = false

export const getSynapsePauseData = () => {
export const useSynapsePauseData = () => {
const dispatch = useAppDispatch()
const [isFetching, setIsFetching] = useState(false)

const fetchAndStoreData = async () => {
const fetchAndStoreData = useCallback(async () => {
if (isFetching) return
try {
isFetching = true
setIsFetching(true)

try {
const pausedChainsData = await fetchJsonData(PAUSED_CHAINS_URL)
const pausedModulesData = await fetchJsonData(PAUSED_MODULES_URL)

Expand All @@ -38,10 +39,10 @@ export const getSynapsePauseData = () => {
dispatch(setPausedModulesData(pausedBridgeModules))
} finally {
setTimeout(() => {
isFetching = false
setIsFetching(false)
}, 1000)
}
}
}, [dispatch, isFetching])

return fetchAndStoreData
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useEffect } from 'react'

import { useIntervalTimer } from './useIntervalTimer'
import { getSynapsePauseData } from '@/components/Maintenance/functions/getSynapsePauseData'
import { useSynapsePauseData } from '@/components/Maintenance/hooks/useSynapsePauseData'

export const useMaintenanceListener = () => {
const interval = useIntervalTimer(60000)
const fetchMaintenanceData = getSynapsePauseData()
const fetchMaintenanceData = useSynapsePauseData()

useEffect(() => {
fetchMaintenanceData()
Expand Down

0 comments on commit b48c8fc

Please sign in to comment.