Skip to content

Commit

Permalink
fix(pay): print paycode page (#3708)
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleSamtoshi authored Dec 14, 2023
1 parent 91a4525 commit 2f10588
Showing 1 changed file with 10 additions and 46 deletions.
56 changes: 10 additions & 46 deletions apps/pay/pages/[username]/print.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,23 @@ import ReactToPrint from "react-to-print"
import { bech32 } from "bech32"
import { QRCode } from "react-qrcode-logo"
import { useRef } from "react"
import { useRouter } from "next/router"

import { NextRequest } from "next/server"

import { getOriginalRequestInfo } from "../../utils/utils"

export async function getServerSideProps({
req,
params: { username },
}: {
req: NextRequest
params: { username: string }
}) {
const originalUrlInfo = getOriginalRequestInfo(req)
export default function Print() {
const componentRef = useRef<HTMLDivElement | null>(null)

const router = useRouter()
const username = router.query.username as string
const url = new URL(window.location.href)
const unencodedLnurl = `${url.protocol}//${url.host}/.well-known/lnurlp/${username}`
const lnurl = bech32.encode(
"lnurl",
bech32.toWords(
Buffer.from(
`${originalUrlInfo}://${originalUrlInfo.hostname}${
originalUrlInfo.port ? `:${originalUrlInfo.port}` : ""
}/.well-known/lnurlp/${username}`,
"utf8",
),
),
bech32.toWords(Buffer.from(unencodedLnurl, "utf8")),
1500,
)

const webURL = `${originalUrlInfo.protocol}//${originalUrlInfo.hostname}${
originalUrlInfo.port ? `:${originalUrlInfo.port}` : ""
}/${username}`

const webURL = `${url.protocol}//${url.host}/${username}`
const qrCodeURL = (webURL + "?lightning=" + lnurl).toUpperCase()

return {
props: {
qrCodeURL,
username,
userHeader: `Pay ${username}@${originalUrlInfo.hostname}`,
},
}
}

export default function Print({
qrCodeURL,
username,
userHeader,
}: {
lightningAddress: string
qrCodeURL: string
username: string
userHeader: string
}) {
const componentRef = useRef<HTMLDivElement | null>(null)
const userHeader = `Pay ${username}@${url.hostname}`

return (
<>
Expand Down

0 comments on commit 2f10588

Please sign in to comment.