-
Notifications
You must be signed in to change notification settings - Fork 46
fix: replace .single() with .maybeSingle() in 5 more routes (PR 3/3) #477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,7 +54,7 @@ | |
| return NextResponse.json({ error: "No Lightning wallet found" }, { status: 400 }); | ||
| } | ||
|
|
||
| // Pre-check sender's balance (informational only — authoritative check happens at transfer time) | ||
| // Pre-check sender's balance (informational only �authoritative check happens at transfer time) | ||
| const senderBalance = await getLnBalance(senderWallet.invoice_key); | ||
| if (senderBalance < amount_sats) { | ||
| return NextResponse.json({ error: "Insufficient balance", balance_sats: senderBalance }, { status: 400 }); | ||
|
|
@@ -70,7 +70,7 @@ | |
| const fee_sats = Math.floor(amount_sats * PLATFORM_FEE_RATE); | ||
| const recipient_amount = amount_sats - fee_sats; | ||
|
|
||
| // Transfer recipient's share: sender → recipient (instant internal transfer) | ||
| // Transfer recipient's share: sender �recipient (instant internal transfer) | ||
| // Handle insufficient-funds errors gracefully (TOCTOU race condition #78) | ||
| try { | ||
| await internalTransfer( | ||
|
|
@@ -117,13 +117,13 @@ | |
| }, { status: 502 }); | ||
| } | ||
|
|
||
| // Generic LNbits error — expose the actual message | ||
| // Generic LNbits error �expose the actual message | ||
| return NextResponse.json({ | ||
| error: err?.message || "Zap transfer failed", | ||
| }, { status: 502 }); | ||
| } | ||
|
|
||
| // Transfer platform fee: sender → platform wallet (retry up to 3 times) | ||
| // Transfer platform fee: sender �platform wallet (retry up to 3 times) | ||
| if (fee_sats > 0) { | ||
| let feeTransferred = false; | ||
| for (let attempt = 1; attempt <= 3; attempt++) { | ||
|
|
@@ -190,7 +190,7 @@ | |
| note: note || null, | ||
| }) | ||
| .select() | ||
| .single(); | ||
| .maybeSingle(); | ||
|
|
||
| const zapId = (zap as any)?.id; | ||
|
|
||
|
|
@@ -229,30 +229,30 @@ | |
| .from("profiles") | ||
| .select("*") | ||
| .eq("id", recipient_id) | ||
| .single(); | ||
| .maybeSingle(); | ||
|
|
||
| const { data: senderProfile } = await admin | ||
| .from("profiles") | ||
| .select("username") | ||
| .eq("id", senderId) | ||
| .single(); | ||
| .maybeSingle(); | ||
|
|
||
| const senderName = senderProfile?.username || "Someone"; | ||
|
|
||
| if ((recipientProfile as any)?.ln_address) { | ||
| await (admin.from("notifications") as any).insert({ | ||
| user_id: recipient_id, | ||
| type: "zap_received", | ||
| title: "You received a zap! âš¡", | ||
| title: "You received a zap! âš?, | ||
| body: `${senderName} zapped you ${recipient_amount.toLocaleString()} sats`, | ||
| data: { zap_id: zapId, amount_sats: recipient_amount, target_type, target_id }, | ||
| }); | ||
| } else { | ||
| await (admin.from("notifications") as any).insert({ | ||
| user_id: recipient_id, | ||
| type: "zap_received", | ||
| title: "You received a zap! âš¡", | ||
| title: "You received a zap! âš?, | ||
| body: `${senderName} zapped you ${recipient_amount.toLocaleString()} sats. Add a Lightning Address to your profile to withdraw.`, | ||
|
Comment on lines
+246
to
255
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The lightning bolt emoji |
||
| data: { zap_id: zapId, amount_sats: recipient_amount, target_type, target_id, action_url: "/profile" }, | ||
| }); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
starsvariableThe
★and☆characters have been replaced with garbled/replacement bytes (?). As written, thestarsvariable will contain corrupted characters repeatedratingtimes rather than actual star glyphs. This string appears in the HTML email body (line 230) and the email subject (line 227), so every testimonial notification email will show garbage characters instead of a star rating like★★★☆☆.