Small fixes, rework zaps
This commit is contained in:
@@ -1,51 +1,11 @@
|
||||
import {tryCatch, fetchJson, batcher, postJson, last} from "@welshman/lib"
|
||||
import type {Maybe} from "@welshman/lib"
|
||||
import {tryCatch, batcher, postJson} from "@welshman/lib"
|
||||
import {queryProfile, displayNip05} from "@welshman/util"
|
||||
import type {Handle} from "@welshman/util"
|
||||
import {deriveDeduplicated} from "@welshman/store"
|
||||
import {LoadableData} from "./clientData.js"
|
||||
import type {IClient} from "./client.js"
|
||||
import {Profiles} from "./profiles.js"
|
||||
|
||||
export type Handle = {
|
||||
nip05: string
|
||||
pubkey?: string
|
||||
nip46?: string[]
|
||||
relays?: string[]
|
||||
}
|
||||
|
||||
export async function queryProfile(nip05: string): Promise<Maybe<Handle>> {
|
||||
const parts = nip05.split("@")
|
||||
const name = parts.length > 1 ? parts[0] : "_"
|
||||
const domain = last(parts)
|
||||
|
||||
try {
|
||||
const {
|
||||
names,
|
||||
relays = {},
|
||||
nip46 = {},
|
||||
} = await fetchJson(`https://${domain}/.well-known/nostr.json?name=${name}`)
|
||||
|
||||
const pubkey = names[name]
|
||||
|
||||
if (!pubkey) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
return {
|
||||
nip05,
|
||||
pubkey,
|
||||
nip46: nip46[pubkey],
|
||||
relays: relays[pubkey],
|
||||
}
|
||||
} catch (_e) {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
export const displayNip05 = (nip05: string) =>
|
||||
nip05?.startsWith("_@") ? last(nip05.split("@")) : nip05
|
||||
|
||||
export const displayHandle = (handle: Handle) => displayNip05(handle.nip05)
|
||||
|
||||
/**
|
||||
* NIP-05 handles, keyed by nip05 identifier. A "local" loadable collection:
|
||||
* items aren't nostr events, they're fetched over HTTP (either directly from
|
||||
|
||||
Reference in New Issue
Block a user