Skip to content

Commit

Permalink
feat: allow memo in paycode
Browse files Browse the repository at this point in the history
  • Loading branch information
sandipndev committed Oct 31, 2023
1 parent a174d5a commit ca27ba5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const createPaymentRequestCreationData = <T extends WalletCurrency>(
// Permissions for the specified type
const permissions = {
canSetReceivingWalletDescriptor: false,
canSetMemo: false,
canSetMemo: true,
canSetAmount: true,
}
if (type === Invoice.Lightning || type === Invoice.OnChain) {
Expand Down
24 changes: 12 additions & 12 deletions app/screens/receive-bitcoin-screen/payment/payment-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}&currency=${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,
),
)
Expand Down

0 comments on commit ca27ba5

Please sign in to comment.