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