forked from nicolas-van/bootstrap-4-github-pages
-
Notifications
You must be signed in to change notification settings - Fork 1
/
e.html
94 lines (88 loc) · 3.86 KB
/
e.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
<!DOCTYPE html>
<html>
<head>
<meta name="robots" content="noindex">
<link rel="stylesheet" href="/assets/main.css">
</head>
<body style="background:transparent;overflow:hidden">
<div id="donatebutton.cash" class="h-100">
<button id="button" class="btn btn-primary btn-block" onclick="listen();$(this).slideUp();buttonQrCard.slideDown()" style="white-space:nowrap">
<img src="/assets/images/BCH_inverted.svg" class="img-fluid mr-1" alt="Donate Bitcoin Cash" style="height:23px">
<span id="button_label">Donate</span>
</button>
<div id="button_qr_card" class="card border-primary h-100" style="display:none;overflow:hidden">
<div class="card-body p-0 text-center justify-content-center align-items-center d-flex" style="height:112px">
<a id="payment_uri" class="w-100" href="//">
<div id="button_qr" class="img-fluid w-100"></div>
</a>
<div id="button_qr_thank_you" class="text-success small px-2 font-weight-bold align-self-center" style="display:none">
<span id="button_qr_received_amount">Payment</span> received. Thank you!
</div>
</div>
<a href="javascript:" onclick="navigator.clipboard.writeText(addr);buttonQrFooterText.html('Copied ┗(°0°)┛');">
<div class="card-footer p-1 bg-primary text-white text-center small">
<span id="button_qr_footer_text">Copy BCH address</span>
</div>
</a>
</div>
</div>
</body>
</html>
<script src="/assets/javascript/bootstrap/jquery.min.js"></script>
<script src="/assets/javascript/bootstrap/bootstrap.bundle.min.js"></script>
<script src="/assets/javascript/jquery-qrcode.min.js"></script>
<script>
// params
let addr = new URLSearchParams(window.location.search).get('a');
let btnLabel = new URLSearchParams(window.location.search).get('l');
let paymentUri = "bitcoincash:" + addr;
// elements
let button = $('#button');
let buttonLabel = $('#button_label');
let buttonQr = $('#button_qr');
let buttonQrThankYou = $('#button_qr_thank_you');
let buttonQrCard = $('#button_qr_card');
let buttonQrReceivedAmount = $('#button_qr_received_amount');
let buttonQrFooterText = $('#button_qr_footer_text');
let buttonQrPaymentUri = $('#payment_uri');
// dom manipulation
buttonQrPaymentUri.attr('href',paymentUri);
buttonQr.qrcode({
text: paymentUri,
render: 'image',
size: 140,
fill: '#5DCB79'
}).find('img').css({height:112,width:'100%'});
if (btnLabel) {
buttonLabel.html(btnLabel);
}
// listen to incoming transactions
function listen() {
let sse = new EventSource("https://bitsocket.bitcoin.com/s/" + btoa(JSON.stringify({v:3,q:{find:{"out.e.a":addr}}})));
sse.onmessage = (event) => {
let data = JSON.parse(event.data);
if (data.type === "mempool") {
// calculate received amount
let received = 0;
for (let i = 0; i < data.data.length; i++) {
for (let j = 0; j < data.data[i].out.length; j++) {
if (data.data[i].out[j].e.a === addr) {
// output address is recipient's address
received = received + data.data[i].out[j].e.v;
}
}
}
received = (received / 100000000).toFixed(8);
buttonQrReceivedAmount.html(received + ' BCH');
// some visual feedback on payment
buttonQrPaymentUri.hide();
buttonQrThankYou.show();
setTimeout(() => {
// show thank you text for 7.5 secs
buttonQrThankYou.hide();
buttonQrPaymentUri.show();
}, 7500);
}
}
}
</script>