Skip to content

Commit

Permalink
Fetch gas when fromChainId on bridge card changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bigboydiamonds committed Apr 3, 2024
1 parent 9758112 commit 1496842
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { useEffect } from 'react'
import { useNetwork } from 'wagmi'

import { useAppDispatch } from '@/store/hooks'
import { fetchGasData } from '@/slices/gasDataSlice'
import { useBridgeState } from '@/slices/bridge/hooks'

export const useFetchGasDataOnInterval = () => {
const dispatch = useAppDispatch()
const { chain } = useNetwork()
const { fromChainId } = useBridgeState()

const fetchData = (chainId: number) => {
dispatch(fetchGasData(chainId))
}

useEffect(() => {
// Fetch when chainId available
if (chain?.id) {
fetchData(chain?.id)
if (fromChainId) {
fetchData(fromChainId)
}

// Fetch every 60 seconds
const interval = setInterval(fetchGasData, 60000)

return () => clearInterval(interval)
}, [dispatch, chain?.id])
}, [dispatch, fromChainId])
}

0 comments on commit 1496842

Please sign in to comment.