Compare commits

...

2 Commits

Author SHA1 Message Date
a5a6a1711a Fix displayed sats 2024-12-27 19:48:30 +01:00
700df20260 Add QR code 2024-12-27 19:48:30 +01:00
6 changed files with 33 additions and 6 deletions

1
go.mod
View File

@ -11,6 +11,7 @@ require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/namsral/flag v1.7.4-pre // indirect
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
golang.org/x/crypto v0.31.0 // indirect

2
go.sum
View File

@ -34,6 +34,8 @@ github.com/namsral/flag v1.7.4-pre/go.mod h1:OXldTctbM6SWH1K899kPZcf65KxJiD7Msce
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=

View File

@ -132,7 +132,7 @@ func (p *Phoenixd) GetInvoice(paymentHash string) (*lightning.Invoice, error) {
var response struct {
PaymentHash string `json:"paymentHash"`
Preimage string `json:"preimage"`
Msats int64 `json:"receivedSat"`
Sats int64 `json:"receivedSat"`
Description string `json:"description"`
CreatedAt int64 `json:"createdAt"`
ConfirmedAt int64 `json:"completedAt"`
@ -150,7 +150,7 @@ func (p *Phoenixd) GetInvoice(paymentHash string) (*lightning.Invoice, error) {
return &lightning.Invoice{
PaymentHash: response.PaymentHash,
Preimage: response.Preimage,
Msats: response.Msats,
Msats: response.Sats * 1_000,
Description: response.Description,
CreatedAt: createdAt,
ConfirmedAt: confirmedAt,

View File

@ -1,6 +1,9 @@
package pages
templ Overlay() {
import "github.com/skip2/go-qrcode"
import "encoding/base64"
templ Overlay(lnurl string) {
<html>
<head>
<meta charset="UTF-8">
@ -25,6 +28,22 @@ templ Overlay() {
}, 60_000)
})
</script>
<div class="bg-white fixed bottom-0 left-0 text-center p-3">
<img src={ "data:image/jpeg;base64," + qrEncode(lnurl) }/>
<div>scan to zap message</div>
</div>
</body>
</html>
}
func qrEncode(value string) string {
q, err := qrcode.New(value, qrcode.Medium)
q.DisableBorder = true
png, err := q.PNG(256)
if err != nil {
return ""
}
return base64.StdEncoding.EncodeToString([]byte(png))
}

View File

@ -27,8 +27,10 @@ func GetEnv(ctx context.Context) string {
return "development"
}
func OverlayHandler(c echo.Context) error {
return render(c, http.StatusOK, Overlay())
func OverlayHandler(lnurl string) echo.HandlerFunc {
return func(c echo.Context) error {
return render(c, http.StatusOK, Overlay(lnurl))
}
}
func render(ctx echo.Context, statusCode int, t templ.Component) error {

View File

@ -1,6 +1,7 @@
package server
import (
"fmt"
"log"
"net/url"
@ -44,7 +45,9 @@ func NewServer() *Server {
s.Static("/", "public/")
s.GET("/overlay", pages.OverlayHandler)
s.GET("/overlay", pages.OverlayHandler(
lnurl.Encode(fmt.Sprintf("%s/.well-known/lnurlp/%s", env.PublicUrl, "SNL")),
))
s.GET("/overlay/sse", sseHandler(p.IncomingPayments()))
return s