forked from ping-pub/faucet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
202 lines (181 loc) · 7.7 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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<!doctype html>
<html lang="en" data-bs-theme="dark">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Sandbox Faucet</title>
<link rel="icon" href="https://nymtech.net/favicon.png" />
<meta name="robots" content="index, follow">
<meta name="description" content="Faucet to request testnet NYM tokens">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<style>
.bg-custom {
background-color: #1c1c1e;
}
.btn-custom {
background-color: rgb(251, 110, 78);
color: white;
}
.btn-custom:hover {
background-color: rgb(255, 135, 100);
}
.footer-custom {
background-color: #1c1c1e;
color: #6c757d;
}
#health-status {
border-radius: 0.25rem;
padding: 0.5rem 1rem;
z-index: 1050;
}
#health-indicator {
width: 1rem;
height: 1rem;
}
#health-status .text-success {
color: #28a745 !important;
}
#health-status .text-danger {
color: #dc3545 !important;
}
[v-cloak] {
display: none;
}
</style>
</head>
<body class="bg-custom text-light">
<div id="app">
<main class="container-md">
<div id="health-status" class="position-fixed top-0 end-0 p-3">
<div class="d-flex align-items-center">
<div id="health-indicator" class="spinner-border text-light" role="status"></div>
<span id="health-text" class="ms-2">Checking faucet health...</span>
</div>
</div>
<div class="py-5 text-center">
<img style="width: 10%; height: 10%" id="logo" class="d-block mx-auto mb-4" :src="logo"
:alt="`${testnet} Faucet`">
<h1><span v-cloak id="testnet">{{ testnet }}</span> Faucet</h1>
<p class="lead mt-5">
Ready to begin your testnet journey? ✨ <br /><br />
You can request <span v-cloak style="color: rgb(251, 110, 78)">{{ amount }} {{ denom }} </span> tokens
by submitting your wallet address below
</p>
</div>
<div class="row g-5 justify-content-center">
<div class="col-md-6">
<div class="input-group">
<input id="address" class="form-control" :placeholder="placeholder" v-model="address" name="address"
@input="validateAddress" :class="{'is-invalid': !isValidAddress}">
<button id="request-button" type="button" class="btn btn-custom d-flex align-items-center"
@click="requestToken(this)" :disabled="!isValidAddress || !isFaucetHealthy">
<span id="button-loading" class="spinner-border spinner-border-sm me-2" style="display:none" role="status"
aria-hidden="true"></span>
<span v-cloak>Request {{ denom }}</span>
</button>
</div>
<div id="message" class="mt-3 justify-content-center" v-html="message"></div>
</div>
</div>
</main>
<footer class="footer-custom text-center py-3 fixed-bottom">
<p class="mb-1">A fork of <a href="https://github.com/ping-pub/faucet" class="text-muted">ping.pub faucet</a></p>
</footer>
</div>
<script type="module">
import { createApp } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js'
createApp({
data() {
return {
message: '',
testnet: 'Nym Sandbox',
logo: 'https://raw.githubusercontent.com/cosmos/chain-registry/master/nyx/images/nym_token_dark.png',
placeholder: 'Input an address to request token',
amount: 101,
denom: "NYM",
address: "",
txendpoint: "",
isValidAddress: false,
isFaucetHealthy: false
}
},
created() {
console.log(this)
fetch("/faucet/config").then(response => response.json()).then(data => {
this.testnet = data.name;
this.logo = data.logo;
this.txendpoint = data.tx_endpoint;
this.placeholder = "Enter your n1xxx.. wallet address";
this.amount = data.amount;
this.denom = data.denom;
});
// Perform health check
this.checkFaucetHealth();
},
methods: {
validateAddress() {
const addressRegex = /^[a-z0-9]{1,}1[ac-hj-np-z02-9]{38}$/i;
this.isValidAddress = addressRegex.test(this.address);
},
requestToken(obj) {
if (this.address && this.isValidAddress) {
document.getElementById("request-button").disabled = true;
document.getElementById("button-loading").style.display = 'block';
// Reset message before making the request
this.message = '';
fetch(`/send/${this.address}`)
.then(response => response.json())
.then(data => {
const dataLength = data.result ? data.result.length : 0;
document.getElementById("button-loading").style.display = 'none';
this.message = `
<div class="alert alert-${dataLength === 64 ? 'success' : 'danger'} alert-dismissible fade show mt-2" role="alert">
${dataLength === 64 ? `Success! ${this.amount} ${this.denom} tokens <a class="alert-link" target="_blank" href="${this.txendpoint}${data.result}">sent</a> to your wallet address 🎉` : `Failed : ${data.result}`}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
`;
});
} else {
this.message = '<span class="text-danger">Invalid address input</span>';
}
},
checkFaucetHealth() {
fetch('/faucet/health')
.then(response => response.json())
.then(data => {
const healthStatus = data.status === 'ok';
const healthText = healthStatus ? 'Faucet is healthy' : (data.status === 'insufficient_funds' ? 'Faucet is low on tokens' : 'Faucet error');
const healthColor = healthStatus ? 'text-success' : 'text-danger';
this.isFaucetHealthy = healthStatus
const healthIndicator = document.getElementById("health-indicator");
const healthTextElement = document.getElementById("health-text");
// Remove spinner and update indicator color
healthIndicator.classList.remove('spinner-border');
healthIndicator.classList.add(healthColor);
// Update health text
healthTextElement.textContent = healthText;
healthTextElement.classList.add(healthColor);
if (healthStatus && this.isValidAddress) {
document.getElementById("request-button").disabled = false;
}
})
.catch(error => {
const healthTextElement = document.getElementById("health-text");
healthTextElement.textContent = 'Error checking faucet health';
healthTextElement.classList.add('text-danger');
console.error('Error checking faucet health:', error);
// Remove spinner and show error indicator
const healthIndicator = document.getElementById("health-indicator");
healthIndicator.classList.remove('spinner-border');
healthIndicator.classList.add('text-danger');
});
}
}
}).mount('#app')
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
crossorigin="anonymous"></script>
</body>
</html>