You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

32 lines
920 B

import relayInfoService from '@/services/relay-info.service'
import { TRelayInfo } from '@/types'
import { useEffect, useState } from 'react'
import logger from '@/lib/logger'
export function useFetchRelayInfo(url?: string) {
const [isFetching, setIsFetching] = useState(true)
const [relayInfo, setRelayInfo] = useState<TRelayInfo | undefined>(undefined)
useEffect(() => {
if (!url) return
const fetchRelayInfos = async () => {
setIsFetching(true)
const timer = setTimeout(() => {
setIsFetching(false)
}, 5000)
try {
const relayInfo = await relayInfoService.getRelayInfo(url)
setRelayInfo(relayInfo)
} catch (err) {
logger.error('Failed to fetch relay info', { error: err, url })
} finally {
clearTimeout(timer)
setIsFetching(false)
}
}
fetchRelayInfos()
}, [url])
return { relayInfo, isFetching }
}