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.
35 lines
892 B
35 lines
892 B
import client from '@/services/client.service' |
|
import { TRelayList } from '@/types' |
|
import { useEffect, useState } from 'react' |
|
import logger from '@/lib/logger' |
|
|
|
export function useFetchRelayList(pubkey?: string | null) { |
|
const [relayList, setRelayList] = useState<TRelayList>({ |
|
write: [], |
|
read: [], |
|
originalRelays: [] |
|
}) |
|
const [isFetching, setIsFetching] = useState(true) |
|
|
|
useEffect(() => { |
|
const fetchRelayList = async () => { |
|
setIsFetching(true) |
|
if (!pubkey) { |
|
setIsFetching(false) |
|
return |
|
} |
|
try { |
|
const relayList = await client.fetchRelayList(pubkey) |
|
setRelayList(relayList) |
|
} catch (err) { |
|
logger.error('Failed to fetch relay list', { error: err, pubkey }) |
|
} finally { |
|
setIsFetching(false) |
|
} |
|
} |
|
|
|
fetchRelayList() |
|
}, [pubkey]) |
|
|
|
return { relayList, isFetching } |
|
}
|
|
|