Compare commits
1 Commits
Author | SHA1 | Date |
---|---|---|
ekzyis | 8c0b262282 |
|
@ -8,13 +8,13 @@ import (
|
||||||
|
|
||||||
templ Zap(inv *lightning.Invoice) {
|
templ Zap(inv *lightning.Invoice) {
|
||||||
<div class="bg-[#212529] w-fit zap-animate-in border border-[#212529] m-3 rounded-lg" id={ inv.PaymentHash }>
|
<div class="bg-[#212529] w-fit zap-animate-in border border-[#212529] m-3 rounded-lg" id={ inv.PaymentHash }>
|
||||||
<div class="flex flex-row gap-3 py-1 items-center">
|
<div class="flex flex-row gap-3 items-center">
|
||||||
<svg width="32" height="32" viewBox="0 0 200 307" fill="#fada5e" xmlns="http://www.w3.org/2000/svg" class="ps-3">
|
<svg width="32" height="32" viewBox="0 0 200 307" fill="#fada5e" xmlns="http://www.w3.org/2000/svg" class="ps-3">
|
||||||
<path d="M56 0L107.606 131H90.2129H89L1.52588e-05 131L177 307L106.979 165H121H160H200L56 0Z"/>
|
<path d="M56 0L107.606 131H90.2129H89L1.52588e-05 131L177 307L106.979 165H121H160H200L56 0Z"/>
|
||||||
</svg>
|
</svg>
|
||||||
<div class="flex flex-col pe-3 py-1">
|
<div class="flex flex-col pe-3 py-1">
|
||||||
<div class="text-lg text-[#f0f0f0]">{ inv.Description }</div>
|
<div class="text-lg text-[#f0f0f0]">{ inv.Description }</div>
|
||||||
<div class="text-sm text-slate-300">{ fmt.Sprintf("%s", humanize(inv.Msats)) }</div>
|
<div class="text-sm text-slate-300">{ fmt.Sprintf("%.8s / %s", inv.PaymentHash, humanize(inv.Msats)) }</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -3,7 +3,7 @@ package pages
|
||||||
import "github.com/skip2/go-qrcode"
|
import "github.com/skip2/go-qrcode"
|
||||||
import "encoding/base64"
|
import "encoding/base64"
|
||||||
|
|
||||||
templ Overlay(lnurl string, lnaddr string) {
|
templ Overlay(lnurl string) {
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
@ -28,50 +28,10 @@ templ Overlay(lnurl string, lnaddr string) {
|
||||||
}, 60_000)
|
}, 60_000)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
<div id="qr" class="bg-white fixed bottom-0 left-0 text-center p-3 cursor-move" style="left: 0; bottom: 0;" draggable="true">
|
<div class="bg-white fixed bottom-0 left-0 text-center p-3">
|
||||||
<div class="p-2">
|
<img src={ "data:image/jpeg;base64," + qrEncode(lnurl) }/>
|
||||||
<div class="font-bold">{ lnaddr }</div>
|
<div>scan to zap message</div>
|
||||||
<img src={ "data:image/jpeg;base64," + qrEncode(lnurl) }/>
|
|
||||||
</div>
|
|
||||||
<div class="italic">zap us a message!</div>
|
|
||||||
</div>
|
</div>
|
||||||
<script>
|
|
||||||
const qr = document.getElementById("qr");
|
|
||||||
|
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
|
||||||
let queryX = parseInt(urlParams.get('x'));
|
|
||||||
let queryY = parseInt(urlParams.get('y'));
|
|
||||||
const [localX,localY] = localStorage.getItem('qrPosition')?.split(',').map(Number) ?? [0,0];
|
|
||||||
|
|
||||||
let currentX = !isNaN(queryX) ? queryX : localX;
|
|
||||||
let currentY = !isNaN(queryY) ? queryY : localY;
|
|
||||||
qr.style.transform = `translate(${currentX}px, ${currentY}px)`;
|
|
||||||
|
|
||||||
let startX = 0;
|
|
||||||
let startY = 0;
|
|
||||||
|
|
||||||
qr.addEventListener("dragstart", (e) => {
|
|
||||||
startX = e.clientX - currentX;
|
|
||||||
startY = e.clientY - currentY;
|
|
||||||
e.dataTransfer.setData("text/plain", `${currentX},${currentY}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
qr.addEventListener("drag", (e) => {
|
|
||||||
if (e.clientX && e.clientY) {
|
|
||||||
currentX = e.clientX - startX;
|
|
||||||
currentY = e.clientY - startY;
|
|
||||||
qr.style.transform = `translate(${currentX}px, ${currentY}px)`;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
qr.addEventListener("dragend", (e) => {
|
|
||||||
currentX = e.clientX - startX;
|
|
||||||
currentY = e.clientY - startY;
|
|
||||||
qr.style.transform = `translate(${currentX}px, ${currentY}px)`;
|
|
||||||
localStorage.setItem('qrPosition', `${currentX},${currentY}`);
|
|
||||||
window.location.search = `?x=${currentX}&y=${currentY}`
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,9 +27,9 @@ func GetEnv(ctx context.Context) string {
|
||||||
return "development"
|
return "development"
|
||||||
}
|
}
|
||||||
|
|
||||||
func OverlayHandler(lnurl string, lnaddr string) echo.HandlerFunc {
|
func OverlayHandler(lnurl string) echo.HandlerFunc {
|
||||||
return func(c echo.Context) error {
|
return func(c echo.Context) error {
|
||||||
return render(c, http.StatusOK, Overlay(lnurl, lnaddr))
|
return render(c, http.StatusOK, Overlay(lnurl))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,11 +27,6 @@ func NewServer() *Server {
|
||||||
CustomTimeFormat: "2006-01-02 15:04:05.00000-0700",
|
CustomTimeFormat: "2006-01-02 15:04:05.00000-0700",
|
||||||
}))
|
}))
|
||||||
|
|
||||||
u, err := url.Parse(env.PublicUrl)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
webhookPath := "/overlay/webhook"
|
webhookPath := "/overlay/webhook"
|
||||||
webhookUrl, err := url.JoinPath(env.PublicUrl, webhookPath)
|
webhookUrl, err := url.JoinPath(env.PublicUrl, webhookPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -51,8 +46,7 @@ func NewServer() *Server {
|
||||||
s.Static("/", "public/")
|
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")),
|
lnurl.Encode(fmt.Sprintf("%s/.well-known/lnurlp/%s", env.PublicUrl, "SNL")),
|
||||||
fmt.Sprintf("%s@%s", "snl", u.Host),
|
|
||||||
))
|
))
|
||||||
s.GET("/overlay/sse", sseHandler(p.IncomingPayments()))
|
s.GET("/overlay/sse", sseHandler(p.IncomingPayments()))
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,11 @@ func sseHandler(invSrc chan *lightning.Invoice) echo.HandlerFunc {
|
||||||
ticker := time.NewTicker(1 * time.Second)
|
ticker := time.NewTicker(1 * time.Second)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
i := 0
|
||||||
|
|
||||||
|
ticker2 := time.NewTicker(1 * time.Second)
|
||||||
|
defer ticker2.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-c.Request().Context().Done():
|
case <-c.Request().Context().Done():
|
||||||
|
@ -66,11 +71,19 @@ func sseHandler(invSrc chan *lightning.Invoice) echo.HandlerFunc {
|
||||||
if err := event.MarshalTo(w); err != nil {
|
if err := event.MarshalTo(w); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case inv := <-invSrc:
|
case <-ticker2.C:
|
||||||
buf := templ.GetBuffer()
|
buf := templ.GetBuffer()
|
||||||
defer templ.ReleaseBuffer(buf)
|
defer templ.ReleaseBuffer(buf)
|
||||||
|
|
||||||
if err := components.Zap(inv).Render(c.Request().Context(), buf); err != nil {
|
inv := lightning.Invoice{
|
||||||
|
PaymentHash: fmt.Sprintf("test-%d", i),
|
||||||
|
Description: "test",
|
||||||
|
Msats: 1000,
|
||||||
|
CreatedAt: time.Now(),
|
||||||
|
ConfirmedAt: time.Now(),
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := components.Zap(&inv).Render(c.Request().Context(), buf); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +98,12 @@ func sseHandler(invSrc chan *lightning.Invoice) echo.HandlerFunc {
|
||||||
if err := event.MarshalTo(w); err != nil {
|
if err := event.MarshalTo(w); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
if i > 10 {
|
||||||
|
ticker2.Stop()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
w.Flush()
|
w.Flush()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue