Fix lnurls, and collection load args
This commit is contained in:
@@ -3,7 +3,7 @@ import {indexBy, type Maybe, now} from '@welshman/lib'
|
||||
import {withGetter} from '@welshman/store'
|
||||
import {getFreshness, setFreshness} from './freshness'
|
||||
|
||||
export const collection = <T>({
|
||||
export const collection = <T, LoadArgs extends any[]>({
|
||||
name,
|
||||
store,
|
||||
getKey,
|
||||
@@ -12,13 +12,13 @@ export const collection = <T>({
|
||||
name: string
|
||||
store: Readable<T[]>
|
||||
getKey: (item: T) => string
|
||||
load: (key: string, ...args: any) => Promise<any>
|
||||
load: (key: string, ...args: LoadArgs) => Promise<any>
|
||||
}) => {
|
||||
const indexStore = withGetter(derived(store, $items => indexBy(getKey, $items)))
|
||||
const getItem = (key: string) => indexStore.get().get(key)
|
||||
const pending = new Map<string, Promise<Maybe<T>>>()
|
||||
|
||||
const loadItem = async (key: string, ...args: any[]) => {
|
||||
const loadItem = async (key: string, ...args: LoadArgs) => {
|
||||
if (getFreshness(name, key) > now() - 3600) {
|
||||
return indexStore.get().get(key)
|
||||
}
|
||||
@@ -40,7 +40,7 @@ export const collection = <T>({
|
||||
return indexStore.get().get(key)
|
||||
}
|
||||
|
||||
const deriveItem = (key: Maybe<string>, ...args: any[]) => {
|
||||
const deriveItem = (key: Maybe<string>, ...args: LoadArgs) => {
|
||||
if (!key) {
|
||||
return readable(undefined)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import {createEventStore} from "@welshman/store"
|
||||
|
||||
export const env: {
|
||||
DUFFLEPUD_URL?: string
|
||||
[key: string]: any
|
||||
} = {
|
||||
DUFFLEPUD_URL: undefined,
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ export const {
|
||||
store: profiles,
|
||||
getKey: profile => profile.event.pubkey,
|
||||
load: async (pubkey: string, hints = [], request: Partial<SubscribeRequest> = {}) => {
|
||||
const relays = getWriteRelayUrls(await loadRelaySelections(pubkey))
|
||||
const relays = getWriteRelayUrls(await loadRelaySelections(pubkey, hints))
|
||||
|
||||
return load({
|
||||
...request,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {writable, derived} from 'svelte/store'
|
||||
import {withGetter} from '@welshman/store'
|
||||
import type {Zapper} from '@welshman/util'
|
||||
import {uniq, bech32ToHex, indexBy, tryCatch, uniqBy, batcher, postJson} from '@welshman/lib'
|
||||
import {uniq, identity, bech32ToHex, indexBy, tryCatch, uniqBy, batcher, postJson} from '@welshman/lib'
|
||||
import {env} from './core'
|
||||
import {collection} from './collection'
|
||||
import {profilesByPubkey} from './profiles'
|
||||
@@ -22,8 +22,10 @@ export const fetchZappers = (lnurls: string[]) => {
|
||||
throw new Error("DUFFLEPUD_URL is required to fetch zapper info")
|
||||
}
|
||||
|
||||
const res: any = postJson(`${base}/zapper/info`, {lnurls: lnurls.map(bech32ToHex)})
|
||||
const zappersByLnurl = new Map<string, Zapper>()
|
||||
const res: any = postJson(`${base}/zapper/info`, {
|
||||
lnurls: lnurls.map(lnurl => tryCatch(() => bech32ToHex(lnurl))).filter(identity),
|
||||
})
|
||||
|
||||
for (const {lnurl, info} of res?.data || []) {
|
||||
tryCatch(() => zappersByLnurl.set(bech32ToHex(lnurl), info))
|
||||
|
||||
Reference in New Issue
Block a user