-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfaucet.html
164 lines (158 loc) · 6.17 KB
/
faucet.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Fusion Testnet Faucet</title>
<!--<link rel="icon" href="./favicon.ico" type="image/x-icon">-->
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-noty/2.4.1/packaged/jquery.noty.packaged.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.0/moment.min.js"></script>
<style>
.vertical-center {
min-height: 100%;
min-height: 100vh;
display: flex;
align-items: center;
}
.progress {
position: relative;
}
.progress span {
position: absolute;
display: block;
width: 100%;
color: white;
}
pre {
padding: 6px;
margin: 0;
}
</style>
</head>
<body>
<div class="vertical-center">
<div class="container">
<div class="row" style="margin-bottom: 16px;">
<div class="col-lg-12">
<h1 style="text-align: center;"><i class="fa fa-bath" aria-hidden="true"></i> Fusion Testnet Faucet</h1>
</div>
</div>
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<div class="input-group">
<input id="address" name="address" type="text" class="form-control" placeholder="Please enter your account.">
<span class="input-group-btn">
<button id="selectCT" class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">FSN</button>
</span>
</div><!--{{if .Recaptcha}}-->
</div>
</div>
<div class="row">
<center><button class="btn btn-default dropdown-toggle" type="button" id="confirm" style="background-color: #46a3ff; width: 140px; margin-top: 20px;" onclick="submit(0)"> Give me FSN </button></center>
</div>
<center>
<div id="txtips" style="height: 50px; margin-top: 10px;">
<span>Please enter your account.</span>
</div>
</center>
</div>
</div>
<script>
// Global variables to hold the current status of the faucet
var server;
var requests = [];
// Define a function that creates closures to drop old requests
var dropper = function(hash) {
return function() {
for (var i=0; i<requests.length; i++) {
if (requests[i].tx.hash == hash) {
requests.splice(i, 1);
break;
}
}
}
};
var selectCointype = function(cointype){
console.log("set cointype "+cointype)
document.getElementById("selectCT").innerHTML = cointype
}
// Define the function that submits a gist url to the server
var submit = function(){
var coinType = document.getElementById("selectCT").innerHTML
console.log(document.getElementById("address").value, coinType)
server.send(JSON.stringify({address:document.getElementById("address").value, cointype: coinType}))
console.log("submit, send")
}
var hidetips = function(){
document.getElementById("txtips").style.color="black"
document.getElementById("txtips").style.opacity="0"
}
// Define a method to reconnect upon server loss
var reconnect = function() {
console.log("connect ..")
//var faucetServerURL = "127.0.0.1:8880/faucet"
var faucetServerURL = "wss.fsn.dev/faucet"
server = new WebSocket(((window.location.protocol === "https:") ? "wss://" : "ws://") + faucetServerURL);
console.log("connected")
console.log("readyState: "+server.readyState)
server.onopen = function() { //test
console.log("server open");
}
server.onmessage = function(event) {
console.log("server onmessage")
console.log("data: "+event.data.toString());
var msg = JSON.parse(event.data);
if (msg.state == "ERR"){
document.getElementById("txtips").style.color="red"
document.getElementById("txtips").style.opacity="1"
document.getElementById("txtips").innerHTML = msg.msg
console.log("mes: "+msg.msg)
setTimeout(hidetips, 3000);
}
if (msg.state == "OK") {
document.getElementById("txtips").style.color="blue"
document.getElementById("txtips").style.opacity="1"
//var addrURL = "https://dcrm.network/explorer/#/blockIndex/accountDtil?params="+document.getElementById('address').value
//document.getElementById("txtips").innerHTML = msg.msg+'<br/>\n'+"Please visit the address for enquiry as follows:"+'<br/>\n'+'<a href="'+addrURL+'">'+addrURL+'</a>'
var txURL = "https://blocks.fusionnetwork.io/#!/transaction/" + msg.txhash
document.getElementById("txtips").innerHTML = msg.msg+'<br/>\n'+"Please visit the transaction as follows:"+'<br/>\n'+'<a href="'+txURL+'">'+txURL+'</a>'
console.log("mes: "+msg.msg+", transaction hash: "+msg.txhash)
}
}
server.onclose = function(event) {
console.log("server closed");
setTimeout(reconnect, 3000);
}
server.onerror = function(event) {
console.log("server error");
}
console.log("server end")
}
// Start a UI updater to push the progress bars forward until they are done
setInterval(function() {
$('.progress-bar').each(function() {
var progress = Number($(this).attr('aria-valuenow')) + 1;
if (progress < 30) {
$(this).attr('aria-valuenow', progress);
$(this).css('width', (progress * 100 / 30) + '%');
} else if (progress == 30) {
$(this).css('width', '100%');
$(this).addClass("progress-bar-danger");
}
})
$('.timer').each(function() {
var index = Number($(this).attr('id').substring(5));
$(this).html(moment.duration(moment(requests[index].time).unix()-moment().unix(), 'seconds').humanize(true));
})
}, 1000);
// Establish a websocket connection to the API server
reconnect();
</script>
</body>
</html>
<!-- vim: set ts=4 sts=4 sw=4 noet : -->