-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
1265 lines (1209 loc) · 71.7 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
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!-- AUTO GENERATED HTML: DO NOT MODIFY MANUALLY -->
<!doctype html>
<html lang="en">
<head>
<!-- header -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="1024 pixels art on Polygon blockchain.">
<title>1024 Pixels Art</title>
<link id="linkFavicon" rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.2/font/bootstrap-icons.css">
<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.12/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/ethers@5.0.32/dist/ethers.umd.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/base64-js@1.5.1/base64js.min.js"></script>
<!--// header -->
<script>
// global vars:
(function () {
const isTestnet = location.hostname === 'localhost';
window.CHAIN_ID = isTestnet ? 80001 : 137;
window.CHAIN_NAME = isTestnet ? 'Polygon Testnet' : 'Polygon';
window.SCAN_URL = isTestnet ? 'https://mumbai.polygonscan.com' : 'https://polygonscan.com';
window.OPENSEA_URL = isTestnet ? 'https://testnets.opensea.io/assets/mumbai/' : 'https://opensea.io/assets/matic/';
window.MARKET_URL = isTestnet ? 'https://testnets.opensea.io/collection/1024pixels-art' : 'https://opensea.io/collection/1024pixels-art';
window.GRAPH_URL = 'https://api.thegraph.com/subgraphs/name/michaelliao/' + (isTestnet ? '1024pixels-testnet' : '1024pixels')
window.PIXELS_ADDR = '0x1024E76fbe54D1016f973FaD36f34ce94D9a128D';
window.PIXELS_ABI = '[{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"address","name":"owner","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"creator","type":"address"},{"indexed":true,"internalType":"address","name":"redirectTo","type":"address"}],"name":"Redirect","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"creatorOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"}],"name":"creatorRedirect","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"imageData","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"imageURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"name":"imagesData","outputs":[{"internalType":"bytes[]","name":"","type":"bytes[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"name":"mint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"mintFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"royaltyFraction","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"salePrice","type":"uint256"}],"name":"royaltyInfo","outputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"royaltyAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"setCreatorRedirect","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"val","type":"uint256"}],"name":"setMintFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"val","type":"uint256"}],"name":"setRoyaltyFraction","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"superOperator","type":"address"},{"internalType":"bool","name":"add","type":"bool"}],"name":"setSuperOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenExist","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]';
window.ANIMATIONS_ADDR = '0x1024AdA38162dD281Fc41814c11EEb5e29CD8CC9';
window.ANIMATIONS_ABI = '[{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"pixelsContract","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"creator","type":"address"},{"indexed":true,"internalType":"address","name":"redirectTo","type":"address"}],"name":"Redirect","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"creatorOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"}],"name":"creatorRedirect","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"imageData","outputs":[{"components":[{"internalType":"uint8","name":"interval","type":"uint8"},{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"internalType":"struct Animations.AnimationInfo","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"imageURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxFrames","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint8","name":"interval","type":"uint8"},{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"name":"mint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"mintFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"royaltyFraction","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"salePrice","type":"uint256"}],"name":"royaltyInfo","outputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"royaltyAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"setCreatorRedirect","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_maxFrames","type":"uint256"}],"name":"setMaxFrames","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"val","type":"uint256"}],"name":"setMintFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"val","type":"uint256"}],"name":"setRoyaltyFraction","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"superOperator","type":"address"},{"internalType":"bool","name":"add","type":"bool"}],"name":"setSuperOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenExist","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]';
window.INDEX_COLORS = [
'#ffc0c0', '#ffffc0', '#c0ffc0', '#00ffc0', '#c0ffff', '#80c0ff', '#c0c0ff', '#ffc0ff',
'#ff8080', '#ffff80', '#80ff80', '#00ff80', '#80ffff', '#0080ff', '#ff80c0', '#ff80ff',
'#ff0000', '#ffff00', '#80ff00', '#00ff40', '#00ffff', '#0080c0', '#8080c0', '#ff00ff',
'#c00000', '#ffc080', '#c08000', '#00c0c0', '#00c0ff', '#8040c0', '#804080', '#ff40c0',
'#804040', '#ff8040', '#00ff00', '#008080', '#004080', '#8080ff', '#800040', '#ff0080',
'#800000', '#ff8000', '#008000', '#008040', '#0000ff', '#0000a0', '#800080', '#8000ff',
'#400000', '#804000', '#004000', '#004040', '#000080', '#000040', '#400040', '#400080',
'#000000', '#808000', '#808040', '#808080', '#408080', '#c0c0c0', '#ffffff', 'transparent'
];
function toRGB(hex) {
if (hex.startsWith('#')) {
hex = hex.substring(1);
}
let rgb = parseInt(hex, 16);
return [(rgb & 0xff0000) >> 16, (rgb & 0xff00) >> 8, rgb & 0xff];
}
function convertRgbColors() {
let colors = [];
for (let i = 0; i < window.INDEX_COLORS.length - 1 /* skip last transparent color */; i++) {
colors.push(toRGB(window.INDEX_COLORS[i]));
}
return colors;
}
window.RGB_COLORS = convertRgbColors();
})();
function getWeb3Provider() {
if (!window.web3Provider) {
if (!window.ethereum) {
console.error("there is no web3 provider.");
return null;
}
window.web3Provider = new ethers.providers.Web3Provider(window.ethereum, "any");
}
return window.web3Provider;
}
function translateError(err) {
window.err = err;
if (typeof (err) === 'string') {
return err;
}
if (err.error && err.error.code && err.error.message) {
return `Error (${err.error.code}): ${err.error.message}`;
}
if (err.code && err.message) {
return `Error (${err.code}): ${err.message}`;
}
return err.message || err.toString();
}
</script>
<style>
div.autoclose {
position: fixed;
bottom: 50px;
left: 5%;
display: block;
width: 90%;
z-index: 999;
}
div.toolbar>div {
text-align: center;
}
div.toolbar button.btn-outline-secondary:hover {
color: #6c757d;
background-color: rgba(0, 0, 0, 0);
border-color: #6c757d;
}
div.toolbar button.btn {
margin: 5px;
}
div.toolbar button.btn:hover {
box-shadow: 0 0 2px 2px rgba(0, 0, 0, 0.1);
transform: scale(1.1);
transition: all 0.1s;
}
div.canvas {
position: relative;
width: 516px;
height: 516px;
border: 2px solid #ccc;
}
div.canvas>canvas {
position: absolute;
top: 0;
left: 0;
}
div.selected-colors {
position: relative;
display: block;
width: 100px;
height: 100px;
}
div.selected-colors>div {
border: 1px solid rgba(0, 0, 0, 0.5);
display: block;
width: 40px;
height: 40px;
}
div.selected-colors>div.fg-color {
position: absolute;
top: 0;
left: 0;
}
div.selected-colors>div.bg-color {
position: absolute;
top: 26px;
left: 26px;
}
div.selected-colors>a.switch-color {
position: absolute;
display: block;
width: 20px;
height: 20px;
top: 0px;
left: 44px;
}
div.palette {}
div.palette div.color {
cursor: pointer;
display: inline-block;
border: 1px solid rgba(0, 0, 0, 0.1);
width: 24px;
height: 24px;
margin: 0 10px 15px 0;
}
div.palette div.color:hover {
box-shadow: 0 0 2px 2px rgba(0, 0, 0, 0.2);
transform: scale(1.25);
transition: all 0.1s;
}
div.preview {}
div.preview img {
border: 2px solid rgba(0, 0, 0, 0.1);
width: 100px;
height: 100px;
image-rendering: pixelated;
margin-left: 30px;
margin-bottom: 10px;
}
div.preview button {
width: 160px;
}
.nav-link.active {
cursor: default;
border-bottom: 2px solid rgba(0, 0, 0, 0.9);
}
a {
text-decoration: none;
}
.x-border {
border: 1px solid #ced4da;
border-left: 0.25rem solid #5bc0de;
border-radius: 0.25rem;
padding: 1rem;
}
</style>
<script>
class ToolbarButton {
key;
title;
icon;
canPressed;
constructor(key, title, icon, canPressed) {
this.key = key;
this.title = title;
this.icon = icon;
this.canPressed = canPressed;
}
}
function findMatchedIndexColor(r, g, b, a) {
if (a < 128) {
return window.INDEX_COLORS.length - 1;
}
let
diff = 1000.0,
rgbColors = window.RGB_COLORS,
matched = 0;
for (let i = 0; i < rgbColors.length; i++) {
let
rgb = rgbColors[i]
d = Math.sqrt(Math.pow(rgb[0] - r, 2) + Math.pow(rgb[1] - g, 2) + Math.pow(rgb[2] - b, 2));
if (diff > d) {
diff = d;
matched = i;
}
}
return matched;
}
function buildPalette() {
let palette = [];
for (let i = 0; i < 8; i++) {
let cc = [];
for (let j = 0; j < 8; j++) {
cc.push(i * 8 + j);
}
palette.push(cc);
}
return palette;
}
function buildCanvasIndexes() {
let
defaultColor = window.INDEX_COLORS.length - 2, // white
indexes = [];
for (let i = 0; i < 32 * 32; i++) {
indexes.push(defaultColor);
}
return indexes;
}
function createTransparentTile() {
// create transparent tile:
let offscreen = document.createElement('canvas');
offscreen.width = 64;
offscreen.height = 64;
let g = offscreen.getContext('2d');
g.fillStyle = '#ffffff';
g.fillRect(0, 0, 64, 64);
g.fillStyle = '#cccccc';
for (let x = 0; x < 64; x += 8) {
for (let y = 0; y < 64; y += 8) {
g.fillRect(x, y, 4, 4);
}
}
for (let x = 4; x < 64; x += 8) {
for (let y = 4; y < 64; y += 8) {
g.fillRect(x, y, 4, 4);
}
}
return offscreen;
}
function init_vm() {
console.log('init vm...');
let
btnUndo = new ToolbarButton('undo', 'Undo', 'arrow-counterclockwise'),
btnRedo = new ToolbarButton('redo', 'Redo', 'arrow-clockwise'),
btnCopy = new ToolbarButton('copy', 'Copy', 'back'),
btnPaste = new ToolbarButton('paste', 'Paste', 'clipboard-plus'),
btnEraser = new ToolbarButton('eraser', 'Eraser', 'eraser-fill', true),
btnFill = new ToolbarButton('fill', 'Fill', 'paint-bucket', true),
btnPick = new ToolbarButton('pick', 'Pick Color', 'eyedropper', true),
btnPencil = new ToolbarButton('pencil', 'Pencil', 'pencil', true),
btnLine = new ToolbarButton('line', 'Line', 'slash-lg', true),
btnRect = new ToolbarButton('rect', 'Rectangle', 'square', true),
btnMoveUp = new ToolbarButton('move_up', 'Move Up', 'arrow-up'),
btnMoveLeft = new ToolbarButton('move_left', 'Move Left', 'arrow-left'),
btnMoveRight = new ToolbarButton('move_right', 'Move Right', 'arrow-right'),
btnMoveDown = new ToolbarButton('move_down', 'Move Down', 'arrow-down'),
toolbar = [
[btnUndo, btnRedo,
btnCopy, btnPaste,
btnEraser, btnFill,
btnPick, btnPencil],
// btnLine, btnRect,
[btnMoveUp],
[btnMoveLeft, btnMoveRight],
[btnMoveDown]
],
buttons = [];
for (let bgroup of toolbar) {
for (let btn of bgroup) {
buttons[btn.key] = btn;
}
}
window.vm = new Vue({
el: '#vm',
data: {
account: null,
undoList: [],
redoList: [],
toolbar: toolbar,
buttons: buttons,
canvas: null,
pressedButton: btnPencil,
palette: buildPalette(),
indexTransparent: window.INDEX_COLORS.length - 1,
canvasIndexes: buildCanvasIndexes(),
fgIndex: window.INDEX_COLORS.indexOf('#000000'),
bgIndex: window.INDEX_COLORS.indexOf('#ffffff'),
transparentTile: null,
transparentTileUrl: null,
version: 0
},
computed: {
transparentIndex: function () {
return window.INDEX_COLORS.length - 1;
}
},
methods: {
isDisabled: function (key) {
if (key === 'undo') {
return this.undoList.length === 0;
}
if (key === 'redo') {
return this.redoList.length === 0;
}
return false;
},
createSnapshot: function () {
return this.canvasIndexes.slice(0, 1024);
},
createUndo: function () {
let snapshot = this.createSnapshot();
this.undoList.push(snapshot);
this.redoList = [];
},
pasteImage: async function () {
if (navigator.clipboard) {
try {
let contents = await navigator.clipboard.read();
let foundImage = false;
for (const item of contents) {
if (item.types.includes('image/png')) {
console.log('paste png...');
const blob = await item.getType('image/png');
let that = this;
let img = new Image();
img.onload = function () {
console.log('draw canvas...');
let offscreen = document.createElement('canvas');
offscreen.width = 32;
offscreen.height = 32;
let g = offscreen.getContext('2d');
g.drawImage(img, 0, 0, img.width, img.height, 0, 0, 32, 32);
let iData = g.getImageData(0, 0, 32, 32);
that.createUndo();
// find rgba:
let
data = iData.data,
dataLength = data.length;
for (let i = 0; i < dataLength; i += 4) {
let
r = data[i],
g = data[i + 1],
b = data[i + 2],
a = data[i + 3],
matchedIndex = findMatchedIndexColor(r, g, b, a);
that.canvasIndexes[i / 4] = matchedIndex;
}
that.drawCanvas();
that.version++;
showTip('Image was pasted from clipboard.');
}
img.src = URL.createObjectURL(blob);
foundImage = true;
break;
}
}
if (!foundImage) {
showTip('There is no image in clipboard.', true);
}
} catch (err) {
showTip('Your browser does not support read from clipboard.', true);
}
} else {
showTip('Your browser does not support read from clipboard.', true);
}
},
range: function (n) {
let r = [];
for (let i = 0; i < n; i++) {
r.push(i);
}
return r;
},
selectColor: function (index, isBg) {
if (isBg) {
this.bgIndex = index;
} else {
this.fgIndex = index;
}
},
toolbarButtonClick: function (key) {
console.log('button clicked: ' + key);
let btn = this.buttons[key];
if (btn.canPressed) {
if (this.pressedButton === btn) {
this.pressedButton = null;
} else {
this.pressedButton = btn;
}
} else {
let key = btn.key;
if (key === 'copy') {
try {
if (!window.ClipboardItem) {
throw 'not support';
}
let gifData = 'data:image/gif;base64,' +
base64js.fromByteArray(this.genGIF());
let img = document.createElement('img');
img.width = 32; img.height = 32;
img.onload = function () {
let offscreen = document.createElement('canvas');
offscreen.width = 32;
offscreen.height = 32;
let g = offscreen.getContext('2d');
g.drawImage(img, 0, 0, img.width, img.height, 0, 0, 32, 32);
offscreen.toBlob(blob => navigator.clipboard.write([new ClipboardItem({ 'image/png': blob })]));
showTip('Image was copied to clipboard.');
};
img.src = gifData;
} catch (err) {
showTip('Your browser does not support write to clipboard.', true);
}
}
else if (key === 'paste') {
this.pasteImage();
} else if (key === 'undo') {
let current = this.createSnapshot();
this.redoList.push(current);
this.canvasIndexes = this.undoList.pop();
this.drawCanvas();
this.version++;
} else if (key === 'redo') {
let current = this.createSnapshot();
this.undoList.push(current);
this.canvasIndexes = this.redoList.pop();
this.drawCanvas();
this.version++;
} else if (key.startsWith('move_')) {
this.createUndo();
let
dir = key.substring(5),
current = this.createSnapshot(),
bgColor = this.bgIndex;
if (dir === 'up') {
current = current.slice(32, 1024);
current = current.concat(Array(32).fill(bgColor));
} else if (dir === 'down') {
current = current.slice(0, 1024 - 32);
current = Array(32).fill(bgColor).concat(current);
} else {
let
fillLeft = dir === 'right',
empty = current.slice(0, 1024);
for (let y = 0; y < 32; y++) {
let offset = y * 32;
if (fillLeft) {
empty[offset] = bgColor;
for (let x = 1; x < 32; x++) {
empty[offset + x] = current[offset + x - 1];
}
} else {
empty[offset + 31] = bgColor;
for (let x = 0; x < 31; x++) {
empty[offset + x] = current[offset + x + 1];
}
}
}
current = empty;
}
this.canvasIndexes = current;
this.drawCanvas();
this.version++;
}
}
},
switchColor: function () {
// switch bg / fg color:
let bg = this.bgIndex;
this.bgIndex = this.fgIndex;
this.fgIndex = bg;
},
indexColor: function (index) {
return window.INDEX_COLORS[index];
},
pointColorIndex: function (x, y) {
return this.canvasIndexes[y * 32 + x];
},
pointColor: function (x, y) {
return this.indexColor(this.pointColorIndex(x, y));
},
drawCanvas: function () {
let
x, y,
g = this.canvas.getContext('2d');
g.imageSmoothingEnabled = false;
for (y = 0; y < 32; y++) {
for (x = 0; x < 32; x++) {
this.drawPoint(x, y, g);
}
}
},
drawPoint: function (x, y, g) {
let
tile = 16,
index = this.canvasIndexes[y * 32 + x];
if (!g) {
g = this.canvas.getContext('2d');
}
if (index !== this.indexTransparent) {
g.fillStyle = window.INDEX_COLORS[index];
g.fillRect(x * tile, y * tile, tile, tile);
} else {
g.putImageData(this.transparentTile, x * tile, y * tile);
}
},
setPoint: function (x, y, isRight) {
let
index = y * 32 + x,
key = this.pressedButton ? this.pressedButton.key : '';
console.log(`${key}: ${x}, ${y}`);
if (key === 'pencil') {
let
oldColor = this.canvasIndexes[index],
newColor = isRight ? this.bgIndex : this.fgIndex;
if (oldColor !== newColor) {
this.createUndo();
this.canvasIndexes[index] = newColor;
this.drawPoint(x, y);
this.version++;
}
} else if (key === 'eraser') {
let
oldColor = this.canvasIndexes[index],
newColor = this.bgIndex;
if (oldColor !== newColor) {
this.createUndo();
this.canvasIndexes[index] = newColor;
this.drawPoint(x, y);
this.version++;
}
} else if (key === 'pick') {
if (isRight) {
this.bgIndex = this.canvasIndexes[index];
} else {
this.fgIndex = this.canvasIndexes[index];
}
} else if (key === 'fill') {
let
fromColorIndex = this.canvasIndexes[index],
toColorIndex = isRight ? this.bgIndex : this.fgIndex;
if (fromColorIndex !== toColorIndex) {
this.createUndo();
this.fillCanvas(x, y, fromColorIndex, toColorIndex, []);
this.drawCanvas();
this.version++;
}
}
},
fillCanvas: function (x, y, fromColorIndex, toColorIndex, marks) {
// 1st: set current point:
let index = y * 32 + x;
if (!marks[index] && this.canvasIndexes[index] === fromColorIndex) {
this.canvasIndexes[index] = toColorIndex;
marks[index] = true;
// check top:
if (y > 0) {
this.fillCanvas(x, y - 1, fromColorIndex, toColorIndex, marks);
}
// check left:
if (x > 0) {
this.fillCanvas(x - 1, y, fromColorIndex, toColorIndex, marks);
}
// check bottom:
if (y < 31) {
this.fillCanvas(x, y + 1, fromColorIndex, toColorIndex, marks);
}
// check right:
if (x < 31) {
this.fillCanvas(x + 1, y, fromColorIndex, toColorIndex, marks);
}
}
},
genGIF: function () {
let
GIF_PIXEL_PREFIX = '2180',
GIF_END = '0181003b',
GIF_START = '0x' +
'47494638396120002000f53f00ffc0c0ffffc0c0ffc000ffc0c0ffff80c0ffc0' +
'c0ffffc0ffff8080ffff8080ff8000ff8080ffff0080ffff80c0ff80ffff0000' +
'ffff0080ff0000ff4000ffff0080c08080c0ff00ffc00000ffc080c0800000c0' +
'c000c0ff8040c0804080ff40c0804040ff804000ff000080800040808080ff80' +
'0040ff0080800000ff80000080000080400000ff0000a08000808000ff400000' +
'8040000040000040400000800000404000404000800000008080008080408080' +
'80408080c0c0c0ffffff11111121ff0b4e45545343415045322e300301000000' +
'21f9041100003f002c00000000200020000007';
let
arr = this.createSnapshot(),
gif = GIF_START;
for (let y = 0; y < 32; y++) {
let line = '';
for (let x = 0; x < 32; x++) {
let c = arr[y * 32 + x];
let hex = (c < 16 ? '0' + c.toString(16) : c.toString(16));
line = line + hex;
}
gif = gif + GIF_PIXEL_PREFIX + line;
}
gif += GIF_END;
return ethers.utils.arrayify(gif);
},
download: function () {
let gifData = 'data:application/octet-stream;base64,' +
base64js.fromByteArray(this.genGIF());
let a = document.createElement('a');
a.href = gifData;
a.download = '1024pixels.gif';
a.click();
},
createNFT: async function () {
if (!window.vm_wallet.ready) {
return showAlert('Error', 'Please connect to wallet with ' + window.CHAIN_NAME + ' !');
}
let
arr = this.createSnapshot(),
hexData = '0x';
for (let i = 0; i < 1024; i++) {
let c = arr[i];
hexData = hexData + (c < 16 ? '0' + c.toString(16) : c.toString(16));
}
let tokenId = ethers.utils.keccak256(hexData);
// check token exist:
let loading = showLoading('Prepare Create NFT', 'Check NFT token ID...');
try {
let contract = new ethers.Contract(window.PIXELS_ADDR, window.PIXELS_ABI, window.getWeb3Provider().getSigner());
let exist = await contract.tokenExist(tokenId);
if (exist) {
throw 'This pixels art is already minted.';
}
loading.setMessage('Get mint fee...');
let fee = await contract.mintFee();
loading.setMessage('Please sign the mint transaction in MetaMask...');
let tx = await contract.mint(hexData, { value: fee });
loading.setMessage('Please wait for blockchain confirmation...');
await tx.wait(1);
loading.close();
let
urlText = window.OPENSEA_URL + '0x...',
url = window.OPENSEA_URL + window.PIXELS_ADDR + '/' + ethers.BigNumber.from(tokenId).toString();
showInfo('Success', '<p>The 1024 Pixels Art was created successfully!</p><p>You should find the NFT on OpenSea shortly: </p><p><a target="_blank" href="' +
url + '">' + urlText + ' <i class="bi bi-box-arrow-up-right"></i></a></p>');
} catch (err) {
loading.close();
return showAlert('Error', translateError(err));
}
},
accountChanged: function (account) {
this.account = account;
}
},
watch: {
version: function (val, oldVal) {
let
last = val,
that = this;
setTimeout(function () {
if (that.version === last) {
// version not changed
$('#imgPreview').attr('src', that.canvas.toDataURL());
$('#linkFavicon').attr('href', that.canvas.toDataURL("image/x-icon"));
}
}, 1000);
setTimeout(function () {
if (that.version === last) {
// version not changed
let data = JSON.stringify(that.createSnapshot());
localStorage.setItem('image', data);
console.log('image saved at version ' + last);
}
}, 3000);
}
},
mounted: function () {
// create transparent tile:
let offscreen = createTransparentTile();
this.transparentTile = offscreen.getContext('2d').getImageData(0, 0, 16, 16);
this.transparentTileUrl = 'url(' + offscreen.toDataURL() + ')';
// draw grid on gridCanvas:
{
let
x, y,
size = 512,
tile = size >> 5,
gridCanvas = document.getElementById('gridCanvas'),
g = gridCanvas.getContext('2d');
g.imageSmoothingEnabled = false;
g.fillStyle = 'rgba(0,0,0,0)';
g.fillRect(0, 0, size, size);
// draw lines:
g.strokeStyle = 'rgba(0,0,0,0.1)';
g.lineWidth = 1;
g.beginPath();
for (y = 1; y < 32; y++) {
g.moveTo(0, y * tile);
g.lineTo(size, y * tile);
}
for (x = 1; x < 32; x++) {
g.moveTo(x * tile, 0);
g.lineTo(x * tile, size);
}
g.closePath();
g.stroke();
// init mouse event:
let that = this;
gridCanvas.addEventListener('contextmenu', (event) => {
event.preventDefault();
});
let mvFn = (event) => {
let
b = event.buttons,
ox = event.offsetX,
oy = event.offsetY;
if (ox >= 0 && oy >= 0 && b > 0) {
let
x = (ox & 0x1ff) >> 4,
y = (oy & 0x1ff) >> 4;
that.setPoint(x, y, b === 2);
}
};
gridCanvas.addEventListener('mousemove', mvFn);
gridCanvas.addEventListener('mousedown', mvFn);
gridCanvas.addEventListener('mouseup', (event) => {
console.log(event.offsetX, event.offsetY, event.buttons);
});
}
// try load storage:
let data = localStorage.getItem('image');
if (data) {
try {
let
hasError = false,
arr = JSON.parse(data);
if (Array.isArray(arr) && arr.length === 1024) {
for (let i = 0; i < 1024; i++) {
let n = arr[i];
if (!Number.isInteger(n)) {
hasError = true;
break;
}
if (n < 0 || n >= 64) {
hasError = true;
break;
}
}
if (!hasError) {
this.canvasIndexes = arr;
console.log('load image from storage ok.');
}
}
} catch (err) {
console.error('failed load from storage.', err);
}
}
this.canvas = document.getElementById('mainCanvas');
this.drawCanvas();
this.version++;
}
});
}
</script>
</head>
<body>
<script>
// show dialogs:
function showAlert(title, message) {
let m = $('#alertModal');
m.find('.x-title').text(title);
m.find('.x-message').text(message);
let myModal = new bootstrap.Modal(m.get(0), { backdrop: 'static', keyboard: false });
myModal.show();
}
function showInfo(title, message) {
let m = $('#infoModal');
m.find('.x-title').text(title);
if (message.startsWith('<')) {
m.find('.x-message').html(message);
} else {
m.find('.x-message').text(message);
}
let myModal = new bootstrap.Modal(m.get(0), { backdrop: 'static', keyboard: false });
myModal.show();
}
function showLoading(title, message) {
let m = $('#loadingModal');
let myModal = new bootstrap.Modal(m.get(0), { backdrop: 'static', keyboard: false });
let obj = {
setTitle: (t) => {
m.find('.x-title').text(t);
},
setMessage: (t) => {
m.find('.x-message').text(t);
},
close: () => {
setTimeout(function () {
myModal.hide();
}, 500);
}
}
obj.setTitle(title);
obj.setMessage(message);
myModal.show();
return obj;
}
function showTip(msg, isError) {
let $div = $('<div/>');
$div.addClass('alert');
$div.addClass(isError ? 'alert-danger' : 'alert-success');
$div.text(msg);
$div.css('display', 'none');
$('#tips').prepend($div);
$div.fadeIn().delay(2000).fadeOut();
}
</script>
<!-- Loading Modal -->
<div id="loadingModal" class="modal fade" role="dialog" aria-hidden="true" aria-labelledby="loadingLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header align-items-center d-flex">
<h4 class="modal-title x-title" id="loadingLabel"> </h4>
</div>
<div class="modal-body">
<div class="float-start">
<div class="spinner-border" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
<div class="ms-5 ps-4 float-none">
<p class="x-message"> </p>
</div>
</div>
<!-- <div class="modal-footer">
<button class="btn btn-outline-primary" data-bs-dismiss="modal" aria-label="Close">Cancel</button>
</div> -->
</div>
</div>
</div>
<!-- Alert Modal -->
<div id="alertModal" class="modal fade" role="dialog" aria-hidden="true" aria-labelledby="alertLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header align-items-center d-flex">
<h4 class="modal-title x-title" id="alertLabel"> </h4>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close">
<span aria-hidden="true"><i class="fe fe-x-circle"></i></span>
</button>
</div>
<div class="modal-body">
<div class="float-start">
<i class="fs-2 text-danger fe fe-alert-triangle"></i>
</div>
<div class="ms-5 ps-4 float-none">
<p class="x-message"> </p>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-outline-primary" data-bs-dismiss="modal" aria-label="Close">OK</button>
</div>
</div>
</div>
</div>
<!-- Info Modal -->
<div id="infoModal" class="modal fade" role="dialog" aria-hidden="true" aria-labelledby="infoLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header align-items-center d-flex">
<h4 class="modal-title x-title" id="infoLabel"> </h4>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close">
<span aria-hidden="true"><i class="fe fe-x-circle"></i></span>
</button>
</div>
<div class="modal-body">
<div class="float-start">
<i class="fs-2 fe fe-info"></i>
</div>
<div class="ms-5 ps-4 float-none">
<p class="x-message"> </p>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-outline-primary" data-bs-dismiss="modal" aria-label="Close">OK</button>
</div>
</div>
</div>
</div>
<div id="tips" class="autoclose">
</div>
<script>
$(function () {
console.log('init wallet...');
window.vm_wallet = new Vue({
el: '#vm_wallet',
data: {
account: null,
chainId: 0
},
computed: {
marketUrl: function () {
return window.MARKET_URL;
},
ready: function () {
return this.account && this.chainId === window.CHAIN_ID;
},
networkName: function () {
return window.CHAIN_NAME;
},
wrongNetworkName: function () {
return 'Unsupported Chain (' + this.chainId + ')';
},
wrongNetwork: function () {
return this.chainId !== window.CHAIN_ID;
}
},
methods: {
abbrAddress: function (addr) {
if (!addr) {
return '';
}
let s = addr.toString();
if (s.indexOf('0x') === 0 && s.length === 42) {
let addr = ethers.utils.getAddress(s.substring(0));
return addr.substring(0, 6) + '...' + addr.substring(38);
}
return s;
},
gotoScanUrl: function () {
window.open(window.SCAN_URL + '/address/' + this.account);