Add a few utils, fix relay fetching
This commit is contained in:
@@ -31,7 +31,7 @@ export const onRelay = (sub: (relay: RelayProfile) => void) => {
|
|||||||
|
|
||||||
export const fetchRelayDirectly = async (url: string): Promise<Maybe<RelayProfile>> => {
|
export const fetchRelayDirectly = async (url: string): Promise<Maybe<RelayProfile>> => {
|
||||||
try {
|
try {
|
||||||
const json = fetchJson(url.replace(/^ws/, "http"), {
|
const json = await fetchJson(url.replace(/^ws/, "http"), {
|
||||||
headers: {
|
headers: {
|
||||||
Accept: "application/nostr+json",
|
Accept: "application/nostr+json",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ export type Maybe<T> = T | undefined
|
|||||||
|
|
||||||
export type MaybeAsync<T> = T | Promise<T>
|
export type MaybeAsync<T> = T | Promise<T>
|
||||||
|
|
||||||
|
export const maybe = <T>(x?: T) => x
|
||||||
|
|
||||||
export const isDefined = <T>(x: T, ...args: unknown[]) => x !== undefined
|
export const isDefined = <T>(x: T, ...args: unknown[]) => x !== undefined
|
||||||
|
|
||||||
export const isUndefined = <T>(x: T, ...args: unknown[]) => x === undefined
|
export const isUndefined = <T>(x: T, ...args: unknown[]) => x === undefined
|
||||||
@@ -1034,9 +1036,11 @@ export const tryCatch = <T>(f: () => T, onError?: (e: Error) => void): T | undef
|
|||||||
/**
|
/**
|
||||||
* Throws an error with the given message
|
* Throws an error with the given message
|
||||||
*/
|
*/
|
||||||
export const thrower = (message: string) => () => {
|
export const thrower =
|
||||||
throw new Error(message)
|
(message: string) =>
|
||||||
}
|
(...args: unknown[]) => {
|
||||||
|
throw new Error(message)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates function that only executes once
|
* Creates function that only executes once
|
||||||
|
|||||||
@@ -138,8 +138,10 @@ export const EMOJIS = 10030
|
|||||||
export const MESSAGING_RELAYS = 10050
|
export const MESSAGING_RELAYS = 10050
|
||||||
export const BLOSSOM_SERVERS = 10063
|
export const BLOSSOM_SERVERS = 10063
|
||||||
export const FILE_SERVERS = 10096
|
export const FILE_SERVERS = 10096
|
||||||
|
export const WALLET_INFO = 13194
|
||||||
export const RELAY_MEMBERS = 13534
|
export const RELAY_MEMBERS = 13534
|
||||||
export const PROMENADE_REGISTER_ACCOUNT = 16430
|
export const PROMENADE_REGISTER_ACCOUNT = 16430
|
||||||
|
export const ROOM_CREATE_PERMISSION = 19004
|
||||||
export const LIGHTNING_PUB_RPC = 21000
|
export const LIGHTNING_PUB_RPC = 21000
|
||||||
export const CLIENT_AUTH = 22242
|
export const CLIENT_AUTH = 22242
|
||||||
export const BLOSSOM_AUTH = 24242
|
export const BLOSSOM_AUTH = 24242
|
||||||
@@ -152,7 +154,6 @@ export const PROMENADE_RESULT = 26433
|
|||||||
export const RELAY_JOIN = 28934
|
export const RELAY_JOIN = 28934
|
||||||
export const RELAY_INVITE = 28935
|
export const RELAY_INVITE = 28935
|
||||||
export const RELAY_LEAVE = 28936
|
export const RELAY_LEAVE = 28936
|
||||||
export const WALLET_INFO = 13194
|
|
||||||
export const WALLET_REQUEST = 23194
|
export const WALLET_REQUEST = 23194
|
||||||
export const WALLET_RESPONSE = 23195
|
export const WALLET_RESPONSE = 23195
|
||||||
export const NOSTR_CONNECT = 24133
|
export const NOSTR_CONNECT = 24133
|
||||||
@@ -199,7 +200,6 @@ export const ROOM = 35834
|
|||||||
export const ROOM_META = 39000
|
export const ROOM_META = 39000
|
||||||
export const ROOM_ADMINS = 39001
|
export const ROOM_ADMINS = 39001
|
||||||
export const ROOM_MEMBERS = 39002
|
export const ROOM_MEMBERS = 39002
|
||||||
export const ROOM_CREATE_PERMISSION = 39004
|
|
||||||
export const FOLLOW_PACK = 39089
|
export const FOLLOW_PACK = 39089
|
||||||
|
|
||||||
export const DEPRECATED_RELAY_RECOMMENDATION = 2
|
export const DEPRECATED_RELAY_RECOMMENDATION = 2
|
||||||
|
|||||||
Reference in New Issue
Block a user