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

Commit

Permalink
feat: fallback schema lnurl (#359)
Browse files Browse the repository at this point in the history
* feat: fallback schema lnurl
  • Loading branch information
abhiShandy authored Dec 6, 2022
1 parent ac7a17a commit 1661935
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions pages/[username]/print.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import originalUrl from "original-url"
import ReactToPrint from "react-to-print"
import { bech32 } from "bech32"
import { QRCode } from "react-qrcode-logo"
import { useRef, useState } from "react"
import { useRef } from "react"

export async function getServerSideProps({
req,
Expand All @@ -18,39 +18,42 @@ export async function getServerSideProps({
}) {
const url = originalUrl(req)

const lnurl = bech32.encode(
"lnurl",
bech32.toWords(
Buffer.from(
`${url.protocol}//${url.hostname}/.well-known/lnurlp/${username}`,
"utf8",
),
),
1500,
)

// Note: add the port to the webURL for local development
const webURL = `${url.protocol}//${url.hostname}/${username}`

const qrCodeURL = (webURL + "?lightning=" + lnurl).toUpperCase()

return {
props: {
lnurl: bech32.encode(
"lnurl",
bech32.toWords(
Buffer.from(
`${url.protocol}//${url.hostname}/.well-known/lnurlp/${username}`,
"utf8",
),
),
1500,
),
webURL: `${url.protocol}//${url.hostname}/${username}`,
qrCodeURL,
username,
userHeader: `${username}'s paycode`,
},
}
}

export default function ({
lnurl,
webURL,
qrCodeURL,
username,
userHeader,
}: {
lightningAddress: string
lnurl: string
webURL: string
qrCodeURL: string
username: string
userHeader: string
}) {
const componentRef = useRef<HTMLDivElement | null>(null)
const [qrType, setQR] = useState("lnurl")

return (
<>
Expand All @@ -69,7 +72,7 @@ export default function ({
</p>
<QRCode
ecLevel="H"
value={qrType === "lnurl" ? lnurl : webURL}
value={qrCodeURL}
size={800}
logoImage="/BBW-QRLOGO.png"
logoWidth={250}
Expand All @@ -96,7 +99,7 @@ export default function ({
</p>
<QRCode
ecLevel="H"
value={qrType === "lnurl" ? lnurl : webURL}
value={qrCodeURL}
size={300}
logoImage="/BBW-QRLOGO.png"
logoWidth={100}
Expand All @@ -109,14 +112,6 @@ export default function ({
<br />
</Container>
<Row className="justify-content-center">
<Button
style={{ marginRight: 10 }}
onClick={() => {
setQR(qrType === "web" ? "lnurl" : "web")
}}
>
Use {qrType === "web" ? "lnurl" : "web URL"}
</Button>
<ReactToPrint
trigger={() => <Button>Print QR Code</Button>}
content={() => componentRef.current}
Expand Down

0 comments on commit 1661935

Please sign in to comment.