-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
91 lines (80 loc) · 3.72 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Faucet</title>
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<script type="text/javascript">
function send() {
var address = document.getElementById("inputAddress").value;
var amount = document.getElementById("inputAmount").value;
var xhr = new XMLHttpRequest();
xhr.onload = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
var data = JSON.parse(xhr.responseText);
if (xhr.status === 200) {
document.getElementById("message").innerHTML = "<div style='color:#008000'>Successfully sent <b>" + amount + "</b> to <b>" + address + "</b></div> <a target='_blank' href='/tx/" + data.result +"'>" + data.result + "</a>";
getBalance();
} else {
document.getElementById("message").innerHTML = "<div style='color:#ff0000'>" + data.error.message + "</div>";
}
}
}
xhr.onerror = function(error) {
console.log("Error: " + error);
document.getElementById("message").innerHTML = "<div style='color:#ff0000'>Failed to send! " + error + "</div>";
}
xhr.open('post', '/bitcoin', true);
const blob = new Blob(['{"jsonrpc": "1.0", "method": "sendtoaddress", "params": ["' + address +'", "'+ amount +'"]}'], { type: "text/plain" });
xhr.setRequestHeader('Content-Type', 'text/plain');
xhr.send(blob);
return false;
}
function getBalance() {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
if (xhr.readyState == XMLHttpRequest.DONE && xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
document.getElementById("balance").innerText = data.result;
}
}
xhr.open('post', '/bitcoin', true);
const blob = new Blob(['{"jsonrpc": "1.0", "method": "getbalance"}'], { type: "text/plain" });
xhr.setRequestHeader('Content-Type', 'text/plain');
xhr.send(blob);
}
function validate() {
var address = document.getElementById("inputAddress").value;
var amount = document.getElementById("inputAmount").value;
document.getElementById('send').disabled = (address == "" || amount == "");
}
</script>
</head>
<body onload="getBalance()">
<div class="px-10 py-5 text-center">
<h1 class="display-5 fw-bold">Faucet</h1>
<div class="col-lg-6 mx-auto">
<p class="lead mb-4">Enter your signet address to receive signet coins.<br/>Faucet balance <b id="balance">0.00</b> btc</p>
<div class="row g-3">
<div class="col-1"></div>
<div class="col-6">
<label for="inputAddress" class="visually-hidden">Address</label>
<input class="form-control" id="inputAddress" placeholder="Addess" onkeyup="validate()">
</div>
<div class="col-3">
<label for="inputAmount" class="visually-hidden">Amount</label>
<input class="form-control" value="0.1" id="inputAmount" placeholder="Amount" onkeyup="validate()">
</div>
<div class="col-auto">
<button id="send" type="submit" class="btn btn-primary mb-3" onclick="send()" disabled>Send</button>
</div>
</div>
</div>
<div class="container">
<p id="message"></p>
</div>
</div>
</body>
</html>