generated from electron/electron-quick-start
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.html
321 lines (286 loc) · 13.2 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
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ZENZO Forge</title>
</head>
<style>
.sidenav {
height: 100%;
width: 160px;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-image: linear-gradient(180deg, #8678dc, #48dfe1);
overflow-x: hidden;
padding-top: 20px;
font-weight: bold;
}
.sidenav a {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 25px;
color: white;
display: block;
}
.sidenav a:hover {
color: #f1f1f1;
}
</style>
<body style="
margin: 0;
height: 100%;
padding: 0;
background-color: white;
overflow-x: hidden;
overflow-y: auto;
color: black;
font-family: helvetica;">
<div class="sidenav">
<a onclick="openProfile();" style="cursor: pointer;">Profile</a>
<a onclick="openWallet();" style="cursor: pointer;">Wallet</a>
<a onclick="openInventory();" style="cursor: pointer;">Inventory</a>
</div>
<script>
function openWallet() {
document.getElementById("wallet").style.display = "block";
document.getElementById("inventory").style.display = "none";
document.getElementById("new_profile").style.display = "none";
document.getElementById("profile").style.display = "none";
}
function openInventory() {
document.getElementById("wallet").style.display = "none";
document.getElementById("inventory").style.display = "block";
document.getElementById("new_profile").style.display = "none";
document.getElementById("profile").style.display = "none";
}
function openProfile() {
loadProfile().then(hasProfile => {
console.info(hasProfile)
if (hasProfile) {
document.getElementById("wallet").style.display = "none";
document.getElementById("inventory").style.display = "none";
document.getElementById("new_profile").style.display = "none";
document.getElementById("profile").style.display = "block";
} else {
document.getElementById("wallet").style.display = "none";
document.getElementById("inventory").style.display = "none";
document.getElementById("new_profile").style.display = "block";
document.getElementById("profile").style.display = "none";
}
})
}
</script>
<div id="inventory" style="
height: 100vh;
background-color: white;
margin-left: 160px;
display: none;">
<h1 style="text-align: center;font-family: helvetica;margin-top: 0;padding-top: 25px;">ZENZO Forge Inventory</h1>
<p style="text-align: center;font-family: helvetica;">Peers: <b id="peerCount">Offline (No peers connected)</b></p>
<br>
<span id="items"></span>
<div style="text-align: center;margin-top: 50px;">
<h2>Create a Decentralized ZNZ-Backed Asset</h2>
<p>Name: </p><input id="new_item_name" type="text">
<p>Value: </p><input id="new_item_value" type="number">
<br>
<input type="button" value="Craft" onclick="craftItem()">
</div>
<!-- FORGE LIBRARY GOES BELOW -->
<script src="./index.js"></script>
<!-- FORGE LIBRARY GOES ABOVE -->
<script>
function craftItem() {
if (peers.length === 0) return;
let nName = document.getElementById("new_item_name").value;
let nValue = Number(document.getElementById("new_item_value").value);
craftForgeItem(nName, nValue);
}
function craftForgeItem (name, value) {
superagent
.post('http://127.0.0.1:80/forge/create')
.send({ amount: value, name: name, auth: authToken})
.end((err, res) => {
console.info(res);
refreshInventory();
});
}
function smeltForgeItem (hash) {
let nItem = getItem(hash);
zenzo.call("signmessage", addy, "smelt_" + nItem.tx).then(sig => {
smeltItem(hash, sig).then(a => {});
});
}
async function getForgeInventory (addr) {
let inv = {items: [], pendingItems: []};
let res = await superagent.post('http://127.0.0.1:80/forge/items');
res = JSON.parse(res.text);
for (let i=0; i<res.items.length; i++) {
if (res.items[i].address === addr) inv.items.push(res.items[i]);
}
for (let i=0; i<res.pendingItems.length; i++) {
if (res.pendingItems[i].address === addr) inv.pendingItems.push(res.pendingItems[i]);
}
return inv;
}
function refreshInventory() {
getForgeInventory(addy).then(inv => {
let itemHTML = "<br>";
for (let i=0; i<inv.items.length; i++) {
itemHTML += '<div style="display: inline-block;border-style: solid;border-width: 2px;border-radius: 7px;padding: 10px;margin: 10px;">' + "<b>Name:<b/> " + inv.items[i].name + '<br><b>Value: </b>' + inv.items[i].value + '<br><button onclick="smeltForgeItem(\'' + inv.items[i].hash + '\')">Smelt</button></div>';
}
for (let i=0; i<inv.pendingItems.length; i++) {
itemHTML += '<div style="display: inline-block;border-style: solid;border-width: 2px;border-radius: 7px;padding: 10px;margin: 10px;opacity: 0.5;">' + "<b>Name:<b/> " + inv.pendingItems[i].name + '<br><b>Value: </b>' + inv.pendingItems[i].value + '</div>';
}
document.getElementById("items").innerHTML = itemHTML;
});
}
setInterval(function() {
if (safeMode) return document.getElementById("peerCount").innerHTML = "Offline (Missing RPC Connection)<br>Please start ZENZO Core, then restart the Forge.";
if (peers.length === 0) {
document.getElementById("peerCount").innerHTML = "Offline (No peers connected)";
} else {
document.getElementById("peerCount").innerHTML = peers.length;
refreshInventory();
}
}, 1000);
refreshInventory();
</script>
</div>
<div id="wallet" style="height: 100vh; background-color: white; margin-left: 160px; display: block; text-align: center;">
<h1 style="text-align: center;font-family: helvetica;margin-top: 0;padding-top: 25px;">ZENZO Wallet</h1>
<h2 style="text-align: center;font-family: helvetica;margin-top: 0;padding-top: 25px;">Available: <b id="available_znz">0</b><br>Total: <b id="total_znz">0</b><br>Locked: <b id="locked_znz">0</b></h2><br>
<h2 style="text-align: center;font-family: helvetica;margin-top: 0;padding-top: 25px;">Receive ZNZ</h2><p>Your receive address</p>
<input id="receive_address" readonly="readonly" type="text" value="" style="text-align: center; width: 315px; border-style: none; background-color: #8678dc4a; border-radius: 1000px;"><br>
<br><h2 style="text-align: center;font-family: helvetica;margin-top: 0;padding-top: 25px;">Send ZNZ</h2>
<input id="send_to" oninput="checkForProfile()" type="text" placeholder="ZNZ Address or Name">
<input id="send_amount" type="number" placeholder="Amount (ZNZ)">
<button onclick="sendGuiTX()">Send</button>
<br>
<p id="sending_to_parent" style="color:black; opacity: 0.5; display:none">(Sending to <b id="sending_to">???</b>)</p>
<script>
function fetchBalances() {
document.getElementById("receive_address").value = addy;
zenzo.call("getwalletinfo").then(RPCbalances => {
document.getElementById("total_znz").innerHTML = RPCbalances.balance.toFixed(2);
let lockedBalance = 0;
for (let i=0; i<items.length; i++) {
if (items[i].address === addy) lockedBalance += items[i].value;
}
for (let i=0; i<itemsToValidate.length; i++) {
if (itemsToValidate[i].address === addy) lockedBalance += itemsToValidate[i].value;
}
document.getElementById("available_znz").innerHTML = (RPCbalances.balance - lockedBalance).toFixed(2);
document.getElementById("locked_znz").innerHTML = lockedBalance;
});
}
function sendGuiTX() {
const amt = Number(document.getElementById("send_amount").value);
const to = document.getElementById("send_to").value;
let toAddress;
let toUsername;
let isUsername = false;
if (to.length !== 34) {
let toUser = getProfile(to, true);
if (toUser !== null) {
toAddress = toUser.address;
toUsername = toUser.name.replace("zenzo.", "");
isUsername = true;
} else {
// No address, no username; error out
}
} else {
toAddress = to;
}
zenzo.call("sendtoaddress", toAddress, amt).then(guiTx => {
console.info("GUI: Transaction sent! " + guiTx);
fetchBalances();
}).catch(console.error);
}
function checkForProfile () {
console.info("Checking for profile...");
const to = document.getElementById("send_to").value;
let toAddress;
let toUsername;
let isUsername = false;
if (to.length !== 34) {
let toUser = getProfile(to, true);
if (toUser !== null) {
toAddress = toUser.address;
toUsername = toUser.name.replace("zenzo.", "");
isUsername = true;
document.getElementById("sending_to").innerHTML = toAddress;
document.getElementById("sending_to_parent").style.display = "block";
console.info("Found username: " + toUsername);
} else {
document.getElementById("sending_to").innerHTML = "invalid Address or Username";
document.getElementById("sending_to_parent").style.display = "block";
console.info("Couldn't find user or address");
}
} else {
let toUser = getProfile(to, true);
if (toUser !== null) {
toAddress = toUser.address;
toUsername = toUser.name.replace("zenzo.", "");
isUsername = true;
document.getElementById("sending_to").innerHTML = toUsername;
document.getElementById("sending_to_parent").style.display = "block";
console.info("Found username: " + toUsername);
} else {
document.getElementById("sending_to").innerHTML = to;
document.getElementById("sending_to_parent").style.display = "block";
console.info("Regular address");
}
}
}
setInterval(fetchBalances, 1000);
</script>
</div>
<div id="new_profile" style="height: 100vh; background-color: white; margin-left: 160px; display: none; text-align: center;">
<h1 style="text-align: center;font-family: helvetica;margin-top: 0;padding-top: 25px;">Create a ZENZO Profile</h1>
<h3 style="text-align: center;font-family: helvetica;margin-top: 0;padding-top: 25px;">What is a ZENZO Profile?</h3>
<p>A ZENZO Profile is a decentralized ZFI (ZENZO Forge Item) that allocates a custom, human-readable username to a ZENZO address.<br>This allows you to have a completely trustless and immutable player profile, directly on the ZENZO Forge network.</p>
<input id="new_username" type="text" placeholder="Zentoshi Zakamoto" style="text-align: center; width: 250px;"><br>
<button onclick="createUsername()">Create Profile</button>
<script>
let user_profile = null;
async function createUsername() {
const newUsername = document.getElementById("new_username").value;
let isUsernameFree = getProfile(newUsername, true);
if (isUsernameFree === null) {
try {
let createdUser = await superagent
.post("http://127.0.0.1:80/forge/create")
.send({name: "zenzo." + newUsername, amount: 10, auth: authToken});
user_profile = createdUser.body;
loadProfile();
openProfile();
} catch (e) {
console.error("Profile creation error: " + e);
}
} else {
console.warn("Profile creation rejected, username already taken");
}
}
</script>
</div>
<div id="profile" style="height: 100vh; background-color: white; margin-left: 160px; display: none; text-align: center;">
<h1 style="text-align: center;font-family: helvetica;margin-top: 0;padding-top: 25px;">ZENZO Profile</h1>
<h3 style="text-align: center;font-family: helvetica;margin-top: 0;padding-top: 25px;">Welcome, <b id="welcome_username"></b></h3>
<script>
async function loadProfile () {
let userTmp = getProfile(addy, true);
if (userTmp !== null) {
user_profile = userTmp;
document.getElementById("welcome_username").innerHTML = user_profile.name.replace("zenzo.", "");
return true;
} else {
return false;
}
}
</script>
</div>
</body>
</html>