added support for zapping replaceable events (#424)
* added support for zapping replaceable events * Update nip57.ts * Update nip57.ts Co-authored-by: 雪猫 <SnowCait@users.noreply.github.com> * apply @SnowCait's suggestions. * fix lint error. --------- Co-authored-by: AsaiToshiya <to.asai.60@gmail.com> Co-authored-by: 雪猫 <SnowCait@users.noreply.github.com>
This commit is contained in:
parent
c1172caf1d
commit
44a679e642
18
nip57.ts
18
nip57.ts
|
@ -2,6 +2,7 @@ import { bech32 } from '@scure/base'
|
||||||
|
|
||||||
import { validateEvent, verifyEvent, type Event, type EventTemplate } from './pure.ts'
|
import { validateEvent, verifyEvent, type Event, type EventTemplate } from './pure.ts'
|
||||||
import { utf8Decoder } from './utils.ts'
|
import { utf8Decoder } from './utils.ts'
|
||||||
|
import { isReplaceableKind, isAddressableKind } from './kinds.ts'
|
||||||
|
|
||||||
var _fetch: any
|
var _fetch: any
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ export function makeZapRequest({
|
||||||
comment = '',
|
comment = '',
|
||||||
}: {
|
}: {
|
||||||
profile: string
|
profile: string
|
||||||
event: string | null
|
event: string | Event | null
|
||||||
amount: number
|
amount: number
|
||||||
comment: string
|
comment: string
|
||||||
relays: string[]
|
relays: string[]
|
||||||
|
@ -68,9 +69,22 @@ export function makeZapRequest({
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event) {
|
if (event && typeof event === 'string') {
|
||||||
zr.tags.push(['e', event])
|
zr.tags.push(['e', event])
|
||||||
}
|
}
|
||||||
|
if (event && typeof event === 'object') {
|
||||||
|
// replacable event
|
||||||
|
if (isReplaceableKind(event.kind)) {
|
||||||
|
const a = ['a', `${event.kind}:${event.pubkey}:`]
|
||||||
|
zr.tags.push(a)
|
||||||
|
// addressable event
|
||||||
|
} else if (isAddressableKind(event.kind)) {
|
||||||
|
let d = event.tags.find(([t, v]) => t === 'd' && v)
|
||||||
|
if (!d) throw new Error('d tag not found or is empty')
|
||||||
|
const a = ['a', `${event.kind}:${event.pubkey}:${d[1]}`]
|
||||||
|
zr.tags.push(a)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return zr
|
return zr
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue