feat: allow changing default relays
This commit is contained in:
parent
36959a1052
commit
53a67d8233
44 changed files with 356 additions and 92 deletions
|
|
@ -1,10 +1,11 @@
|
|||
import { BIG_RELAY_URLS, MAX_PINNED_NOTES, POLL_TYPE } from '@/constants'
|
||||
import { MAX_PINNED_NOTES, POLL_TYPE } from '@/constants'
|
||||
import { TEmoji, TPollType, TRelayList, TRelaySet } from '@/types'
|
||||
import { Event, kinds } from 'nostr-tools'
|
||||
import { buildATag } from './draft-event'
|
||||
import { getReplaceableEventIdentifier } from './event'
|
||||
import { getAmountFromInvoice, getLightningAddressFromProfile } from './lightning'
|
||||
import { formatPubkey, isValidPubkey, pubkeyToNpub } from './pubkey'
|
||||
import { getDefaultRelayUrls } from './relay'
|
||||
import { generateBech32IdFromETag, getEmojiInfosFromEmojiTags, tagNameEquals } from './tag'
|
||||
import { isOnionUrl, isWebsocketUrl, normalizeHttpUrl, normalizeUrl } from './url'
|
||||
|
||||
|
|
@ -12,8 +13,10 @@ export function getRelayListFromEvent(
|
|||
event?: Event | null,
|
||||
filterOutOnionRelays: boolean = true
|
||||
): TRelayList {
|
||||
const defaultRelays = getDefaultRelayUrls()
|
||||
|
||||
if (!event) {
|
||||
return { write: BIG_RELAY_URLS, read: BIG_RELAY_URLS, originalRelays: [] }
|
||||
return { write: defaultRelays, read: defaultRelays, originalRelays: [] }
|
||||
}
|
||||
|
||||
const relayList = { write: [], read: [], originalRelays: [] } as TRelayList
|
||||
|
|
@ -38,11 +41,11 @@ export function getRelayListFromEvent(
|
|||
}
|
||||
})
|
||||
|
||||
// If there are too many relays, use the default BIG_RELAY_URLS
|
||||
// If there are too many relays, use the default relays
|
||||
// Because they don't know anything about relays, their settings cannot be trusted
|
||||
return {
|
||||
write: relayList.write.length && relayList.write.length <= 8 ? relayList.write : BIG_RELAY_URLS,
|
||||
read: relayList.read.length && relayList.write.length <= 8 ? relayList.read : BIG_RELAY_URLS,
|
||||
write: relayList.write.length && relayList.write.length <= 8 ? relayList.write : defaultRelays,
|
||||
read: relayList.read.length && relayList.write.length <= 8 ? relayList.read : defaultRelays,
|
||||
originalRelays: relayList.originalRelays
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
import { BIG_RELAY_URLS } from '@/constants'
|
||||
import storage from '@/services/local-storage.service'
|
||||
import { TRelayInfo } from '@/types'
|
||||
|
||||
export function getDefaultRelayUrls() {
|
||||
return storage.getDefaultRelayUrls()
|
||||
}
|
||||
|
||||
export function checkAlgoRelay(relayInfo: TRelayInfo | undefined) {
|
||||
return relayInfo?.software === 'https://github.com/bitvora/algo-relay' // hardcode for now
|
||||
}
|
||||
|
|
@ -14,7 +18,8 @@ export function checkNip43Support(relayInfo: TRelayInfo | undefined) {
|
|||
}
|
||||
|
||||
export function filterOutBigRelays(relayUrls: string[]) {
|
||||
return relayUrls.filter((url) => !BIG_RELAY_URLS.includes(url))
|
||||
const defaultRelays = getDefaultRelayUrls()
|
||||
return relayUrls.filter((url) => !defaultRelays.includes(url))
|
||||
}
|
||||
|
||||
export function recommendRelaysByLanguage(i18nLanguage: string) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue