Skip to content

Commit

Permalink
chore: prioritize incoming memo for lnurl/ln-address
Browse files Browse the repository at this point in the history
  • Loading branch information
vindard committed Aug 28, 2024
1 parent 0fac444 commit d4a8b18
Showing 1 changed file with 35 additions and 18 deletions.
53 changes: 35 additions & 18 deletions core/api/src/app/payments/send-lnurl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { payInvoiceByWalletId } from "./send-lightning"

import { LnurlPayService } from "@/services/lnurl-pay"
import { checkedToBtcPaymentAmount } from "@/domain/shared"
import { decodeInvoice } from "@/domain/bitcoin/lightning"

export const lnAddressPaymentSend = async ({
senderWalletId,
Expand All @@ -16,18 +17,26 @@ export const lnAddressPaymentSend = async ({
return amount
}

const invoice = await LnurlPayService().fetchInvoiceFromLnAddressOrLnurl({
amount,
lnAddressOrLnurl: lnAddress,
})

if (invoice instanceof Error) {
return invoice
const uncheckedPaymentRequest =
await LnurlPayService().fetchInvoiceFromLnAddressOrLnurl({
amount,
lnAddressOrLnurl: lnAddress,
})
if (uncheckedPaymentRequest instanceof Error) {
return uncheckedPaymentRequest
}

const decodedInvoice = decodeInvoice(uncheckedPaymentRequest)
const resolvedMemo =
decodedInvoice instanceof Error
? memo
: decodedInvoice.description
? decodedInvoice.description
: memo

return payInvoiceByWalletId({
uncheckedPaymentRequest: invoice,
memo,
uncheckedPaymentRequest,
memo: resolvedMemo,
senderWalletId,
senderAccount,
})
Expand All @@ -46,18 +55,26 @@ export const lnurlPaymentSend = async ({
return amount
}

const invoice = await LnurlPayService().fetchInvoiceFromLnAddressOrLnurl({
amount,
lnAddressOrLnurl: lnurl,
})

if (invoice instanceof Error) {
return invoice
const uncheckedPaymentRequest =
await LnurlPayService().fetchInvoiceFromLnAddressOrLnurl({
amount,
lnAddressOrLnurl: lnurl,
})
if (uncheckedPaymentRequest instanceof Error) {
return uncheckedPaymentRequest
}

const decodedInvoice = decodeInvoice(uncheckedPaymentRequest)
const resolvedMemo =
decodedInvoice instanceof Error
? memo
: decodedInvoice.description
? decodedInvoice.description
: memo

return payInvoiceByWalletId({
uncheckedPaymentRequest: invoice,
memo,
uncheckedPaymentRequest,
memo: resolvedMemo,
senderWalletId,
senderAccount,
})
Expand Down

0 comments on commit d4a8b18

Please sign in to comment.