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] 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