Offer LNURL QR code for download on Lightning info page #135

Merged
raucao merged 5 commits from feature/lightning_donation_qr_codes into master 2023-06-20 16:44:59 +00:00
Showing only changes of commit 332ad757a5 - Show all commits

View File

@@ -17,39 +17,40 @@ class Services::LightningController < ApplicationController
end
def qr_lnurlp
lnurlp_url = "https://kosmos.org/.well-known/lnurlp/#{current_user.cn}"
lnurlp_bech32 = Lnurl.new(lnurlp_url).to_bech32
qr_code = RQRCode::QRCode.new("lightning:" + lnurlp_bech32)
respond_to do |format|
lnurlp_url = "https://kosmos.org/.well-known/lnurlp/#{current_user.cn}"
lnurlp_bech32 = Lnurl.new(lnurlp_url).to_bech32
qr_code = RQRCode::QRCode.new("lightning:" + lnurlp_bech32)
raucao marked this conversation as resolved Outdated
Outdated
Review

why don't you use respond_to here?

why don't you use `respond_to` here?

Good question. Should've done so to begin with. Refactored and pushed.

Good question. Should've done so to begin with. Refactored and pushed.
Outdated
Review

I'd move the logic out of this block and only have

lnurlp_url = "https://kosmos.org/.well-known/lnurlp/#{current_user.cn}"
lnurlp_bech32 = Lnurl.new(lnurlp_url).to_bech32
qr_code = RQRCode::QRCode.new("lightning:" + lnurlp_bech32)
      
respond_to do |format|
  format.svg ...
  format.png ...
end
I'd move the logic out of this block and only have ``` lnurlp_url = "https://kosmos.org/.well-known/lnurlp/#{current_user.cn}" lnurlp_bech32 = Lnurl.new(lnurlp_url).to_bech32 qr_code = RQRCode::QRCode.new("lightning:" + lnurlp_bech32) respond_to do |format| format.svg ... format.png ... end ```
if params[:format] == "svg"
qr_svg = qr_code.as_svg(
color: "000",
shape_rendering: "crispEdges",
module_size: 6,
standalone: true,
use_path: true,
svg_attributes: {
class: 'inline-block'
}
)
send_data(
qr_svg,
filename: "bitcoin-lightning-#{current_user.address}.svg",
type: "image/svg+xml"
)
elsif params[:format] == "png"
qr_png = qr_code.as_png(
fill: "white",
color: "black",
size: 1024,
)
send_data(
qr_png,
filename: "bitcoin-lightning-#{current_user.address}.png",
type: "image/png"
)
else
http_status :not_found
format.svg do
qr_svg = qr_code.as_svg(
color: "000",
shape_rendering: "crispEdges",
module_size: 6,
standalone: true,
use_path: true,
svg_attributes: {
class: 'inline-block'
}
)
send_data(
qr_svg,
filename: "bitcoin-lightning-#{current_user.address}.svg",
raucao marked this conversation as resolved Outdated
Outdated
Review

does this need a disposition attribute? 🤔

does this need a `disposition` attribute? 🤔

Disposition should default to attachment, i.e. download. It works exactly as intended in FF, maybe you could test manually in another browser?

Disposition should default to attachment, i.e. download. It works exactly as intended in FF, maybe you could test manually in another browser?
type: "image/svg+xml"
)
end
format.png do
qr_png = qr_code.as_png(
fill: "white",
color: "black",
size: 1024,
)
send_data(
qr_png,
filename: "bitcoin-lightning-#{current_user.address}.png",
type: "image/png"
)
end
end
end