/
index.html
117 lines (109 loc) · 4.61 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Johoe's Lightning Donation Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style.css" rel="stylesheet" type="text/css"/>
<script src="qrcodegen.min.js"></script>
</head>
<body onload="loadDoc()">
<div class="tab">
<button class="tablinks" onclick="selectTab(event, 'channel')">Open Channel</button>
<button id="defaulttab" class="tablinks" onclick="selectTab(event, 'invoice')">Payment Request</button>
</div>
<div id="channel" class="tabcontent" onclick="copyclipboard('textnode')">
<p>Scan this QRCode to open a channel to my node. Click to copy to clipboard.</p>
<div class="lncontainer"><canvas id="qrnode" class="lnqrcode"></canvas></div>
<textarea id="textnode" class="lntext" rows="2"></textarea>
</div>
<div id="invoice" class="tabcontent">
<p>Scan or click this QRCode to start a payment.</p>
<div class="lncontainer">
<a id="qrlink" href="#"><canvas id="qrinvoice" class="lnqrcode"></canvas></a>
<div id="qrpayed" class="lnsettled">PAID<br/>Thank You</div>
</div>
<textarea id="textinvoice" rows="5" class="lntext"></textarea>
<input type="button" value="Copy to Clipboard"
onclick="copyclipboard('textinvoice')"/>
</div>
<script>
var border = 4;
var scale = 4;
var uri = "0358327cb80ab2a8db36a5924c62966c7b4a753045600df594aa3863ecb618cc5d@37.221.198.57:9735";
var qruri = qrcodegen.QrCode.encodeText(uri.toUpperCase(), qrcodegen.QrCode.Ecc.MEDIUM);
qruri.drawCanvas(scale, border, document.getElementById("qrnode"));
document.getElementById("textnode").value = uri;
function waitfor(rhash) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4) {
if (this.status == 200) {
var response = JSON.parse(this.responseText);
if (!response.settled) {
waitfor(rhash);
} else {
document.getElementById("qrinvoice").style.opacity = 0.2;
document.getElementById("qrpayed").style.display = "block";
}
} else if (this.status != 0) {
alert("Cannot check payment status: "+ this.status + " state: "+this.readyState+"text: "+this.responseText);
}
}
}
xhttp.open("POST", "/lnd/check-invoice.py?r_hash="+rhash, true);
xhttp.send();
}
function loadDoc() {
var xhttp = new XMLHttpRequest();
function handleInvoice(invoice) {
rhash = invoice.r_hash;
paymentrequest = invoice.payment_request;
var qrcode = qrcodegen.QrCode.encodeText(paymentrequest.toUpperCase(), qrcodegen.QrCode.Ecc.LOW);
qrcode.drawCanvas(scale, border, document.getElementById("qrinvoice"));
document.getElementById("qrlink").href = "lightning:" + paymentrequest;
document.getElementById("textinvoice").value = paymentrequest;
waitfor(rhash);
}
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {
handleInvoice(JSON.parse(this.responseText));
} else {
document.getElementById("textinvoice").value = "Failed to get payment request";
}
}
}
xhttp.open("POST", "/lnd/invoice-mp.py", true);
xhttp.send();
}
function selectTab(evt, name) {
// Declare all variables
var i, tabcontent, tablinks;
// Get all elements with class="tabcontent" and hide them
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
// Get all elements with class="tablinks" and remove the class "active"
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
// Show the current tab, and add an "active" class to the button that opened the tab
document.getElementById(name).style.display = "block";
evt.currentTarget.className += " active";
}
function copyclipboard(id) {
var copyText = document.getElementById(id);
copyText.select();
document.execCommand("copy");
}
document.getElementById("defaulttab").click();
</script>
<div class="centered" style="font-size: 13px; margin: 20px;">
Source code on github: <a href="https://github.com/jhoenicke/mempool/tree/master/web/lightning/" target="_blank">https://github.com/jhoenicke/mempool</a><br/>
© 2018 <a href="https://jochen-hoenicke.de/">Jochen Hoenicke</a>
</div>
</body>
</html>