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

Add LNURL Fallback Scheme to Web URL #318

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions pages/[username]/print.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ export async function getServerSideProps({
params: { username: string }
}) {
const url = originalUrl(req)

const lnurlp = bech32.encode(
"lnurl",
bech32.toWords(
Buffer.from(
`${url.protocol}//${url.hostname}/.well-known/lnurlp/${username}`,
"utf8",
),
),
1500,
)
return {
props: {
lightningAddress: `${username}@${url.hostname}`,
lnurl: bech32.encode(
"lnurl",
bech32.toWords(
Buffer.from(
`${url.protocol}//${url.hostname}/.well-known/lnurlp/${username}`,
"utf8",
),
),
1500,
),
webURL: `${url.protocol}//${url.hostname}/${username}`,
lnurl: lnurlp,
webURL: `${url.protocol}//${url.hostname}/${username}?lightning=${lnurlp}`,
},
}
}
Expand All @@ -46,7 +46,8 @@ export default function ({
webURL: string
}) {
const componentRef = useRef<HTMLDivElement | null>(null)
const [qrType, setQR] = useState("lnurl")
const [qrType, setQR] = useState("web")
const qrCodeData = (qrType === "lnurl" ? lnurl : webURL).toUpperCase()

return (
<>
Expand All @@ -61,7 +62,7 @@ export default function ({
<h1>Pay {lightningAddress}</h1>
<QRCode
ecLevel="H"
value={qrType === "lnurl" ? lnurl : webURL}
value={qrCodeData}
size={800}
logoImage="/BBQRLogo.png"
logoWidth={250}
Expand All @@ -85,7 +86,7 @@ export default function ({
<h3>Pay {lightningAddress}</h3>
<QRCode
ecLevel="H"
value={qrType === "lnurl" ? lnurl : webURL}
value={qrCodeData}
size={300}
logoImage="/BBQRLogo.png"
logoWidth={100}
Expand Down