From d4a8b18a528a6b74989433033708da84e4c77d49 Mon Sep 17 00:00:00 2001 From: vindard <17693119+vindard@users.noreply.github.com> Date: Tue, 27 Aug 2024 20:40:04 -0400 Subject: [PATCH] chore: prioritize incoming memo for lnurl/ln-address --- core/api/src/app/payments/send-lnurl.ts | 53 ++++++++++++++++--------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/core/api/src/app/payments/send-lnurl.ts b/core/api/src/app/payments/send-lnurl.ts index 1d86c590da..89fd529247 100644 --- a/core/api/src/app/payments/send-lnurl.ts +++ b/core/api/src/app/payments/send-lnurl.ts @@ -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, @@ -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, }) @@ -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, })