@@ -54,6 +54,21 @@ function findByTag(tags: string[][], tag: string): string | undefined {
54
54
}
55
55
}
56
56
57
+ function getZapKind ( event : NostrEvent ) : "public" | "private" | "anonymous" {
58
+ const anonTag = event . tags . find ( ( t ) => {
59
+ if ( t [ 0 ] === "anon" ) {
60
+ return true ;
61
+ }
62
+ } ) ;
63
+
64
+ // If the anon field is empty it's anon, if it has other elements its private, otherwise it's public
65
+ if ( anonTag ) {
66
+ return anonTag . length < 2 ? "anonymous" : "private" ;
67
+ }
68
+
69
+ return "public" ;
70
+ }
71
+
57
72
async function simpleZapFromEvent (
58
73
event : NostrEvent ,
59
74
wallet : MutinyWallet
@@ -66,8 +81,6 @@ async function simpleZapFromEvent(
66
81
const from = request . pubkey ;
67
82
68
83
const content = request . content ;
69
- const anon = findByTag ( request . tags , "anon" ) ;
70
-
71
84
const bolt11 = findByTag ( event . tags , "bolt11" ) || "" ;
72
85
73
86
if ( ! bolt11 ) {
@@ -100,13 +113,7 @@ async function simpleZapFromEvent(
100
113
}
101
114
102
115
return {
103
- // If the anon field is empty it's anon, if it has length it's private, otherwise it's public
104
- kind :
105
- typeof anon === "string"
106
- ? anon . length
107
- ? "private"
108
- : "anonymous"
109
- : "public" ,
116
+ kind : getZapKind ( request ) ,
110
117
from_hexpub : from ,
111
118
to_hexpub : to ,
112
119
timestamp : BigInt ( event . created_at ) ,
@@ -280,7 +287,7 @@ export const fetchZaps: ResourceFetcher<
280
287
zaps . push ( event ) ;
281
288
}
282
289
} catch ( e ) {
283
- console . error ( "Failed to parse zap event: " , object ) ;
290
+ console . error ( "Failed to parse zap event: " , object , e ) ;
284
291
}
285
292
}
286
293
}
0 commit comments