From 13ecf8bf8b85d857c8c087dba527af45cbf353da Mon Sep 17 00:00:00 2001 From: Nicolas Burtey Date: Tue, 22 Aug 2023 12:39:48 +0100 Subject: [PATCH] chore: make it possible to pass an amount for initial request --- README.md | 1 + app/lnurlp/[username]/route.ts | 26 ++++++++++++++++++-------- hooks/use-Create-Invoice.tsx | 2 -- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 8c338714..a83044dc 100644 --- a/README.md +++ b/README.md @@ -77,3 +77,4 @@ This will build the app for production under a `build` folder. It will bundle Re This environment variable is needed for getting the lnurlp endpoint working. curl localhost:3000/.well-known/lnurlp/alice +curl localhost:3000/.well-known/lnurlp/alice?amount=1234 diff --git a/app/lnurlp/[username]/route.ts b/app/lnurlp/[username]/route.ts index 5b32c773..5dbefe86 100644 --- a/app/lnurlp/[username]/route.ts +++ b/app/lnurlp/[username]/route.ts @@ -9,7 +9,7 @@ import { InMemoryCache, } from "@apollo/client" -import { GRAPHQL_URL_INTERNAL, NOSTR_PUBKEY } from "../../../lib/config" +import { GRAPHQL_URL, GRAPHQL_URL_INTERNAL, NOSTR_PUBKEY } from "../../../lib/config" import { AccountDefaultWalletDocument, AccountDefaultWalletQuery, @@ -78,16 +78,18 @@ export async function GET( ) { console.log(NOSTR_PUBKEY) + const { searchParams } = new URL(request.url) + const username = params.username - const accountUsername = username ? username.toString() : "" + const amount = searchParams.get("amount") let walletId: string | null = null try { const { data } = await client.query({ query: AccountDefaultWalletDocument, - variables: { username: accountUsername, walletCurrency: "BTC" }, + variables: { username, walletCurrency: "BTC" }, context: { "x-real-ip": request.headers.get("x-real-ip"), "x-forwarded-for": request.headers.get("x-forwarded-for"), @@ -106,17 +108,25 @@ export async function GET( } const metadata = JSON.stringify([ - ["text/plain", `Payment to ${accountUsername}`], - ["text/identifier", `${accountUsername}@${URL_HOST_DOMAIN}`], + ["text/plain", `Payment to ${username}`], + ["text/identifier", `${username}@${URL_HOST_DOMAIN}`], ]) - const payServer = GRAPHQL_URI.replace("/graphql", "").replace("api", "pay") + const payServer = GRAPHQL_URL.replace("/graphql", "").replace("api", "pay") const callback = `${payServer}/.well-known/${username}/lnurlp/callback` + let minSendable = 1000 // 1 sat in millisat + let maxSendable = 100000000000 // 1 BTC in millisat + + if (amount && Number.isInteger(Number(amount))) { + minSendable = Number(amount) * 1000 + maxSendable = Number(amount) * 1000 + } + return NextResponse.json({ callback, - minSendable: 1000, - maxSendable: 100000000000, + minSendable, + maxSendable, metadata, tag: "payRequest", ...(nostrEnabled diff --git a/hooks/use-Create-Invoice.tsx b/hooks/use-Create-Invoice.tsx index f36055ad..9daae169 100644 --- a/hooks/use-Create-Invoice.tsx +++ b/hooks/use-Create-Invoice.tsx @@ -29,9 +29,7 @@ gql` __typename } } -` -gql` mutation lnInvoiceCreateOnBehalfOfRecipients( $input: LnInvoiceCreateOnBehalfOfRecipientInput! ) {