-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
605 lines (512 loc) · 26.6 KB
/
main.js
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
import { ethers } from "ethers";
import 'regenerator-runtime/runtime'
import * as constants from "./constants.js"
//import * as constants from "./rinkeby-constants.js"
import images_jpg from "./images/*.jpg"
import images_png from "./images/*.png"
import images_gif from "./images/*.gif"
let images = Object.assign({}, images_jpg, images_png, images_gif);
const numCards = 30; // for debugging
const { ethereum } = window;
if (ethereum) {
var provider = new ethers.providers.Web3Provider(ethereum);
var signer = provider.getSigner();
}
function isEthereumAvailable() {
Boolean(ethereum);
}
function updateStatusBar(color, blink, contents) {
// remove existing state
document.getElementById("connection-indicator").classList.remove("circle-blink");
document.getElementById("connection-indicator").classList.remove("circle-red");
document.getElementById("connection-indicator").classList.remove("circle-orange");
document.getElementById("connection-indicator").classList.remove("circle-green");
// set blink
if (blink) {
document.getElementById("connection-indicator").classList.add("circle-blink");
}
// add color
document.getElementById("connection-indicator").classList.add("circle-" + color);
// set contents
document.getElementById("web3").innerText = contents;
}
async function resetStatusBarToGreen() {
getUserAddr().then(userAddr => {
updateStatusBar("green", false, "Connected as " + userAddr.substring(0, 5) + "…" + userAddr.substring(userAddr.length-3));
});
}
async function connectWallet() {
console.debug("connectWallet");
await ethereum.request({
method: 'eth_requestAccounts'
});
const accts = await provider.listAccounts();
if (accts.length > 0) {
document.getElementById("connect-wallet").remove();
} else {
throw Error("Connected to ethereum but provider.listAccounts() returned empty!");
}
// once connected, perform the next tasks, like populating token balances
postConnection();
// show "click the cards" helper image
document.getElementById("click-da-cards").classList.remove("hidden");
}
async function getUserAddr() {
return await provider.listAccounts().then(accts => {
if (accts.length > 0) {
console.debug("connected! " + JSON.stringify(accts));
return accts[0];
} else {
console.debug("not yet connected!");
return;
}
});
}
async function getErc20Balance(tokenAddr, userAddr) {
//console.debug("fetching balance for tokenAddr: " + tokenAddr);
//await new Promise(resolve => setTimeout(resolve, Math.random() * 500));
const contract = await new ethers.Contract(tokenAddr, constants.erc20Abi, provider);
return await contract.balanceOf(userAddr);
}
async function getErc1155BalanceBatch(contractAddr, userAddr) {
const contract = await new ethers.Contract(contractAddr, constants.wrapperAbi, provider);
console.debug("querying batch... ");
const userAddrArray = Array(30).fill(userAddr);
let idArray = Array.from(Array(31).keys());
idArray.shift();
return await contract.balanceOfBatch(userAddrArray, idArray);
}
async function handleCardClick(event) {
return await _handleCardClick(event.target);
}
async function _handleCardClick(clickedElement) {
let currentCard, currentType, currentElement, otherElement;
if (document.getElementById("click-da-cards")) {
// remove "click the cards" helper image
document.getElementById("click-da-cards").remove();
// show middle dividing line
document.getElementById("middle-line").classList.remove("hidden");
}
if (clickedElement.id.startsWith("nav-card-erc20")) {
currentType = "erc20";
currentCard = Number(clickedElement.id.substring(21));
// reassign current, other to the <article>s in the <nav>
currentElement = document.getElementById("nav-card-erc20-" + currentCard);
otherElement = document.getElementById("nav-card-erc1155-" + currentCard);
} else if (clickedElement.id.startsWith("nav-card-erc1155")) {
currentCard = Number(clickedElement.id.substring(23));
currentType = "erc1155";
// reassign current, other to the <article>s in the <nav>
currentElement = document.getElementById("nav-card-erc1155-" + currentCard);
otherElement = document.getElementById("nav-card-erc20-" + currentCard);
} else {
throw Error("handleCardClick: unable to determine id startswith nav-card.ercXXXX");
}
if (currentElement.classList.contains("unselected")) {
// card is unselected- set to selected
currentElement.classList.remove("unselected");
currentElement.classList.add("selected");
otherElement.classList.remove("unselected");
otherElement.classList.add("selected");
// unhide table row
document.getElementById("row-" + currentCard).classList.remove("hidden");
document.getElementById("row-" + currentCard).classList.add("row-displayinitial");
//set currentElement and otherElement to have the selected class
Array.from(currentElement.children).find(e => e.localName == "img").classList.add("nav-card__grayscale");
Array.from(otherElement.children).find(e => e.localName == "img").classList.add("nav-card__grayscale");
Array.from(currentElement.children).find(e => e.classList.contains("nav-card__overlay")).classList.add("nav-card__overlay-selected");
Array.from(otherElement.children).find(e => e.classList.contains("nav-card__overlay")).classList.add("nav-card__overlay-selected");
} else if (currentElement.classList.contains("selected")) {
// card is selected- set to unselected
currentElement.classList.remove("selected");
currentElement.classList.add("unselected");
otherElement.classList.remove("selected");
otherElement.classList.add("unselected");
// hide table row
document.getElementById("row-" + currentCard).classList.remove("row-displayinitial");
document.getElementById("row-" + currentCard).classList.add("hidden");
// set to-wrap-# for this row back to 0
document.getElementById("to-wrap-" + currentCard).value = "";
document.getElementById("to-unwrap-" + currentCard).value = "";
Array.from(currentElement.children).find(e => e.localName == "img").classList.remove("nav-card__grayscale");
Array.from(otherElement.children).find(e => e.localName == "img").classList.remove("nav-card__grayscale");
Array.from(currentElement.children).find(e => e.classList.contains("nav-card__overlay")).classList.remove("nav-card__overlay-selected");
Array.from(otherElement.children).find(e => e.classList.contains("nav-card__overlay")).classList.remove("nav-card__overlay-selected");
} else {
throw Error("handleCardClick: card in neither Selected nor Unselected state!");
}
// finally, update the total to wrap #
updateWrapTotal();
}
function handleSelectAll(event) {
for (let i = 1; i <= numCards; i++) {
switch (event.target.id) {
case "select-all-unwrapped":
// hack- force all to deselected state so handleCardClick works right
document.getElementById("nav-card-erc20-" + i).classList.remove("selected");
document.getElementById("nav-card-erc20-" + i).classList.add("unselected");
_handleCardClick(document.getElementById("nav-card-erc20-image-" + i));
break;
case "deselect-all-unwrapped":
// hack- force all to selected state so handleCardClick works right
document.getElementById("nav-card-erc20-" + i).classList.remove("unselected");
document.getElementById("nav-card-erc20-" + i).classList.add("selected");
_handleCardClick(document.getElementById("nav-card-erc20-image-" + i));
break;
case "select-all-wrapped":
// hack- force all to deselected state so handleCardClick works right
document.getElementById("nav-card-erc1155-" + i).classList.remove("selected");
document.getElementById("nav-card-erc1155-" + i).classList.add("unselected");
_handleCardClick(document.getElementById("nav-card-erc1155-image-" + i), document.getElementById("nav-card-erc20-" + i));
break;
case "deselect-all-wrapped":
// hack- force all to selected state so handleCardClick works right
document.getElementById("nav-card-erc1155-" + i).classList.remove("unselected");
document.getElementById("nav-card-erc1155-" + i).classList.add("selected");
_handleCardClick(document.getElementById("nav-card-erc1155-image-" + i), document.getElementById("nav-card-erc20-" + i));
break;
}
}
}
function updateWrapTotal() {
let totalToWrap = 0, totalToUnwrap = 0;
for (let i = 1; i <= numCards; i++) {
const wrapAmt = document.getElementById("to-wrap-" + i).value;
if (Number(wrapAmt)) {
totalToWrap += Number(wrapAmt);
}
const unwrapAmt = document.getElementById("to-unwrap-" + i).value;
if (Number(unwrapAmt)) {
totalToUnwrap += Number(unwrapAmt);
}
}
document.getElementById("total-wrap").innerText = "Wrap " + totalToWrap + " Curio Cards";
document.getElementById("total-unwrap").innerText = "Unwrap " + totalToUnwrap + " Curio Cards";
}
async function calculateTotalToWrap() {
// these will be used to calculate total for display, and to pass args to wrapBatch and unwrapBatch.
let wrapitup = {
"wrap": {
1: null,
2: null
},
"unwrap": {
1: null,
2: null
}
};
for (let i = 1; i <= numCards; i++) {
const wrapAmt = document.getElementById("to-wrap-" + i).value;
wrapitup["wrap"][i] = Number(wrapAmt) || 0;
const unwrapAmt = document.getElementById("to-unwrap-" + i).value;
wrapitup["unwrap"][i] = Number(unwrapAmt) || 0;
}
return wrapitup;
}
async function handleWrapClick(event) {
let action = event.target.id == "wrap-button" ? "wrap" : "unwrap";
const wrapitup = await calculateTotalToWrap();
console.debug("wrapitup: " + JSON.stringify(wrapitup));
const wrapperContract = await new ethers.Contract(constants.wrapperAddr, constants.wrapperAbi, signer);
const userAddr = await getUserAddr();
// there's 4 possible functions to execute from here:
// wrap or unwrap, if only 1 type of card to change
// wrapBatch or unwrapBatch, if multiple types of card to change
try {
// First, test if there's only any cards to wrap.
if (action == "wrap") {
console.debug("handling wrap");
// find nonzero values
const nonzeroWrapValues = Object.keys(wrapitup["wrap"])
.filter(key => wrapitup["wrap"][key] > 0)
.reduce((res, key) => (res[key] = wrapitup["wrap"][key], res), {});
console.debug("nonzeroWrapValues: " + JSON.stringify(nonzeroWrapValues));
if (Object.keys(nonzeroWrapValues).length == 0) {
console.debug("No values found to wrap!");
} else if (Object.keys(nonzeroWrapValues).length == 1) {
console.debug("Wrapping 1 type of card...");
const cardId = Object.keys(nonzeroWrapValues)[0];
const wrapNum = nonzeroWrapValues[cardId];
console.debug("cardId: " + cardId);
console.debug("wrapNum: " + wrapNum);
const erc20Contract = await new ethers.Contract(constants.curioAddresses["CRO" + cardId], constants.erc20Abi, signer);
// if we have approval already, skip
const allowanceToSpend = await erc20Contract.allowance(userAddr, constants.wrapperAddr);
console.debug("current allowance: " + allowanceToSpend);
if (allowanceToSpend == 0) {
updateStatusBar("orange", true, "Executing transaction 1 of 2…");
// seek approval
const approvalResult = await erc20Contract.approve(constants.wrapperAddr, 2000);
console.debug("approvalResult:");
console.debug(approvalResult);
const receipt = await approvalResult.wait();
console.debug("receipt:");
console.debug(receipt);
updateStatusBar("orange", true, "Executing transaction 2 of 2…");
} else {
updateStatusBar("orange", true, "Executing transaction 1 of 1…");
}
// perform wrap
const wrapResult = await wrapperContract.wrap(cardId, wrapNum);
console.debug("wrapResult:");
const receipt2 = await wrapResult.wait();
console.debug("receipt2:");
console.debug(receipt2);
// update balances
populateBalances();
// reset state of status bar
updateStatusBar("green", false, "Wrap completed");
} else {
console.debug("Wrapping multiple types of cards...");
// what do i gotta do here.
// 1. get approvals for all erc20s that don't yet have approval
// 2. submit bulk txn
let approvalsRequired = [];
for (let i = 0; i < Object.keys(nonzeroWrapValues).length; i++) {
const cardId = Object.keys(nonzeroWrapValues)[i];
console.debug("cardId: " + cardId);
const erc20Contract = await new ethers.Contract(constants.curioAddresses["CRO" + cardId], constants.erc20Abi, signer);
// if we have approval already, skip
const allowanceToSpend = await erc20Contract.allowance(userAddr, constants.wrapperAddr);
console.debug("current allowance: " + allowanceToSpend);
if (allowanceToSpend == 0) {
approvalsRequired.push(cardId);
}
}
console.debug(approvalsRequired.length + " approvals required. executing...");
for (let i = 0; i < approvalsRequired.length; i++) {
// Update status bar with how many more transactions are required
updateStatusBar("orange", true, "Executing transaction " + (i+1) + " of " + (approvalsRequired.length+1) + "…");
// seek approval
const erc20Contract = await new ethers.Contract(constants.curioAddresses["CRO" + approvalsRequired[i]], constants.erc20Abi, signer);
const approvalResult = await erc20Contract.approve(constants.wrapperAddr, 2000);
console.debug("approvalResult:");
console.debug(approvalResult);
const receipt = await approvalResult.wait();
console.debug("receipt:");
console.debug(receipt);
}
// Update status bar with how many more transactions are required
console.debug(approvalsRequired.length)
console.debug(approvalsRequired.length+1)
console.debug((approvalsRequired.length+1))
updateStatusBar("orange", true, "Executing transaction " + (approvalsRequired.length+1) + " of " + (approvalsRequired.length+1) + "…");
// perform wrap
const cardIdList = Object.keys(nonzeroWrapValues);
let wrapNumList = [];
for (let i = 0; i < cardIdList.length; i++) {
wrapNumList.push(nonzeroWrapValues[cardIdList[i]]);
}
console.debug("About to wrap card IDs " + JSON.stringify(cardIdList) + " with balances " + JSON.stringify(wrapNumList));
const wrapResult = await wrapperContract.wrapBatch(cardIdList, wrapNumList);
console.debug("wrapResult:");
const receipt = await wrapResult.wait();
console.debug("receipt:");
console.debug(receipt);
// update balances
populateBalances();
// reset state of status bar
updateStatusBar("green", false, "Wrap completed");
}
} else {
console.debug("handling unwrap");
// find nonzero values
const nonzeroUnwrapValues = Object.keys(wrapitup["unwrap"])
.filter(key => wrapitup["unwrap"][key] > 0)
.reduce((res, key) => (res[key] = wrapitup["unwrap"][key], res), {});
console.debug("nonzeroUnwrapValues: " + JSON.stringify(nonzeroUnwrapValues));
if (Object.keys(nonzeroUnwrapValues).length == 0) {
console.debug("No values found to unwrap!");
} else if (Object.keys(nonzeroUnwrapValues).length == 1) {
console.debug("Unwrapping 1 type of card...");
const cardId = Object.keys(nonzeroUnwrapValues)[0];
const unwrapNum = nonzeroUnwrapValues[cardId];
console.debug(wrapperContract.unwrap);
console.debug("cardId: " + cardId);
console.debug("unwrapNum: " + unwrapNum);
updateStatusBar("orange", true, "Executing transaction 1 of 1…");
const unwrapResult = await wrapperContract.unwrap(cardId, unwrapNum);
console.debug("unwrapResult:");
const receipt2 = await unwrapResult.wait();
console.debug("receipt2:");
console.debug(receipt2);
// update balances
populateBalances();
// reset state of status bar
updateStatusBar("green", false, "Unwrap completed");
} else {
console.debug("Unwrapping multiple types of cards...");
const cardIdList = Object.keys(nonzeroUnwrapValues);
let unwrapNumList = [];
for (let i = 0; i < cardIdList.length; i++) {
unwrapNumList.push(nonzeroUnwrapValues[cardIdList[i]]);
}
updateStatusBar("orange", true, "Executing transaction 1 of 1…");
console.debug("About to unwrap card IDs " + JSON.stringify(cardIdList) + " with balances " + JSON.stringify(unwrapNumList));
const unwrapResult = await wrapperContract.unwrapBatch(cardIdList, unwrapNumList);
console.debug("unwrapResult:");
const receipt = await unwrapResult.wait();
console.debug("receipt:");
console.debug(receipt);
// update balances
populateBalances();
// reset state of status bar
updateStatusBar("green", false, "Unwrap completed");
}
}
} catch (e) {
if (e.code) {
console.warn("Received Metamask errorcode: " + e.code);
if (e.code == 4001) {
updateStatusBar("red", false, "Metamask error 4001: User denied transaction signature");
} else {
updateStatusBar("red", false, "Metamask error " + e.code);
}
}
// rethrow for logging
throw e;
}
}
// This exists for debug purposes
async function revokeApproval() {
await new Promise(resolve => setTimeout(resolve, 2000));
const i = 2; // which curio card to revoke?
console.debug("Revoking approval for card " + i);
const erc20Contract = await new ethers.Contract(constants.curioAddresses["CRO" + i], constants.erc20Abi, signer);
const approvalResult = await erc20Contract.approve(constants.wrapperAddr, 0);
console.debug("approvalResult:");
console.debug(approvalResult);
const receipt = await approvalResult.wait();
console.debug("receipt:");
console.debug(receipt);
}
async function populateBalances() {
console.debug("populateBalances");
const userAddr = await getUserAddr();
if (!userAddr) {
throw Error("populateBalances(): Unable to fetch user address!");
}
// populate erc20 balances
for (let i = 1; i <= numCards; i++) {
const currentSymbol = "CRO" + i;
getErc20Balance(constants.curioAddresses[currentSymbol], userAddr).then(balance => {
console.debug("erc20 " + currentSymbol + " balance: " + balance);
document.getElementById("nav-card-erc20-" + i + "-balance").innerText = balance;
document.getElementById("main-card-erc20-" + i + "-balance").innerText = balance;
// set max value for input field
document.getElementById("to-wrap-" + i).max = balance;
});
}
// populate erc1155 balances
getErc1155BalanceBatch(constants.wrapperAddr, userAddr).then(balances => {
console.debug("erc1155 balances: " + balances);
for (let i = 1; i <= numCards; i++) {
console.debug("erc1155 id " + i + " balance: " + balances[i-1]);
document.getElementById("nav-card-erc1155-" + i + "-balance").innerText = balances[i-1];
document.getElementById("main-card-erc1155-" + i + "-balance").innerText = balances[i-1];
// set max value for input field
document.getElementById("to-unwrap-" + i).max = balances[i-1];
}
});
// TODO reset <input> fields back to 0
for (let i = 1; i <= numCards; i++) {
document.getElementById("to-wrap-" + i).value = "";
document.getElementById("to-unwrap-" + i).value = "";
}
}
// work to perform after connection is established
async function postConnection() {
// update status bar
resetStatusBarToGreen();
// populate cards dynamically
for (let i = 1; i <= numCards; i++) {
document.getElementById("nav").innerHTML += `
<article id="nav-card-erc20-${i}" class="nav-card unselected">
<div class="nav-card__overlay"></div>
<img id="nav-card-erc20-image-${i}" class="nav-card__image" src="${images[i]}" alt="Curio${i}">
<div class="label__wrapper">
<p class="cell cell__white">CRO${i}</p>
<div class="balance__container">
<p class="cell cell__white">Balance</p><p id="nav-card-erc20-${i}-balance" class="cell cell__red">0</p>
</div>
</div>
</article>
<div class="spacer"></div>
<article id="nav-card-erc1155-${i}" class="nav-card unselected">
<div class="nav-card__overlay"></div>
<img id="nav-card-erc1155-image-${i}" class="nav-card__image" src="${images[i]}" alt="Curio${i}">
<div class="label__wrapper">
<p class="cell cell__red">WRAPPED</p>
<p class="cell cell__white">CRO${i}</p>
<div class="balance__container">
<p class="cell cell__white">Balance</p><p id="nav-card-erc1155-${i}-balance" class="cell cell__red">0</p>
</div>
</div>
</article>
`;
document.getElementById("rows").innerHTML += `
<article id="row-${i}" class="row hidden">
<header class="row__header cell cell__red">CRO${i}</header>
<div class="row__gridfucker">
<p class="balance-label cell">Unwrapped Balance</p>
<p class="balance-value cell" id="main-card-erc20-${i}-balance">0</p>
<p class="balance-label cell">Wrapped Balance</p>
<p class="balance-value cell" id="main-card-erc1155-${i}-balance">0</p>
<label for="wrap" class="balance-label cell">How many to wrap?</label>
<input for="wrap" id="to-wrap-${i}" class="how-many-input cell cell__pink" type="number" placeholder="0" min="0" max="2000"></input>
<label for="unwrap" class="balance-label cell">How many to unwrap?</label>
<input for="unwrap" id="to-unwrap-${i}" class="how-many-input cell cell__pink" type="number" placeholder="0" min="0" max="2000"></input>
</div>
</article>
`;
}
await populateBalances();
// bind event listeners to nav cards
for (let i = 1; i <= numCards; i++) {
const erc20Element = document.getElementById("nav-card-erc20-" + i);
erc20Element.addEventListener("click", handleCardClick);
erc20Element.classList.add("pointer");
const erc1155Element = document.getElementById("nav-card-erc1155-" + i);
erc1155Element.addEventListener("click", handleCardClick);
erc1155Element.classList.add("pointer");
}
// bind event listeners to select/unselect all buttons
document.getElementById("select-all-wrapped").addEventListener("click", handleSelectAll);
document.getElementById("deselect-all-wrapped").addEventListener("click", handleSelectAll);
document.getElementById("select-all-unwrapped").addEventListener("click", handleSelectAll);
document.getElementById("deselect-all-unwrapped").addEventListener("click", handleSelectAll);
// bind event listeners to Wrap and Unwrap buttons
const wrapButton = document.getElementById("wrap-button");
wrapButton.addEventListener("click", handleWrapClick);
wrapButton.classList.add("pointer");
const unwrapButton = document.getElementById("unwrap-button");
unwrapButton.addEventListener("click", handleWrapClick);
unwrapButton.classList.add("pointer");
// bind event listeners to <input> fields
for (let i = 1; i <= numCards; i++) {
document.getElementById("to-wrap-" + i).addEventListener("input", updateWrapTotal);
document.getElementById("to-unwrap-" + i).addEventListener("input", updateWrapTotal);
}
}
async function initialize() {
console.debug("initialize");
if (!provider) {
console.error("Your browser is not web3 enabled.");
document.getElementById("install-metamask").classList.remove("hidden");
return;
}
getUserAddr().then(userAddr => {
if (userAddr) {
// already connected
document.getElementById("connect-wallet").remove();
document.getElementById("click-da-cards").classList.remove("hidden");
postConnection();
} else {
// prompt user to connect
updateStatusBar("orange", false, "Connect your wallet to continue");
document.getElementById("connect-wallet").classList.remove("hidden");
document.getElementById("connect-wallet-button").addEventListener("click", connectWallet);
}
});
}
window.addEventListener('DOMContentLoaded', initialize);