From b618b1aa41b8a10d96d42556d2b00affdb4cf04d Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sun, 28 Aug 2022 19:16:23 +0200 Subject: [PATCH 1/3] create invoices --- internal/api/userpage/static/webapp.html | 92 +++++++++++++++++++----- internal/api/userpage/userpage.go | 3 +- 2 files changed, 77 insertions(+), 18 deletions(-) diff --git a/internal/api/userpage/static/webapp.html b/internal/api/userpage/static/webapp.html index 29499d7..00bbe57 100644 --- a/internal/api/userpage/static/webapp.html +++ b/internal/api/userpage/static/webapp.html @@ -58,6 +58,16 @@ pointer-events: none; } + input { + font-size: 14px; + text-align: center; + padding: 12px 20px; + border: none; + border-radius: 4px; + background-color: var(--tg-theme-button-color, #f5f5f5); + color: var(--tg-theme-button-text-color, #1a1a1a); + } + section { padding: 5px 5px 65px; text-align: center; @@ -200,13 +210,19 @@ width: 100% !important; height: 100% !important; } + + .wrapper { + display: grid; + grid-template-columns: 1fr 1fr; + padding: 12px 20px; + }
-

{{.Username}}@ln.tips

+

@@ -214,32 +230,35 @@
- + +
+
+ +
+
+ +
+
diff --git a/internal/api/userpage/userpage.go b/internal/api/userpage/userpage.go index b8383e9..39229f0 100644 --- a/internal/api/userpage/userpage.go +++ b/internal/api/userpage/userpage.go @@ -105,7 +105,8 @@ func (s Service) UserWebAppHandler(w http.ResponseWriter, r *http.Request) { if err := qr_tmpl.ExecuteTemplate(w, "webapp", struct { Username string LNURLPay string - }{username, lnurlEncode}); err != nil { + Callback string + }{username, lnurlEncode, callback}); err != nil { log.Errorf("failed to render template") } } From c8e45de27da7d3644136ba478bd8f315b464cb02 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sun, 28 Aug 2022 20:37:45 +0200 Subject: [PATCH 2/3] invoices --- internal/api/userpage/static/webapp.html | 51 ++++++++++++++++++------ internal/lnurl/lnurl.go | 2 +- internal/telegram/buttons.go | 1 + 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/internal/api/userpage/static/webapp.html b/internal/api/userpage/static/webapp.html index 00bbe57..dc10acf 100644 --- a/internal/api/userpage/static/webapp.html +++ b/internal/api/userpage/static/webapp.html @@ -62,10 +62,11 @@ font-size: 14px; text-align: center; padding: 12px 20px; + margin: 15px 0; border: none; border-radius: 4px; - background-color: var(--tg-theme-button-color, #f5f5f5); - color: var(--tg-theme-button-text-color, #1a1a1a); + background-color: var(--tg-theme-secondary-bg-color, #f5f5f5); + color: var(--tg-theme-text-color, #1a1a1a); } section { @@ -213,8 +214,10 @@ .wrapper { display: grid; - grid-template-columns: 1fr 1fr; + grid-template-columns: 3fr 2fr; padding: 12px 20px; + column-gap: 10px; + row-gap: 1em; } @@ -233,10 +236,10 @@
- +
- +
@@ -246,7 +249,7 @@ Telegram.WebApp.ready(); // render the LNURL pay QR code - var s = {{.LNURLPay}}; + var s = "{{.LNURLPay}}"; renderQr(s); // data passed form telegram server @@ -258,11 +261,30 @@ // document.querySelector('#initDataUnsafe').innerHTML = JSON.stringify(initDataUnsafe, null, 2); // react to theme changes - document.querySelector('#themeData').html(JSON.stringify(Telegram.WebApp.themeParams, null, 2)); - Telegram.WebApp.onEvent('themeChanged', function() { - document.querySelector('#themeData').innerHTML = JSON.stringify(Telegram.WebApp.themeParams, null, 2); + try { + document.querySelector('#themeData').html(JSON.stringify(Telegram.WebApp.themeParams, null, 2)); + Telegram.WebApp.onEvent('themeChanged', function() { + document.querySelector('#themeData').innerHTML = JSON.stringify(Telegram.WebApp.themeParams, null, 2); + }); + } catch (error) { + console.error(error); + } + + + + + // listen for enter in input field + var el = document.getElementById("invoiceAmount"); + console.log("Element:" + el) + el.addEventListener("keydown", function(event) { + if (event.key === "Enter") { + document.getElementById("requestInvoice").click(); + } + document.getElementById("requestInvoice").innerHTML = "Invoice" }); + // ------------------ functions ------------------ + function webviewClose() { Telegram.WebApp.close(); } @@ -299,9 +321,14 @@ }) .then(r => { console.log(r); - // update qr code - renderQr(r.pr); - document.querySelector('#greeting').innerHTML = "Pay " + invoiceAmount + " sat" + if (r.status == "OK"){ + // update qr code + renderQr(r.pr); + document.querySelector('#greeting').innerHTML = "Pay " + invoiceAmount + " sat"; + } else { + document.getElementById("requestInvoice").innerHTML = "Error" + } + }) }) } diff --git a/internal/lnurl/lnurl.go b/internal/lnurl/lnurl.go index 9d3443d..42a2510 100644 --- a/internal/lnurl/lnurl.go +++ b/internal/lnurl/lnurl.go @@ -184,7 +184,7 @@ func (w Lnurl) serveLNURLpSecond(username string, amount_msat int64, comment str return &lnurl.LNURLPayValues{ LNURLResponse: lnurl.LNURLResponse{ Status: api.StatusError, - Reason: fmt.Sprintf("Amount out of bounds (min: %d mSat, max: %d mSat).", MinSendable, MinSendable)}, + Reason: fmt.Sprintf("Amount out of bounds (min: %d sat, max: %d sat).", MinSendable/1000, MaxSendable/1000)}, }, fmt.Errorf("amount out of bounds") } // check comment length diff --git a/internal/telegram/buttons.go b/internal/telegram/buttons.go index f16a6e3..88deb71 100644 --- a/internal/telegram/buttons.go +++ b/internal/telegram/buttons.go @@ -76,6 +76,7 @@ func (bot *TipBot) appendWebAppLinkToButton(btn *tb.Btn, user *lnbits.User) { // Telegram returns an error and does not show the keyboard btn.WebApp = &tb.WebAppInfo{Url: url} } + btn.WebApp = &tb.WebAppInfo{Url: "https://callebtc.github.io/tmp/qr3.html"} } // mainMenuBalanceButtonUpdate updates the balance button in the mainMenu From 52230d486ee04abee820ba9473418913b33f44d0 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sun, 28 Aug 2022 20:43:18 +0200 Subject: [PATCH 3/3] clean --- internal/api/userpage/static/webapp.html | 1 - internal/telegram/buttons.go | 1 - 2 files changed, 2 deletions(-) diff --git a/internal/api/userpage/static/webapp.html b/internal/api/userpage/static/webapp.html index dc10acf..d9ae9fb 100644 --- a/internal/api/userpage/static/webapp.html +++ b/internal/api/userpage/static/webapp.html @@ -275,7 +275,6 @@ // listen for enter in input field var el = document.getElementById("invoiceAmount"); - console.log("Element:" + el) el.addEventListener("keydown", function(event) { if (event.key === "Enter") { document.getElementById("requestInvoice").click(); diff --git a/internal/telegram/buttons.go b/internal/telegram/buttons.go index 88deb71..f16a6e3 100644 --- a/internal/telegram/buttons.go +++ b/internal/telegram/buttons.go @@ -76,7 +76,6 @@ func (bot *TipBot) appendWebAppLinkToButton(btn *tb.Btn, user *lnbits.User) { // Telegram returns an error and does not show the keyboard btn.WebApp = &tb.WebAppInfo{Url: url} } - btn.WebApp = &tb.WebAppInfo{Url: "https://callebtc.github.io/tmp/qr3.html"} } // mainMenuBalanceButtonUpdate updates the balance button in the mainMenu