-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
841 lines (788 loc) · 30.1 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
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
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src='web3.min.js'></script>
<script src="//code.jquery.com/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
var accounts;
var contractInstance;
var productId = 0;
var currentProductId;
async function registClick() {
if (accounts == null) {
alert("계정을 연결해주세요")
return;
}
if (contractInstance != null) {
try {
let valproductName = document.getElementsByClassName('productName')[0].value
let valproductAmount = document.getElementsByClassName('productAmount')[0].value
let valproductTime = document.getElementsByClassName('productTime')[0].value
if (valproductName == '' | valproductAmount == '' | valproductTime == '') {
alert("모든 정보를 입력해주세요")
} else {
let value = await contractInstance.methods.registerProduct(valproductName, web3.utils.toWei(valproductAmount, 'ether'), valproductTime).send({ from: accounts[0] });
// auction product list 에 동적 추가
$('.ProductWrap > div:last-child').append(
"<div class=\"product\" id=" + productId + " onclick=\"bidding(id)\">\n" +
"<span>" + valproductName + "</span>\n" +
"<span>\n" +
"<span>min bidding :</span>\n" +
"<span>" + valproductAmount + " eth</span>\n" +
"</span>\n" +
"</div>"
);
productId++;
document.getElementsByClassName('productName')[0].value = '';
document.getElementsByClassName('productAmount')[0].value = '';
document.getElementsByClassName('productTime')[0].value = '';
}
} catch (e) {
console.log(e)
}
}
}
async function bidClick() {
if (contractInstance != null) {
try {
let valbidAmount = document.getElementsByClassName('bidAmount')[0].value
let value = await contractInstance.methods.bid(currentProductId).send({ from: accounts[0], value: valbidAmount * (10 ** 18) });
let productValue = await contractInstance.methods.getProduct(currentProductId).call()
let showCurBid = document.getElementsByClassName('bidCurBid')[0]
showCurBid.innerHTML = productValue[5] / (10 ** 18)
alert("입찰이 성공적으로 진행되었습니다.");
document.getElementsByClassName('bidAmount')[0].value = '';
} catch (e) {
alert('입찰에 실패했습니다.');
}
}
}
async function getProductInfo() {
if (contractInstance != null) {
try {
let productValue = await contractInstance.methods.getProduct(currentProductId).call()
let auctionValue = await contractInstance.methods.getAuction(currentProductId).call()
let showProductName = document.getElementsByClassName('bidProductName')[0]
let showMinBid = document.getElementsByClassName('bidMinBid')[0]
let showCurBid = document.getElementsByClassName('bidCurBid')[0]
let showTimeLimit = document.getElementsByClassName('bidTimeLimit')[0]
showProductName.innerHTML = productValue[0]
showMinBid.innerHTML = productValue[1] / (10 ** 18)
showCurBid.innerHTML = productValue[5] / (10 ** 18)
const date = new Date(parseInt(auctionValue[1]) * 1000); // 유닉스 시간을 밀리초 단위로 변환하여 Date 객체 생성
const now = date.toLocaleString(); // 현재 시간으로 변환
showTimeLimit.innerHTML = now
} catch (e) {
console.log(e)
}
}
}
async function endAuction() {
if (contractInstance != null) {
try {
let auctionValues = await contractInstance.methods.endAuction(currentProductId).send({ from: accounts[0] });
let item = document.getElementById(currentProductId);
backToMain();
$('.RecordWrap > div:last-child').append(item);
} catch (e) {
alert('경매 종료에 실패했습니다.');
}
}
}
async function getAuctions() {
const showAccount = document.querySelector('.address')
if (showAccount.innerHTML == '') {
if (contractInstance != null) {
try {
let auctionValues = await contractInstance.methods.getAuctions().call()
for (var i = 0; i < auctionValues.length; i++) {
let productValue = await contractInstance.methods.getProduct(i).call()
if (auctionValues[i][2] == false) {
$('.ProductWrap > div:last-child').append(
"<div class=\"product\" id=" + productId + " onclick=\"bidding(id)\">\n" +
"<span>" + productValue[0] + "</span>\n" +
"<span>\n" +
"<span>min bidding :</span>\n" +
"<span>" + productValue[1] / (10 ** 18) + " eth</span>\n" +
"</span>\n" +
"</div>"
);
productId++;
}
else {
$('.RecordWrap > div:last-child').append(
"<div class=\"product\" id=" + productId + " onclick=\"bidding(id)\">\n" +
"<span>" + productValue[0] + "</span>\n" +
"<span>\n" +
"<span>min bidding :</span>\n" +
"<span>" + productValue[1] / (10 ** 18) + " eth</span>\n" +
"</span>\n" +
"</div>"
);
productId++;
}
}
} catch (e) {
console.log(e)
}
}
}
}
// Show current time
function handleDate() {
let now = new Date().toLocaleString();
var downloadTimer = setInterval(function () {
let check = new Date().toLocaleString();
$('.currentTime').text(check)
}, 1000);
}
async function checkRecord() {
if (contractInstance != null) {
try {
console.log(currentProductId)
let productValue = await contractInstance.methods.getProduct(currentProductId).call()
let showEndProductName = document.getElementsByClassName('endName')[0]
let showEndAddress = document.getElementsByClassName('endAddress')[0]
let showEndBid = document.getElementsByClassName('endAmount')[0]
showEndProductName.innerHTML = productValue[0]
showEndAddress.innerHTML = productValue[4]
showEndBid.innerHTML = productValue[5] / (10 ** 18)
} catch (e) {
console.log(e)
}
}
let showBlock = document.getElementById('detailRecord')
showBlock.style.display = 'flex';
}
function closeDetail() {
let showBlock = document.getElementById('detailRecord')
showBlock.style.display = 'none';
}
// show bidding block
function bidding(number) {
let ele = this.document.getElementById(number).parentElement.parentElement;
currentProductId = number;
// 종료된 경매의 경우 bidding 창으로 넘어가지 않도록
if (ele.classList.contains('RecordWrap')) {
checkRecord();
return;
}
handleDate();
getProductInfo()
let hiddenBlock = document.getElementById('main')
let showBlock = document.getElementById('bidding')
hiddenBlock.style.display = 'none';
showBlock.style.display = 'block';
}
// back to main block
function backToMain() {
let hiddenBlock = document.getElementById('bidding')
let showBlock = document.getElementById('main')
hiddenBlock.style.display = 'none';
showBlock.style.display = 'block';
}
// wallet 연결
async function connectWallet() {
var web3 = new Web3(Web3.givenProvider);
web3.eth.getAccounts(function (error, account) {
if (error) {
console.log(error);
return;
}
accounts = account
const showAccount = document.querySelector('.address')
showAccount.innerHTML = account[0]
});
var abiobj = [
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "auctionInfo",
"outputs": [
{
"internalType": "address payable",
"name": "beneficiary",
"type": "address"
},
{
"internalType": "uint256",
"name": "auctionEnd",
"type": "uint256"
},
{
"internalType": "bool",
"name": "ended",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_productId",
"type": "uint256"
}
],
"name": "bid",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_productId",
"type": "uint256"
}
],
"name": "endAuction",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_auctionId",
"type": "uint256"
}
],
"name": "getAuction",
"outputs": [
{
"internalType": "address payable",
"name": "",
"type": "address"
},
{
"internalType": "uint256",
"name": "",
"type": "uint256"
},
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getAuctions",
"outputs": [
{
"components": [
{
"internalType": "address payable",
"name": "beneficiary",
"type": "address"
},
{
"internalType": "uint256",
"name": "auctionEnd",
"type": "uint256"
},
{
"internalType": "bool",
"name": "ended",
"type": "bool"
}
],
"internalType": "struct Auction.AuctionInfo[]",
"name": "",
"type": "tuple[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_productId",
"type": "uint256"
}
],
"name": "getProduct",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
},
{
"internalType": "uint256",
"name": "",
"type": "uint256"
},
{
"internalType": "address",
"name": "",
"type": "address"
},
{
"internalType": "bool",
"name": "",
"type": "bool"
},
{
"internalType": "address",
"name": "",
"type": "address"
},
{
"internalType": "uint256",
"name": "",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getProducts",
"outputs": [
{
"components": [
{
"internalType": "string",
"name": "name",
"type": "string"
},
{
"internalType": "uint256",
"name": "price",
"type": "uint256"
},
{
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "bool",
"name": "sold",
"type": "bool"
},
{
"internalType": "address payable",
"name": "bidder",
"type": "address"
},
{
"internalType": "uint256",
"name": "bid",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "timelimit",
"type": "uint256"
}
],
"internalType": "struct Auction.Product[]",
"name": "",
"type": "tuple[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "products",
"outputs": [
{
"internalType": "string",
"name": "name",
"type": "string"
},
{
"internalType": "uint256",
"name": "price",
"type": "uint256"
},
{
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "bool",
"name": "sold",
"type": "bool"
},
{
"internalType": "address payable",
"name": "bidder",
"type": "address"
},
{
"internalType": "uint256",
"name": "bid",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "timelimit",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "_name",
"type": "string"
},
{
"internalType": "uint256",
"name": "_price",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "_auctionEnd",
"type": "uint256"
}
],
"name": "registerProduct",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
];
var address = "0x9Cd568A0D0b2963B694F6Bb82dC693a353be0750";
window.web3 = new Web3(window.ethereum);
contractInstance = await new window.web3.eth.Contract(abiobj, address);
getAuctions()
}
</script>
<style>
@font-face {
font-family: 'BookkMyungjo-Bd';
src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/[email protected]/BookkMyungjo-Bd.woff2') format('woff2');
font-weight: 700;
font-style: normal;
}
* {
font-family: 'BookkMyungjo-Bd';
}
body>div {
max-width: 1140px;
margin: auto;
}
.infoWrap {
margin: 60px 0 32px;
}
.infoWrap>div:nth-child(1) {
font-size: 28px;
font-weight: 700;
margin-bottom: 12px;
}
.infoWrap>div:nth-child(2) {
font-size: 22px;
font-weight: 500;
margin-bottom: 20px;
}
.infoWrap>div:nth-child(3) {
margin-bottom: 40px;
font-size: 18px;
}
.infoWrap>div:nth-child(4) {
display: flex;
align-items: center;
font-size: 18px;
gap: 12px;
}
.infoWrap>div:nth-child(4) button {
all: unset;
cursor: pointer;
background-color: #D9D9D9;
border-radius: 36px;
padding: 12px 24px;
}
.infoWrap>div:nth-child(4) div {
display: flex;
align-items: center;
margin: unset;
font-size: 18px;
}
.blockWrap {
margin-bottom: 60px;
}
.blockWrap>div {
max-width: 500px;
padding: 32px 40px 80px;
width: 100%;
margin: auto;
border: 1px solid #000000;
border-radius: 20px;
position: relative;
}
.blockWrap>div>div {
display: flex;
flex-direction: column;
margin-bottom: 20px;
}
.blockWrap button {
all: unset;
cursor: pointer;
background-color: #D9D9D9;
border-radius: 36px;
padding: 8px 24px;
position: absolute;
bottom: 36px;
left: 50%;
transform: translateX(-50%);
}
.ProductWrap {
margin-bottom: 60px;
}
.ProductWrap .product,
.RecordWrap>div:last-child>div {
border: 1px solid #7c7c7c;
border-radius: 12px;
padding: 20px 60px;
cursor: pointer;
display: flex;
justify-content: space-between;
margin-bottom: 12px;
}
.RecordWrap {
margin-bottom: 60px;
}
.RecordWrap>div:first-child,
.ProductWrap>div:first-child {
font-weight: 700;
font-size: 20px;
margin-bottom: 20px;
}
#main .subTitle {
font-weight: 700;
font-size: 20px;
text-align: center;
}
#bidding .subTitle,
#detailRecord .inputTitle {
font-weight: 700;
font-size: 20px;
margin-bottom: 8px;
}
#bidding {
display: none;
max-width: 500px;
width: 100%;
padding: 32px 40px;
border: 1px solid #000000;
border-radius: 20px;
margin: auto;
}
#bidding>div:first-child {
cursor: pointer;
margin-bottom: 32px;
}
#bidding input {
max-width: 360px;
width: 100%;
}
#bidding button {
all: unset;
cursor: pointer;
background-color: #D9D9D9;
border-radius: 36px;
padding: 8px 24px;
display: flex;
margin: 20px auto;
}
#detailRecord {
z-index: 99;
background: rgba(0, 0, 0, 0.5);
position: fixed;
top: 0;
inset: 0;
height: 100vh;
display: none;
justify-content: center;
align-items: center;
}
#detailRecord>div {
background-color: #ffffff;
border-radius: 12px;
max-width: 768px;
padding: 40px;
}
#detailRecord>div>div {
margin-bottom: 20px;
}
#detailRecord button {
all: unset;
cursor: pointer;
border-radius: 20px;
border: 2px solid #141414;
padding: 2px 8px;
margin-top: 20px;
}
#detailRecord span {
font-weight: 700;
font-size: 22px;
color: #141414;
padding-bottom: 20px;
}
.productInfo {
margin-bottom: 32px;
}
.inputTitle {
font-weight: 600;
font-size: 16px;
color: #141414;
margin-bottom: 8px;
}
input {
border: 2px solid #E0E0E0;
border-radius: 30px;
flex: 100%;
padding: 12px 20px;
}
input::-webkit-inner-spin-button {
appearance: none;
-moz-appearance: none;
-webkit-appearance: none;
}
</style>
</head>
<body>
<div>
<div id="main">
<div class="infoWrap">
<div>
Project Name : $$-Auction
</div>
<div>
Team Name: Sangwoo Pyo(20181704), Sanglim Nam(20191584)
</div>
<div>
<a href="https://youtu.be/CmO15QmHagA" target="_blank">Project 1 Demo Video</a>
</div>
<div>
<button onclick="connectWallet()">connect account</button>
<div>
<span>Address : </span>
<span class="address"></span>
</div>
</div>
</div>
<div class="blockWrap">
<div>
<div class="subTitle">Registering a Product</div>
<div>
<div class="inputTitle">Product Name</div>
<input class="productName" type="text" placeholder="Enter the product name" />
</div>
<div>
<div class="inputTitle">Minimum bid amount(ether)</div>
<input class="productAmount" type="number" placeholder="Enter the minimum bid amount" />
</div>
<div>
<div class="inputTitle">End time of auction(second)</div>
<input class="productTime" type="number" placeholder="Enter the end time of auction" />
</div>
<button onclick="registClick()">Register</button>
</div>
</div>
<div class="ProductWrap">
<div>List of auction products</div>
<div>
</div>
</div>
<div class="RecordWrap">
<div>Check all auction records</div>
<div></div>
</div>
</div>
<div id="bidding">
<div onclick="backToMain()">↪ back</div>
<div class="productInfo">
<div class="subTitle">
<span>Product Name : </span>
<span class="bidProductName"></span>
</div>
<div class="subTitle">
<span>Minimum bidding amount(ether) : </span>
<span class="bidMinBid"></span>
</div>
<div class="subTitle">
<span>Current bidding amount : </span>
<span class="bidCurBid"></span>
</div>
<div class="subTitle">
<span>Time Limit : </span>
<span class="bidTimeLimit"></span>
</div>
<div class="subTitle">
<span>Current Time : </span>
<span class="currentTime"></span>
</div>
</div>
<div>
<div>
<div class="inputTitle">Bid amount</div>
<input class="bidAmount" type="number" placeholder="Enter the bid amount" />
</div>
<button onclick="bidClick()">Bidding</button>
<div>
<button onclick="endAuction()">End This Autcion</button>
</div>
</div>
</div>
<div id="detailRecord">
<div>
<div>
<div class="inputTitle">★ 경매 물품</div>
<span class="endName"></span>
</div>
<div>
<div class="inputTitle">★ 낙찰 주소</div>
<span class="endAddress"></span>
</div>
<div>
<div class="inputTitle">★ 낙찰 금액</div>
<span class="endAmount"></span>
<span> ether</span>
</div>
<button onclick="closeDetail()">닫기</button>
</div>
</div>
</div>
</body>
</html>