refactor: 💨
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { checkIfAlgoRelay } from '@renderer/lib/relay'
|
import { checkAlgoRelay } from '@renderer/lib/relay'
|
||||||
import client from '@renderer/services/client.service'
|
import client from '@renderer/services/client.service'
|
||||||
import { TRelayInfo } from '@renderer/types'
|
import { TRelayInfo } from '@renderer/types'
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
@@ -17,7 +17,7 @@ export function useFetchRelayInfos(urls: string[]) {
|
|||||||
try {
|
try {
|
||||||
const relayInfos = await client.fetchRelayInfos(urls)
|
const relayInfos = await client.fetchRelayInfos(urls)
|
||||||
setRelayInfos(relayInfos)
|
setRelayInfos(relayInfos)
|
||||||
setAreAlgoRelays(relayInfos.every((relayInfo) => checkIfAlgoRelay(relayInfo)))
|
setAreAlgoRelays(relayInfos.every((relayInfo) => checkAlgoRelay(relayInfo)))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import { TRelayInfo } from '@renderer/types'
|
import { TRelayInfo } from '@renderer/types'
|
||||||
|
|
||||||
export function checkIfAlgoRelay(relayInfo: TRelayInfo | undefined) {
|
export function checkAlgoRelay(relayInfo: TRelayInfo | undefined) {
|
||||||
return relayInfo?.software === 'https://github.com/bitvora/algo-relay' // hardcode for now
|
return relayInfo?.software === 'https://github.com/bitvora/algo-relay' // hardcode for now
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function checkSearchRelay(relayInfo: TRelayInfo | undefined) {
|
||||||
|
return relayInfo?.supported_nips?.includes(50)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { TRelayGroup } from '@common/types'
|
import { TRelayGroup } from '@common/types'
|
||||||
import { checkIfAlgoRelay } from '@renderer/lib/relay'
|
import { checkAlgoRelay, checkSearchRelay } from '@renderer/lib/relay'
|
||||||
import { isWebsocketUrl, normalizeUrl } from '@renderer/lib/url'
|
import { isWebsocketUrl, normalizeUrl } from '@renderer/lib/url'
|
||||||
import client from '@renderer/services/client.service'
|
import client from '@renderer/services/client.service'
|
||||||
import storage from '@renderer/services/storage.service'
|
import storage from '@renderer/services/storage.service'
|
||||||
@@ -59,20 +59,18 @@ export function RelaySettingsProvider({ children }: { children: React.ReactNode
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handler = async () => {
|
const handler = async () => {
|
||||||
const relayUrls = temporaryRelayUrls.length
|
const newRelayUrls = temporaryRelayUrls.length
|
||||||
? temporaryRelayUrls
|
? temporaryRelayUrls
|
||||||
: (relayGroups.find((group) => group.isActive)?.relayUrls ?? [])
|
: (relayGroups.find((group) => group.isActive)?.relayUrls ?? [])
|
||||||
|
|
||||||
setSearchableRelayUrls([])
|
const relayInfos = await client.fetchRelayInfos(newRelayUrls)
|
||||||
setRelayUrls([])
|
setSearchableRelayUrls(newRelayUrls.filter((_, index) => checkSearchRelay(relayInfos[index])))
|
||||||
const relayInfos = await client.fetchRelayInfos(relayUrls)
|
const nonAlgoRelayUrls = newRelayUrls.filter((_, index) => !checkAlgoRelay(relayInfos[index]))
|
||||||
setSearchableRelayUrls(
|
setAreAlgoRelays(newRelayUrls.length > 0 && nonAlgoRelayUrls.length === 0)
|
||||||
relayUrls.filter((_, index) => relayInfos[index]?.supported_nips?.includes(50))
|
|
||||||
)
|
|
||||||
const nonAlgoRelayUrls = relayUrls.filter((_, index) => !checkIfAlgoRelay(relayInfos[index]))
|
|
||||||
setAreAlgoRelays(relayUrls.length > 0 && nonAlgoRelayUrls.length === 0)
|
|
||||||
setRelayUrls(relayUrls)
|
|
||||||
client.setCurrentRelayUrls(nonAlgoRelayUrls)
|
client.setCurrentRelayUrls(nonAlgoRelayUrls)
|
||||||
|
if (JSON.stringify(relayUrls) !== JSON.stringify(newRelayUrls)) {
|
||||||
|
setRelayUrls(newRelayUrls)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
handler()
|
handler()
|
||||||
}, [relayGroups, temporaryRelayUrls])
|
}, [relayGroups, temporaryRelayUrls])
|
||||||
|
|||||||
Reference in New Issue
Block a user