From ca27ba583f09323bdaa660aadadb41f709091bc3 Mon Sep 17 00:00:00 2001 From: Sandipan Dey Date: Thu, 21 Sep 2023 13:22:18 +0530 Subject: [PATCH] feat: allow memo in paycode --- .../payment-request-creation-data.spec.ts | 2 +- .../payment/payment-request-creation-data.ts | 2 +- .../payment/payment-request.ts | 24 +++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/__tests__/payment-request/payment-request-creation-data.spec.ts b/__tests__/payment-request/payment-request-creation-data.spec.ts index a3da14c45c..f93c75e16b 100644 --- a/__tests__/payment-request/payment-request-creation-data.spec.ts +++ b/__tests__/payment-request/payment-request-creation-data.spec.ts @@ -65,7 +65,7 @@ describe("create payment request creation data", () => { expect(prcd.canUsePaycode).toBe(true) expect(prcd.username).toBe("test-username") expect(prcd.canSetAmount).toBe(true) - expect(prcd.canSetMemo).toBe(false) + expect(prcd.canSetMemo).toBe(true) expect(prcd.canSetReceivingWalletDescriptor).toBe(false) expect(prcd.receivingWalletDescriptor).toBe(btcWalletDescriptor) }) diff --git a/app/screens/receive-bitcoin-screen/payment/payment-request-creation-data.ts b/app/screens/receive-bitcoin-screen/payment/payment-request-creation-data.ts index b700937343..b32cf6dc55 100644 --- a/app/screens/receive-bitcoin-screen/payment/payment-request-creation-data.ts +++ b/app/screens/receive-bitcoin-screen/payment/payment-request-creation-data.ts @@ -36,7 +36,7 @@ export const createPaymentRequestCreationData = ( // Permissions for the specified type const permissions = { canSetReceivingWalletDescriptor: false, - canSetMemo: false, + canSetMemo: true, canSetAmount: true, } if (type === Invoice.Lightning || type === Invoice.OnChain) { diff --git a/app/screens/receive-bitcoin-screen/payment/payment-request.ts b/app/screens/receive-bitcoin-screen/payment/payment-request.ts index f7c62afb25..b506bfa08b 100644 --- a/app/screens/receive-bitcoin-screen/payment/payment-request.ts +++ b/app/screens/receive-bitcoin-screen/payment/payment-request.ts @@ -209,23 +209,23 @@ export const createPaymentRequest = ( // Paycode } else if (pr.type === Invoice.PayCode && pr.username) { - const queryStringForAmount = - pr.unitOfAccountAmount === undefined || pr.unitOfAccountAmount.amount === 0 - ? "" - : `amount=${pr.unitOfAccountAmount?.amount}¤cy=${pr.unitOfAccountAmount?.currencyCode}` + const baseLnurl = `${pr.posUrl}/.well-known/lnurlp/${pr.username}` + const url = new URL(baseLnurl) + + if (pr.unitOfAccountAmount !== undefined && pr.unitOfAccountAmount.amount !== 0) { + url.searchParams.append("amount", pr.unitOfAccountAmount.amount.toString()) + url.searchParams.append("currency", pr.unitOfAccountAmount.currencyCode) + } + + if (pr.memo !== "") { + url.searchParams.append("comment", pr.memo) + } const lnurl: string = await new Promise((resolve) => { resolve( bech32.encode( "lnurl", - bech32.toWords( - Buffer.from( - `${pr.posUrl}/.well-known/lnurlp/${pr.username}${ - queryStringForAmount ? `?${queryStringForAmount}` : "" - }`, - "utf8", - ), - ), + bech32.toWords(Buffer.from(url.toString(), "utf8")), 1500, ), )