Skip to content

Commit

Permalink
useMaintenanceListener
Browse files Browse the repository at this point in the history
  • Loading branch information
bigboydiamonds committed Jul 5, 2024
1 parent a93298d commit 62589b3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fetchJSONData } from './fetchJsonData'
import { fetchJSONData } from './fetchJSONData'

const mockUrl =
'https://raw.githubusercontent.com/synapsecns/sanguine/test/maintenance/packages/synapse-interface/public/pauses/v1/paused-chains.json'
Expand Down Expand Up @@ -27,7 +27,7 @@ describe('fetchJSONData', () => {
})

test('retries the maximum number of times and fails', async () => {
const maxRetries = 5
const maxRetries = 3
;(fetch as jest.Mock).mockResolvedValue({
ok: false,
status: 500,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const fetchJSONData = async (url: string): Promise<any> => {
// Configurable parameters
const maxRetries = 5 // maximum number of retries
const maxRetries = 3 // maximum number of retries
const initialDelay = 1000 // initial delay in milliseconds

// Helper function to delay for a given amount of time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import { useTransactionListener } from '@/utils/hooks/useTransactionListener'
import { use_TransactionsListener } from '@/utils/hooks/use_TransactionsListener'
import { useFetchPricesOnInterval } from '@/utils/hooks/useFetchPricesOnInterval'
import { useFetchGasDataOnInterval } from '@/utils/hooks/useFetchGasDataOnInterval'
import { useMaintenanceListener } from '@/utils/hooks/useMaintenanceListener'

const BackgroundListenerContext = createContext(null)

export const BackgroundListenerProvider = ({ children }) => {
useMaintenanceListener()
useApplicationListener()
usePortfolioListener()
useTransactionListener()
Expand Down
17 changes: 0 additions & 17 deletions packages/synapse-interface/contexts/MaintenanceProvider.tsx

This file was deleted.

11 changes: 4 additions & 7 deletions packages/synapse-interface/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import setupLogRocketReact from 'logrocket-react'

import { SegmentAnalyticsProvider } from '@/contexts/SegmentAnalyticsProvider'
import { UserProvider } from '@/contexts/UserProvider'
import { MaintenanceProvider } from '@/contexts/MaintenanceProvider'
import { BackgroundListenerProvider } from '@/contexts/BackgroundListenerProvider'
import CustomToaster from '@/components/toast'
import { SynapseProvider } from '@/utils/providers/SynapseProvider'
Expand Down Expand Up @@ -52,12 +51,10 @@ function App({ Component, pageProps }: AppProps) {
<PersistGate loading={null} persistor={persistor}>
<SegmentAnalyticsProvider>
<UserProvider>
<MaintenanceProvider>
<BackgroundListenerProvider>
<Component {...pageProps} />
</BackgroundListenerProvider>
<CustomToaster />
</MaintenanceProvider>
<BackgroundListenerProvider>
<Component {...pageProps} />
</BackgroundListenerProvider>
<CustomToaster />
</UserProvider>
</SegmentAnalyticsProvider>
</PersistGate>
Expand Down
15 changes: 15 additions & 0 deletions packages/synapse-interface/utils/hooks/useMaintenanceListener.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useEffect } from 'react'

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

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

useEffect(() => {
fetchMaintenanceData()
}, [interval])

return null
}

0 comments on commit 62589b3

Please sign in to comment.