This repository has been archived by the owner on Feb 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
playground.html
269 lines (257 loc) · 10.1 KB
/
playground.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<!DOCTYPE html>
<html lang="en">
<head>
<title>MetaHash JavaScript playground</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<style>
body {
margin-bottom: 60px;
}
html {
position: relative;
min-height: 100%;
}
.navbar-brand {
font-weight: bold;
padding: 0;
}
.navbar-brand img {
position: relative;
top: 7px;
height: 16px;
}
footer {
position: absolute;
bottom: 0;
width: 100%;
height: 60px;
line-height: 60px;
background-color: #f5f5f5;
text-align: center;
}
.navbar li {
margin: 0 20px;
}
.card-body {
padding-bottom: 0;
}
#network-form {
margin-right: -30px;
}
</style>
</head>
<body>
<header>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container">
<a class="navbar-brand" href="# ">
<img src="https://static.metahash.org/img/logo_mail.svg" class="d-inline-block align-top" alt="MegaHash"> JavaScript playground
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" target="_blank" href="https://github.com/epexa/metahash-js">JavaScript library</a>
</li>
<li class="nav-item">
<a class="nav-link" target="_blank" href="https://developers.metahash.org/hc/en-us/sections/360000600513-General">Documentation</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0 col-sm-5" id="network-form">
<div class="col-sm-12">
<div class="input-group input-group-sm">
<input type="text" class="form-control" name="ip-address" placeholder="API URL">
<div class="input-group-append">
<button class="btn btn-warning btn-sm" id="node-address-modal-btn" type="button"><span class="icon-database"></span> Change</button>
</div>
</div>
</div>
</form>
</div>
</div>
</nav>
</header>
<article>
<main role="main" class="container">
<br>
<div class="row">
<div class="col">
<div class="card">
<div class="card-body">
<form id="fetch-balance-form">
<fieldset>
<div class="row">
<div class="col">
<h5 class="card-title"><a target="_blank" href="https://github.com/epexa/metahash-js#fetchbalance">fetchBalance</a></h5>
<h6 class="card-subtitle mb-2 text-muted">get balance information for address</h6>
<br>
<div class="form-group">
<label for="fetch-balance-address">Address:</label>
<input type="text" class="form-control" name="address" id="fetch-balance-address" placeholder="0x009b84f533aa2192456a7e944eb471183abbceafe678a98984" required>
<small class="form-text text-muted">Example: 0x009b84f533aa2192456a7e944eb471183abbceafe678a98984</small>
</div>
<div class="form-group">
<button class="btn btn-success" type="submit">Send request</button>
<a class="btn btn-info explorer-btn" target="_blank" href="">Open in explorer</a>
<button class="btn btn-danger clear-btn" type="button">Clear</button>
</div>
</div>
<div class="col">
<div class="form-group">
<label>Result:</label>
<textarea class="form-control" name="log" rows="7" readonly></textarea>
</div>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col">
<div class="card">
<div class="card-body">
<form id="fetch-history-form">
<fieldset>
<div class="row">
<div class="col">
<h5 class="card-title"><a target="_blank" href="https://github.com/epexa/metahash-js#fetchhistory">fetchHistory</a></h5>
<h6 class="card-subtitle mb-2 text-muted">get history transactions for address</h6>
<br>
<div class="form-group">
<label for="fetch-balance-address">Address:</label>
<input type="text" class="form-control" name="address" id="fetch-balance-address" placeholder="0x009b84f533aa2192456a7e944eb471183abbceafe678a98984" required>
<small class="form-text text-muted">Example: 0x009b84f533aa2192456a7e944eb471183abbceafe678a98984</small>
</div>
<div class="form-group">
<button class="btn btn-success" type="submit">Send request</button>
<a class="btn btn-info explorer-btn" target="_blank" href="#">Open in explorer</a>
<button class="btn btn-danger clear-btn" type="button">Clear</button>
</div>
</div>
<div class="col">
<div class="form-group">
<label>Result:</label>
<textarea class="form-control" name="log" rows="7" readonly></textarea>
</div>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col">
<div class="card">
<div class="card-body">
<form id="get-tx-form">
<fieldset>
<div class="row">
<div class="col">
<h5 class="card-title"><a target="_blank" href="https://github.com/epexa/metahash-js#fetchhistory">getTx</a></h5>
<h6 class="card-subtitle mb-2 text-muted">get transaction information by hash</h6>
<br>
<div class="form-group">
<label for="get-tx-hash">Hash:</label>
<input type="text" class="form-control" name="hash" id="get-tx-hash" placeholder="2af70ff53c2f6e3d28aea8ee4fb566e41fdb2e4ed061ab7ca7989bd4f4a681ab" required>
<small class="form-text text-muted">Example: 2af70ff53c2f6e3d28aea8ee4fb566e41fdb2e4ed061ab7ca7989bd4f4a681ab</small>
</div>
<div class="form-group">
<button class="btn btn-success" type="submit">Send request</button>
<a class="btn btn-info explorer-btn" target="_blank" href="#">Open in explorer</a>
<button class="btn btn-danger clear-btn" type="button">Clear</button>
</div>
</div>
<div class="col">
<div class="form-group">
<label>Result:</label>
<textarea class="form-control" name="log" rows="7" readonly></textarea>
</div>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
</div>
</main>
</article>
<br>
<footer class="footer">
<div class="container-fluid">
<span class="text-muted">MetaHash @ 2018</span>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/bootstrap-native-v4.min.js"></script>
<script src="metahash.min.js"></script>
<script>
const camelCase = (str) => {
str = str.replace(/[=\[\]"]/g, ' ').replace(/ +/g, ' ').replace(/[#\.]/g, '');
str = str.replace(/-([a-z])/g, (_m, l) => {
return l.toUpperCase();
});
return str.replace(/ ([a-z])/g, (_m, l) => {
return l.toUpperCase();
});
}
const initHtmlElements = ($htmlElements) => {
for (let name in $htmlElements) {
let nameConst = $htmlElements[name];
nameConst = camelCase(nameConst);
eval(`window.$${nameConst} = document.querySelector('${$htmlElements[name]}');`);
}
};
initHtmlElements([ '#network-form', '#network-form input[name="ip-address"]', '#fetch-balance-form', '#fetch-balance-form fieldset', '#fetch-balance-form input[name="address"]', '#fetch-balance-form textarea[name="log"]' , '#fetch-balance-form a[class="btn btn-info explorer-btn"]', '#fetch-history-form', '#fetch-history-form fieldset', '#fetch-history-form input[name="address"]', '#fetch-history-form textarea[name="log"]' , '#fetch-history-form a[class="btn btn-info explorer-btn"]', '#get-tx-form', '#get-tx-form fieldset', '#get-tx-form input[name="hash"]', '#get-tx-form textarea[name="log"]' , '#get-tx-form a[class="btn btn-info explorer-btn"]' ]);
//metahash.apiUrl = 'http://172.104.224.65:5795'; // net-dev
$networkFormInputNameIpAddress.value = metahash.apiUrl;
explorerUrl = 'http://mhscan.com/';
$fetchBalanceForm.addEventListener('submit', (e) => {
e.preventDefault();
metahash.apiUrl = 'http://172.104.224.65:5795';
metahash.fetchBalance($fetchBalanceFormInputNameAddress.value, (res, err) => {
if (res) {
console.log('fetchBalance', res);
$fetchBalanceFormTextareaNameLog.value = JSON.stringify(res);
$fetchBalanceFormAClassBtnBtnInfoExplorerBtn.href = explorerUrl + '?page=address&id=' + $fetchBalanceFormInputNameAddress.value;
}
else console.error('fetchBalance', err)
});
});
$fetchHistoryForm.addEventListener('submit', (e) => {
e.preventDefault();
metahash.apiUrl = 'http://172.104.224.65:5795';
metahash.fetchHistory($fetchHistoryFormInputNameAddress.value, (res, err) => {
if (res) {
console.log('fetchHistory', res);
$fetchHistoryFormTextareaNameLog.value = JSON.stringify(res);
$fetchHistoryFormAClassBtnBtnInfoExplorerBtn.href = explorerUrl + '?page=address&id=' + $fetchHistoryFormInputNameAddress.value;
}
else console.error('fetchHistory', err)
});
});
$getTxForm.addEventListener('submit', (e) => {
e.preventDefault();
metahash.apiUrl = 'http://172.104.224.65:5795';
metahash.getTx($getTxFormInputNameHash.value, (res, err) => {
if (res) {
console.log('getTx', res);
$getTxFormTextareaNameLog.value = JSON.stringify(res);
$getTxFormAClassBtnBtnInfoExplorerBtn.href = explorerUrl + '?page=tx&id=' + $getTxFormInputNameHash.value;
}
else console.error('getTx', err)
});
});
</script>
</body>
</html>