-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.html
144 lines (131 loc) · 4.9 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.6.2/css/bulma.min.css" />
<title>Faucet ERC20</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="container is-fluid">
<section class="hero is-dark is-fullheight">
<div class="hero-body">
<div class="container">
<h1 class="title">
ERC20 automated faucet
</h1>
<h3 id="subtitle" style="display: none">
You need a github account to get your AGI
</h3>
<br />
<p>
<a href="https://github.com/vulpemventures/faucet-erc20/blob/master/README.md" target="_blank">
<strong>README</strong>
</a>
</p>
<br />
<ul style="list-style: none;">
<li>Network
<b>Kovan</b>
</li>
<li> Token
<a href="https://kovan.etherscan.io/token/0x3b226ff6aad7851d3263e53cb7688d13a07f6e81#readContract">
<b>SingularityNET</b>
</a>
</li>
<li>Symbol
<b>AGI</b>
</li>
<li>Decimals
<b>8</b>
</li>
</ul>
<br />
<div class="field">
<div id="control" class="control" style="display: none">
<input class="input" id="input" type="text" style="width: 360px" placeholder="Enter your ETH address">
<button id="button" class="button is-primary" onClick="sendRequest()">
Submit
</button>
</div>
<button class="button" id="login" style="display: none" onClick="githubLogin()">
Login with Github
</button>
</div>
<div id="notification" class="notification is-success" style="display:none">
</div>
<div id="error" class="notification is-danger" style="display:none">
</div>
</div>
</div>
</section>
</div>
<script>
const BASE_URI = "https://nd9vvrqz39.execute-api.eu-west-1.amazonaws.com/production"
// const BASE_URI = "https://jmtb0drpvb.execute-api.eu-west-1.amazonaws.com/staging"
window.onload = function () {
if (location.search !== "") {
document.getElementById("control").style.display = "block"
} else {
document.getElementById("login").style.display = "block"
document.getElementById("subtitle").style.display = "block"
}
}
function githubLogin() {
const xhr = new XMLHttpRequest()
xhr.open("GET", BASE_URI + "/appId")
xhr.onload = function (e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
window.location.href = "https://github.com/login/oauth/authorize?client_id=" + JSON.parse(xhr.response).clientId
} else {
const error = document.getElementById("error")
error.style.display = 'block'
error.innerText = "Something went wrong! Reason: " + xhr.responseText
}
}
}
xhr.send()
}
function sendRequest() {
const button = document.getElementById("button"),
address = document.getElementById("input"),
error = document.getElementById("error"),
notification = document.getElementById("notification")
error.style.display = "none"
notification.style.display = "none"
button.setAttribute("disabled", "disabled")
if (address.value !== "" && address.value.length === 42) {
button.innerText = "Loading.."
const xhr = new XMLHttpRequest()
xhr.open("POST", `${BASE_URI}/agi/${location.search.split("=")[1]}/${address.value}`)
xhr.onload = function (e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
const response = JSON.parse(xhr.response).result,
txHash = response.transactionHash || ""
notification.style.display = "block"
notification.innerHTML = `<p>Success! <br /> Tx Hash: <a href="https://kovan.etherscan.io/tx/${txHash}" target="_blank">${txHash}</a></p>`
} else {
const reason = JSON.parse(xhr.response)
error.style.display = "block"
error.innerHTML = "Something went wrong! Reason: " + (reason.message || reason.error_description)
}
button.innerText = "Submit"
button.removeAttribute("disabled")
}
}
xhr.send()
} else {
error.style.display = "block"
button.removeAttribute("disabled")
error.innerHTML = "Insert a valid address"
}
}
</script>
</body>
</html>