46 lines
1002 B
TypeScript
46 lines
1002 B
TypeScript
import { nostrService } from './nostr'
|
|
import { getPrimaryRelaySync } from './config'
|
|
import type { Event } from 'nostr-tools'
|
|
import { createSubscription } from '@/types/nostr-tools-extended'
|
|
|
|
/**
|
|
* Get zap receipt event by ID
|
|
*/
|
|
export async function getZapReceiptById(zapReceiptId: string): Promise<Event | null> {
|
|
const pool = nostrService.getPool()
|
|
if (!pool) {
|
|
return null
|
|
}
|
|
|
|
const filters = [
|
|
{
|
|
kinds: [9735],
|
|
ids: [zapReceiptId],
|
|
limit: 1,
|
|
},
|
|
]
|
|
|
|
const relayUrl = getPrimaryRelaySync()
|
|
const sub = createSubscription(pool, [relayUrl], filters)
|
|
|
|
return new Promise<Event | null>((resolve) => {
|
|
let resolved = false
|
|
|
|
const finalize = (value: Event | null): void => {
|
|
if (resolved) {
|
|
return
|
|
}
|
|
resolved = true
|
|
sub.unsub()
|
|
resolve(value)
|
|
}
|
|
|
|
sub.on('event', (event: Event) => {
|
|
finalize(event)
|
|
})
|
|
|
|
sub.on('eose', () => finalize(null))
|
|
setTimeout(() => finalize(null), 5000)
|
|
})
|
|
}
|