Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
chore: make it possible to pass an amount for initial request
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Burtey committed Aug 22, 2023
1 parent 76700a4 commit 13ecf8b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 18 additions & 8 deletions app/lnurlp/[username]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<AccountDefaultWalletQuery>({
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"),
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions hooks/use-Create-Invoice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ gql`
__typename
}
}
`
gql`
mutation lnInvoiceCreateOnBehalfOfRecipients(
$input: LnInvoiceCreateOnBehalfOfRecipientInput!
) {
Expand Down

0 comments on commit 13ecf8b

Please sign in to comment.