This commit is contained in:
callebtc 2022-08-28 20:37:45 +02:00
parent 6a01936c2e
commit c8e45de27d
3 changed files with 41 additions and 13 deletions

View file

@ -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;
}
</style>
</head>
@ -233,10 +236,10 @@
<!-- <button onclick="webviewClose();">Close</button> -->
<div class="wrapper">
<div>
<input type="number" id="invoiceAmount" placeholder="1000 sat"></input>
<input type="number" id="invoiceAmount" placeholder="amount in sat" style="width: 80%"></input>
</div>
<div>
<button onclick="getInvoice(this, {{.Callback}});" style="display: inline; margin: 0px;">Invoice</button>
<button onclick="getInvoice(this, {{.Callback}});" style="display: inline;" id="requestInvoice">Invoice</button>
</div>
</div>
</div>
@ -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"
}
})
})
}

View file

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

View file

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