From 0aeec7e488bbdd6049199f6c89195621437d6ffd Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Mon, 29 Aug 2022 02:22:25 +0200 Subject: [PATCH] fiat currencies --- internal/api/userpage/static/webapp.html | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/internal/api/userpage/static/webapp.html b/internal/api/userpage/static/webapp.html index 8a24f31..f0cd961 100644 --- a/internal/api/userpage/static/webapp.html +++ b/internal/api/userpage/static/webapp.html @@ -245,7 +245,7 @@
-
sat
+
@@ -260,6 +260,10 @@ // render the LNURL pay QR code var s = "{{.LNURLPay}}"; + const currencies = ["sat", "USD", "EUR"]; + var currency_idx = 0; + document.getElementById("inputCurrency").innerHTML = currencies[0]; + renderQr(s); // data passed form telegram server @@ -292,6 +296,12 @@ $('#requestInvoice').removeClass('btn-danger').addClass('btn-primary'); }); + var el = document.getElementById("inputCurrency"); + el.addEventListener("click", function(event) { + currency_idx += 1; + $(this).html(currencies[currency_idx%(currencies.length)]); + }); + // ------------------ functions ------------------ function invoiceButtonClick() { @@ -339,8 +349,14 @@ invoiceButtonDisplayError("Invalid") return false; } - console.log("requesting invoice with amount " + invoiceAmount); - fetch(r.callback + '?amount='+ invoiceAmount * 1000).then(data => { + var amountQueryParam; + if (currencies[currency_idx] == "sat") { + amountQueryParam = invoiceAmount * 1000 // sat to msat + } else { + amountQueryParam = invoiceAmount + currencies[currency_idx] + } + console.log("requesting invoice with amount " + amountQueryParam); + fetch(r.callback + '?amount='+ amountQueryParam).then(data => { return data.json(); }) .then(r => { @@ -348,7 +364,7 @@ if (r.status == "OK"){ // update qr code renderQr(r.pr); - document.querySelector('#greeting').innerHTML = "Pay " + invoiceAmount + " sat"; + document.querySelector('#greeting').innerHTML = "Pay " + invoiceAmount + " " + currencies[currency_idx]; } else { invoiceButtonDisplayError("Error") return false;