387 lines
12 KiB
HTML
387 lines
12 KiB
HTML
<!-- @format -->
|
|
|
|
{{define "webapp"}}
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport"
|
|
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
|
<meta name="format-detection" content="telephone=no" />
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
<meta name="MobileOptimized" content="176" />
|
|
<meta name="HandheldFriendly" content="True" />
|
|
<meta name="robots" content="noindex,nofollow" />
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
|
|
|
<title>@LightningTipBot</title>
|
|
<script src="https://unpkg.com/kjua@0.6.0/dist/kjua.min.js"></script>
|
|
<script src="https://telegram.org/js/telegram-web-app.js?1"></script>
|
|
<script>
|
|
function setThemeClass() {
|
|
document.documentElement.className = Telegram.WebApp.colorScheme;
|
|
}
|
|
Telegram.WebApp.onEvent('themeChanged', setThemeClass);
|
|
setThemeClass();
|
|
|
|
</script>
|
|
<style>
|
|
body {
|
|
font-family: sans-serif;
|
|
background-color: var(--tg-theme-bg-color, #ffffff);
|
|
color: var(--tg-theme-text-color, #222222);
|
|
font-size: 16px;
|
|
margin: 0;
|
|
padding: 0;
|
|
color-scheme: var(--tg-color-scheme);
|
|
}
|
|
|
|
a {
|
|
color: var(--tg-theme-link-color, #2678b6);
|
|
}
|
|
|
|
button {
|
|
display: block;
|
|
width: 100%;
|
|
font-size: 14px;
|
|
border: none;
|
|
background-color: var(--tg-theme-button-color, #50a8eb);
|
|
color: var(--tg-theme-button-text-color, #ffffff);
|
|
cursor: pointer;
|
|
}
|
|
|
|
.btn-primary {
|
|
background-color: var(--tg-theme-button-color, #50a8eb);
|
|
color: var(--tg-theme-button-text-color, #ffffff);
|
|
}
|
|
|
|
button[disabled] {
|
|
opacity: 0.6;
|
|
cursor: auto;
|
|
pointer-events: none;
|
|
}
|
|
|
|
input {
|
|
font-size: 14px;
|
|
text-align: center;
|
|
border: none;
|
|
background-color: var(--tg-theme-bg-color, #f5f5f5) !important;
|
|
color: var(--tg-theme-text-color, #1a1a1a) !important;
|
|
}
|
|
|
|
.input-group-text {
|
|
background-color: var(--tg-theme-bg-color, #f5f5f5) !important;
|
|
color: var(--tg-theme-text-color, #1a1a1a) !important;
|
|
}
|
|
|
|
section {
|
|
padding: 5px 5px 65px;
|
|
text-align: center;
|
|
}
|
|
|
|
p {
|
|
margin: 40px 0 15px;
|
|
}
|
|
|
|
ul {
|
|
text-align: left;
|
|
}
|
|
|
|
li {
|
|
color: var(--tg-theme-hint-color, #a8a8a8);
|
|
}
|
|
|
|
textarea {
|
|
width: 100%;
|
|
box-sizing: border-box;
|
|
padding: 7px;
|
|
}
|
|
|
|
pre {
|
|
background: rgba(0, 0, 0, .07);
|
|
border-radius: 4px;
|
|
padding: 4px;
|
|
margin: 7px 0;
|
|
word-break: break-all;
|
|
word-break: break-word;
|
|
white-space: pre-wrap;
|
|
text-align: left;
|
|
}
|
|
|
|
.dark pre {
|
|
background: rgba(255, 255, 255, .15);
|
|
}
|
|
|
|
.hint {
|
|
font-size: .8em;
|
|
color: var(--tg-theme-hint-color, #a8a8a8);
|
|
}
|
|
|
|
.ok {
|
|
color: green;
|
|
}
|
|
|
|
.err {
|
|
color: red;
|
|
}
|
|
|
|
#fixed_wrap {
|
|
position: fixed;
|
|
left: 0;
|
|
right: 0;
|
|
top: 0;
|
|
transform: translateY(100vh);
|
|
}
|
|
|
|
.viewport_border,
|
|
.viewport_stable_border {
|
|
position: fixed;
|
|
left: 0;
|
|
right: 0;
|
|
top: 0;
|
|
height: var(--tg-viewport-height, 100vh);
|
|
pointer-events: none;
|
|
}
|
|
|
|
.viewport_stable_border {
|
|
height: var(--tg-viewport-stable-height, 100vh);
|
|
}
|
|
|
|
.viewport_border:before,
|
|
.viewport_stable_border:before {
|
|
content: attr(text);
|
|
display: inline-block;
|
|
position: absolute;
|
|
background: gray;
|
|
right: 0;
|
|
top: 0;
|
|
font-size: 7px;
|
|
padding: 2px 4px;
|
|
vertical-align: top;
|
|
}
|
|
|
|
.viewport_stable_border:before {
|
|
background: green;
|
|
left: 0;
|
|
right: auto;
|
|
}
|
|
|
|
.viewport_border:after,
|
|
.viewport_stable_border:after {
|
|
content: '';
|
|
display: block;
|
|
position: absolute;
|
|
left: 0;
|
|
right: 0;
|
|
top: 0;
|
|
bottom: 0;
|
|
border: 2px dashed gray;
|
|
}
|
|
|
|
.viewport_stable_border:after {
|
|
border-color: green;
|
|
}
|
|
|
|
small {
|
|
font-size: 12px;
|
|
}
|
|
|
|
h1 {
|
|
font-size: 120%;
|
|
word-wrap: break-word;
|
|
margin: 0.5em;
|
|
}
|
|
|
|
.qr-container {
|
|
position: relative;
|
|
display: flex;
|
|
flex-direction: column;
|
|
height: 100%;
|
|
width: 100%;
|
|
}
|
|
|
|
.qr {
|
|
display: flex;
|
|
justify-content: center;
|
|
margin: 0px;
|
|
background-size: contain;
|
|
background-repeat: no-repeat;
|
|
background-position: center;
|
|
}
|
|
|
|
.qr > canvas {
|
|
max-height: 800px;
|
|
max-width: 800px;
|
|
width: 100% !important;
|
|
height: 100% !important;
|
|
}
|
|
|
|
.wrapper {
|
|
display: grid;
|
|
grid-template-columns: 3fr 2fr;
|
|
padding: 12px 20px;
|
|
column-gap: 10px;
|
|
row-gap: 1em;
|
|
align-items: center;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<section>
|
|
<h1 id="greeting"></h1>
|
|
|
|
<div class="qr-container">
|
|
<div class="qr" id="qr">
|
|
</div>
|
|
</div>
|
|
|
|
<div id="buttons">
|
|
<!-- <button onclick="webviewClose();">Close</button> -->
|
|
<div class="wrapper">
|
|
<label class="sr-only" for="inlineFormInputGroup">Username</label>
|
|
<div class="input-group">
|
|
<input type="number" class="form-control" min="1" inputmode="numeric" pattern="[0-9]*" id="invoiceAmount" placeholder="amount">
|
|
<div class="input-group-append">
|
|
<div class="input-group-text" id="inputCurrency"></div>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<button class="btn btn-primary" onclick="invoiceButtonClick();" style="display: inline;" id="requestInvoice">Invoice</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<script type="application/javascript">
|
|
Telegram.WebApp.ready();
|
|
|
|
// 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
|
|
const initData = Telegram.WebApp.initData || '';
|
|
const initDataUnsafe = Telegram.WebApp.initDataUnsafe || {};
|
|
|
|
document.querySelector('#greeting').innerHTML = "{{.Username}}@ln.tips";
|
|
// document.querySelector('#initData').innerHTML = JSON.stringify(initData, null, 2);
|
|
// document.querySelector('#initDataUnsafe').innerHTML = JSON.stringify(initDataUnsafe, null, 2);
|
|
|
|
// react to theme changes
|
|
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");
|
|
el.addEventListener("keydown", function(event) {
|
|
if (event.key === "Enter") {
|
|
document.getElementById("requestInvoice").click();
|
|
}
|
|
document.getElementById("requestInvoice").innerHTML = "Invoice"
|
|
// revert color of button
|
|
$('#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)]);
|
|
$('#requestInvoice').removeClass('btn-danger').addClass('btn-primary');
|
|
});
|
|
|
|
// ------------------ functions ------------------
|
|
|
|
function invoiceButtonClick() {
|
|
var c = "{{.Callback}}";
|
|
getInvoice(this, c);
|
|
// hide keyboard and scroll up
|
|
document.getElementById("invoiceAmount").blur();
|
|
window.scrollTo(0, 0);
|
|
}
|
|
|
|
function invoiceButtonDisplayError(message) {
|
|
btn = document.getElementById("requestInvoice")
|
|
btn.innerHTML = message
|
|
// update color of button
|
|
$('#requestInvoice').removeClass('btn-primary').addClass('btn-danger');
|
|
}
|
|
|
|
function webviewClose() {
|
|
Telegram.WebApp.close();
|
|
}
|
|
|
|
function renderQr(payload) {
|
|
const qr = document.getElementById('qr');
|
|
qr.innerHTML = '';
|
|
if ( qr ) {
|
|
const qrGfx = kjua({
|
|
text: payload,
|
|
rounded: 50,
|
|
size: 500,
|
|
render: 'canvas',
|
|
});
|
|
qr.appendChild( qrGfx );
|
|
// var href_link = "lightning:" + payload;
|
|
// qr.setAttribute('href', "javascript:window.open('"+ href_link+ "');" );
|
|
}
|
|
}
|
|
|
|
function getInvoice(el, callback) {
|
|
curr_idx = currency_idx%currencies.length
|
|
var invoiceAmount = Number(document.getElementById("invoiceAmount").value);
|
|
if ((currencies[curr_idx] == "sat" && !Number.isInteger(invoiceAmount)) || invoiceAmount < 1) {
|
|
invoiceButtonDisplayError("Invalid")
|
|
return false;
|
|
}
|
|
var amountQueryParam;
|
|
if (currencies[curr_idx] == "sat") {
|
|
amountQueryParam = invoiceAmount * 1000 // sat to msat
|
|
} else {
|
|
amountQueryParam = invoiceAmount + currencies[curr_idx]
|
|
}
|
|
fetch(callback)
|
|
.then(data => {
|
|
return data.json();
|
|
})
|
|
.then(r => {
|
|
console.log(r);
|
|
console.log("requesting invoice with amount " + amountQueryParam);
|
|
fetch(r.callback + '?amount='+ amountQueryParam).then(data => {
|
|
return data.json();
|
|
})
|
|
.then(r => {
|
|
console.log(r);
|
|
if (r.status == "OK"){
|
|
// update qr code
|
|
renderQr(r.pr);
|
|
document.querySelector('#greeting').innerHTML = "Pay " + invoiceAmount + " " + currencies[curr_idx];
|
|
} else {
|
|
invoiceButtonDisplayError("Error")
|
|
return false;
|
|
}
|
|
|
|
})
|
|
})
|
|
}
|
|
</script>
|
|
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
|
|
</body>
|
|
</html>
|
|
|
|
{{end}} |