-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleaderboard.html
More file actions
946 lines (923 loc) · 33.5 KB
/
leaderboard.html
File metadata and controls
946 lines (923 loc) · 33.5 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="SnappQuest - Leaderboard">
<title>SnappQuest - Leaderboard</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" rel="stylesheet" onerror="console.error('Font Awesome failed to load')">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}
body {
background-color: #F9FAFB;
color: #1F2937;
line-height: 1.6;
font-size: 16px;
margin: 0;
overflow-x: hidden;
}
header {
background: rgba(31, 41, 55, 0.9);
backdrop-filter: blur(12px);
padding: 16px 24px;
display: flex;
align-items: center;
justify-content: space-between;
position: sticky;
top: 0;
z-index: 1000;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.logo img {
width: 100%;
max-width: 140px;
height: auto;
filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}
.nav-container {
display: flex;
align-items: center;
gap: 24px;
}
.nav-links {
display: flex;
gap: 24px;
}
.nav-links a {
color: #ffffff;
text-decoration: none;
font-size: 16px;
font-weight: 500;
position: relative;
transition: transform 0.3s ease, color 0.3s ease;
background: linear-gradient(90deg, #34D399, #FBBF24);
-webkit-background-clip: text;
background-clip: text;
color: transparent;
}
.nav-links a::after {
content: '';
position: absolute;
width: 0;
height: 2px;
bottom: -4px;
left: 0;
background: linear-gradient(90deg, #34D399, #FBBF24);
transition: width 0.3s ease;
}
.nav-links a:hover::after {
width: 100%;
}
.nav-links a:hover {
transform: translateY(-2px);
}
.nav-links a:active {
transform: scale(0.95);
}
.disconnect-btn {
background: #EF4444;
color: #ffffff;
border: none;
padding: 10px 20px;
border-radius: 8px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
white-space: nowrap;
}
.disconnect-btn:hover {
background: #DC2626;
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
.disconnect-btn:active {
transform: scale(0.95);
}
.hamburger {
display: none;
font-size: 24px;
color: #ffffff;
cursor: pointer;
z-index: 1001;
transition: transform 0.3s ease;
}
.hamburger.active {
transform: rotate(90deg);
}
@media (max-width: 768px) {
.nav-container {
display: none;
flex-direction: column;
position: fixed;
top: 0;
right: 0;
height: 100vh;
width: 280px;
background: rgba(31, 41, 55, 0.95);
backdrop-filter: blur(10px);
padding: 80px 24px 24px;
transform: translateX(100%);
transition: transform 0.3s ease-in-out;
box-shadow: -4px 0 12px rgba(0, 0, 0, 0.3);
}
.nav-container.active {
display: flex;
transform: translateX(0);
}
.nav-links {
flex-direction: column;
width: 100%;
}
.nav-links a {
font-size: 18px;
padding: 16px 0;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
text-align: left;
width: 100%;
background: none;
color: #ffffff;
transition: background-color 0.3s ease, transform 0.3s ease;
}
.nav-links a:hover {
background: rgba(255, 255, 255, 0.1);
transform: translateX(4px);
}
.disconnect-btn {
margin-top: 24px;
width: 100%;
padding: 16px;
font-size: 18px;
}
.hamburger {
display: block;
}
.overlay {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.6);
z-index: 999;
}
.overlay.active {
display: block;
}
}
.leaderboard-container {
max-width: 1200px;
margin: 0 auto;
padding: 40px 24px;
}
.leaderboard-header {
text-align: center;
margin-bottom: 32px;
}
.leaderboard-header h2 {
font-size: 28px;
font-weight: 700;
color: #1F2937;
margin-bottom: 16px;
}
.back-btn {
background: #6B7280;
color: #ffffff;
border: none;
padding: 12px 24px;
border-radius: 8px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
display: inline-block;
text-align: center;
text-decoration: none;
}
.back-btn:hover {
background: #4B5563;
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
.back-btn:active {
transform: scale(0.95);
}
.leaderboard-table {
width: 100%;
border-collapse: collapse;
background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(52, 211, 153, 0.1));
border-radius: 16px;
overflow: hidden;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
.leaderboard-table th,
.leaderboard-table td {
padding: 16px;
text-align: left;
font-size: 16px;
}
.leaderboard-table th {
background: linear-gradient(135deg, #6366F1, #34D399);
color: #ffffff;
font-weight: 600;
}
.leaderboard-table tr:nth-child(even) {
background: rgba(255, 255, 255, 0.8);
}
.leaderboard-table tr:nth-child(odd) {
background: rgba(243, 244, 246, 0.8);
}
.leaderboard-table tr:hover {
background: rgba(209, 213, 219, 0.5);
transform: translateY(-2px);
transition: all 0.3s ease;
}
.leaderboard-table .rank {
font-weight: 700;
color: #34D399;
}
.error-message {
color: #EF4444;
font-size: 14px;
text-align: center;
margin: 16px 0;
display: none;
}
.error-message.show {
display: block;
}
.currency-switch {
display: flex;
align-items: center;
gap: 12px;
margin-top: 20px;
justify-content: center;
}
.currency-switch input[type="checkbox"] {
display: none;
}
.currency-switch label {
position: relative;
width: 60px;
height: 28px;
background: #E5E7EB;
border-radius: 14px;
cursor: pointer;
transition: background 0.3s ease;
}
.currency-switch label::before {
content: '';
position: absolute;
width: 24px;
height: 24px;
background: #ffffff;
border-radius: 50%;
top: 2px;
left: 2px;
transition: transform 0.3s ease;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.currency-switch input:checked + label {
background: linear-gradient(135deg, #6366F1, #34D399);
}
.currency-switch input:checked + label::before {
transform: translateX(32px);
}
.currency-switch span {
font-size: 14px;
font-weight: 500;
color: #1F2937;
}
.currency-switch .ngn-label {
color: #6B7280;
}
.currency-switch .usdc-label {
color: #6B7280;
}
.currency-switch input:checked ~ .ngn-label {
color: #1F2937;
}
.currency-switch input:not(:checked) ~ .usdc-label {
color: #1F2937;
}
footer {
background: linear-gradient(135deg, #1F2937, #111827);
color: #E5E7EB;
padding: 60px 60px;
border-top: 1px solid rgba(255, 255, 255, 0.1); ;
text-align: left;
position: relative;
overflow: hidden;
}
.footer-row {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
gap: 40px;
margin-bottom: 40px;
}
.footer-col {
min-width: 150px;
}
.footer-col h3 {
font-size: 18px;
font-weight: 700;
margin-bottom: 16px;
color: var(--color-text-primary);
}
.footer-link li {
margin-bottom: 10px;
list-style: none;
}
.footer-link a {
color: var(--color-text-secondary);
font-size: 14px;
display: flex;
align-items: center;
gap: 8px;
text-decoration: none;
}
.footer-link a:hover {
color: var(--color-teal);
transform: translateX(3px);
}
.social-icons a {
font-size: 20px;
margin-right: 15px;
color: var(--color-text-secondary);
}
.social-icons a:hover {
color: var(--color-indigo);
}
.footer-bottom {
text-align: center;
padding-top: 20px;
border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.footer-bottom p {
font-size: 12px;
color: var(--color-text-secondary);
margin: 0;
}
.copyright-text p {
font-size: 12px;
margin: 0;
opacity: 0.9;
}
#back-to-top {
position: fixed;
bottom: 32px;
right: 32px;
z-index: 1000;
background: linear-gradient(135deg, #6366F1, #34D399);
color: #ffffff;
width: 56px;
height: 56px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
opacity: 0;
visibility: hidden;
transition: all 0.4s ease;
cursor: pointer;
animation: pulseButton 2s ease-in-out infinite;
}
@keyframes pulseButton {
0%, 100% {
transform: scale(1);
}
50% {
transform: scale(1.1);
}
}
#back-to-top.visible {
opacity: 1;
visibility: visible;
}
#back-to-top:hover {
transform: translateY(-6px);
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3), 0 0 15px rgba(52, 211, 153, 0.5);
}
#back-to-top i {
font-size: 24px;
}
.modal {
display: none;
position: fixed;
z-index: 1000;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background: rgba(0, 0, 0, 0.7);
padding-top: 80px;
opacity: 0;
transition: opacity 0.4s ease-in-out;
}
.modal.active {
opacity: 1;
}
.modal-content {
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(10px);
margin: 5% auto;
padding: 0;
width: 80%;
max-width: 720px;
border-radius: 20px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
transform: translateY(-60px);
transition: transform 0.4s ease-in-out, opacity 0.4s ease-in-out;
opacity: 0;
}
.modal.active .modal-content {
transform: translateY(0);
opacity: 1;
}
.modal-header {
background: linear-gradient(135deg, #6366F1, #34D399);
color: #ffffff;
padding: 24px;
border-radius: 20px 20px 0 0;
font-size: 28px;
font-weight: 700;
display: flex;
justify-content: space-between;
align-items: center;
}
.modal-body {
padding: 32px;
font-size: 16px;
color: #1F2937;
}
.modal-body h3 {
font-size: 22px;
font-weight: 600;
margin-bottom: 12px;
color: #111827;
}
.modal-body p {
margin-bottom: 24px;
font-size: 16px;
line-height: 1.8;
color: #4B5563;
}
.modal-body ul {
list-style: none;
padding-left: 0;
margin-bottom: 24px;
}
.modal-body ul li {
position: relative;
padding-left: 28px;
margin-bottom: 12px;
font-size: 16px;
color: #4B5563;
}
.modal-body ul li::before {
content: '\f00c';
font-family: 'Font Awesome 6 Free';
font-weight: 900;
color: #34D399;
position: absolute;
left: 0;
top: 4px;
}
.modal-body a {
color: #6366F1;
text-decoration: none;
font-weight: 600;
transition: color 0.3s ease;
}
.modal-body a:hover {
color: #34D399;
}
.close {
color: #ffffff;
font-size: 28px;
font-weight: bold;
cursor: pointer;
transition: transform 0.3s ease, color 0.3s ease;
}
.close:hover,
.close:focus {
color: #E5E7EB;
transform: scale(1.2);
}
.modal-close-btn {
background: linear-gradient(135deg, #6366F1, #34D399);
color: #ffffff;
border: none;
padding: 12px 24px;
border-radius: 12px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
margin-top: 24px;
display: inline-block;
}
.modal-close-btn:hover {
background: linear-gradient(135deg, #4F46E5, #22C55E);
transform: translateY(-3px);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
@media (max-width: 768px) {
.leaderboard-table th,
.leaderboard-table td {
padding: 12px;
font-size: 14px;
}
.leaderboard-header h2 {
font-size: 24px;
}
.modal-content {
width: 90%;
border-radius: 16px;
}
.modal-header {
font-size: 24px;
padding: 20px;
}
.modal-body {
padding: 24px;
}
.modal-body h3 {
font-size: 20px;
}
.modal-body p,
.modal-body ul li {
font-size: 14px;
}
.modal-close-btn {
padding: 10px 20px;
font-size: 14px;
}
.currency-switch label {
width: 50px;
height: 24px;
}
.currency-switch label::before {
width: 20px;
height: 20px;
top: 2px;
left: 2px;
}
.currency-switch input:checked + label::before {
transform: translateX(26px);
}
.currency-switch span {
font-size: 12px;
}
}
</style>
<link href="images/icon.png" rel="icon" onerror="console.error('Favicon failed to load')">
</head>
<body>
<header>
<div class="logo">
<a href="index.html"><img src="images/logo.png" alt="SnappQuest Logo" onerror="console.error('Logo image failed to load')"></a>
</div>
<div class="nav-container">
<nav class="nav-links">
<a href="profile.html"><i class="fas fa-user"></i> Profile</a>
<a href="balance.html"><i class="fas fa-wallet"></i> Check Your Balance</a>
</nav>
<button class="disconnect-btn" id="disconnectBtn"><i class="fas fa-sign-out-alt"></i> Home</button>
</div>
<div class="hamburger">
<i class="fas fa-bars"></i>
</div>
</header>
<div class="overlay"></div>
<div class="leaderboard-container">
<div class="leaderboard-header">
<h2><i class="fas fa-medal"></i> SnappQuest Leaderboard</h2>
<a href="profile.html" class="back-btn">Back to Profile</a>
<p></p>
</div>
<div class="currency-switch">
<span class="usdc-label">NGN</span>
<input type="checkbox" id="currencyToggle">
<label for="currencyToggle"></label>
<span class="ngn-label">USDC</span>
</div>
<br>
<div class="error-message" id="errorMessage"></div>
<table class="leaderboard-table" id="leaderboardTable">
<thead>
<tr>
<th>Rank</th>
<th>Name</th>
<th>Total Earnings</th>
<th>Total Quests Completed</th>
</tr>
</thead>
<tbody id="leaderboardBody"></tbody>
</table>
</div>
<footer>
<div class="container">
<div class="footer-row">
<div class="footer-col" style="min-width: 250px;">
<h3 class="hero-gradient-text">SnappQuest</h3>
<p style="color: var(--color-text-secondary); font-size: 14px;">The Engage-to-Earn Business Solution.<br>Building active, incentivized, sustainable communities.</p>
<div class="social-icons">
<a href="https://x.com/SnappQuest" target="_blank"><i class="fab fa-twitter"></i></a>
<a href="https://t.me/SnappQuest" target="_blank"><i class="fab fa-telegram-plane"></i></a>
</div>
</div>
<div class="footer-col">
<h3>Explore</h3>
<ul class="footer-link">
<li><a href="#hero">Home</a></li>
<li><a href="card.html">Explore Quest</a></li>
</ul>
</div>
<div class="footer-col">
<h3>Other Tools</h3>
<ul class="footer-link">
<li><a href="card.html"><i class="fas fa-gift"></i> Gift Card</a></li>
</ul>
</div>
</div>
<div class="footer-bottom">
<p>© <span id="currentYear"></span> SnappQuest. All rights reserved. Powered by Neroitech Inventions.</p>
</div>
</div>
</footer>
<button id="back-to-top" title="Back to Top">
<i class="fas fa-arrow-up"></i>
</button><!--
<div id="learnMoreModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h2>SnappQuest Overview</h2>
<span class="close">×</span>
</div>
<div class="modal-body">
<h3>Vision</h3>
<p>SnappQuest exists to become the Engage-to-Earn tool for Superteam Nigeria and the Solana ecosystem, rewarding effort, not just outcomes.</p>
<h3>Mission</h3>
<p>To unlock quick earning opportunities for the SnappQuest community, while providing sponsors with real engagement in return.</p>
<h3>The Problem</h3>
<p>New projects and the Solana community struggle to gain visibility, while communities show up but often don't get rewarded.</p>
<h3>The Solution: SnappQuest</h3>
<p>SnappQuest is a tool that incentivizes participation, turning effort into recognition, rewards, and earning opportunities.</p>
<h3>How SnappQuest Works</h3>
<p>Create your Quest, generate the quote, and after payment, submit the new Quest for admin approval. Admins verify the Quest, if it’s legitimate, they move it to the active Quests for community participation.</p>
<h3>Key Features</h3>
<ul>
<li>Real engagement</li>
<li>No bots</li>
<li>Community powered</li>
</ul>
<h3>Long-Term Vision</h3>
<p>SnappQuest becomes the go-to tool for engagement across Solana, helping contributors, builders, and communities thrive.</p>
<button class="modal-close-btn">Close</button>
</div>
</div>
</div>-->
<script> // Set current year in footer
document.getElementById('currentYear').textContent = new Date().getFullYear(); </script>
<script>
// Configuration
const CONFIG = {
API_KEY: 'AIzaSyCs8fSiITdfU4WyZRgKsWRlbhAKeJaVC0Q',
SPREADSHEET_ID: '1kyUzw6Dx3LDosQwpTmqp2cxEM846tir6CxiN1t6-eOA',
RANGE: 'Form responses 3!A1:K1000',
STATS_ID: '1Wa2KMPLPp-egHpifo_aG1yM2_srqhgv4HYMw3z8lC0w',
RATE_RANGE: 'SnappQuestData!D2:D2',
FALLBACK_RATE: 1500
};
// State
let currentCurrency = 'NGN';
let usdcRate = 0;
let leaderboardData = [];
// DOM Elements
const DOM = {
leaderboardBody: document.getElementById('leaderboardBody'),
errorMessage: document.getElementById('errorMessage'),
hamburger: document.querySelector('.hamburger'),
navContainer: document.querySelector('.nav-container'),
overlay: document.querySelector('.overlay'),
disconnectBtn: document.getElementById('disconnectBtn'),
backToTopButton: document.getElementById('back-to-top'),
//learnMoreModal: document.getElementById('learnMoreModal'),
//learnMoreLink: document.getElementById('learn-more-link'),
closeButtons: document.querySelectorAll('.close, .modal-close-btn'),
currencyToggle: document.getElementById('currencyToggle')
};
// Fetch data from Google Sheets
async function fetchSheetData(spreadsheetId, range) {
const url = `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values/${range}?key=${CONFIG.API_KEY}`;
try {
const response = await fetch(url);
if (!response.ok) {
const errorText = await response.text();
throw new Error(`HTTP ${response.status}: ${errorText}`);
}
const data = await response.json();
if (data.error) throw new Error(data.error.message);
if (!data.values?.length) throw new Error(`No data in ${range}`);
if (range === CONFIG.RATE_RANGE) {
const rawValue = data.values[0][0];
console.log(`Raw value from SnappQuestData!D2: "${rawValue}"`);
return rawValue;
}
const headers = data.values[0].map(h => h.trim());
return data.values.slice(1).map(row => {
const obj = {};
headers.forEach((header, i) => { obj[header] = (row[i] || '').trim(); });
return obj;
});
} catch (error) {
console.error(`Fetch error for ${range}:`, error);
showError(`Failed to load ${range.split('!')[0]} data: ${error.message}.`);
return range === CONFIG.RATE_RANGE ? null : [];
}
}
// Show error message
function showError(message) {
DOM.errorMessage.textContent = message;
DOM.errorMessage.classList.add('show');
DOM.leaderboardBody.innerHTML = '';
}
// Clear error message
function clearError() {
DOM.errorMessage.textContent = '';
DOM.errorMessage.classList.remove('show');
}
// Format number with K, M, B abbreviations
function formatNumber(num, prefix) {
const absNum = Math.abs(num);
if (absNum >= 1_000_000_000) {
const value = num / 1_000_000_000;
return `${prefix}${value.toFixed(value % 1 === 0 ? 0 : 1)}B`;
} else if (absNum >= 1_000_000) {
const value = num / 1_000_000;
return `${prefix}${value.toFixed(value % 1 === 0 ? 0 : 1)}M`;
} else if (absNum >= 10_000) {
const value = num / 1_000;
return `${prefix}${value.toFixed(value % 1 === 0 ? 0 : 1)}K`;
} else {
return `${prefix}${num.toLocaleString('en-US', {
minimumFractionDigits: prefix === '$' ? 2 : 0,
maximumFractionDigits: prefix === '$' ? 2 : 0
})}`;
}
}
// Format currency based on currentCurrency
function formatCurrency(amount, currency) {
const num = parseFloat(amount.replace(/[^0-9.]/g, '') || 0);
if (currency === 'USDC') {
if (usdcRate <= 0 || isNaN(usdcRate)) {
console.warn(`Invalid usdcRate: ${usdcRate}. Displaying NGN.`);
return formatNumber(num, '₦');
}
const usdcAmount = num / usdcRate;
console.log(`Converting ${num} NGN to USDC: ${num} / ${usdcRate} = ${usdcAmount}`);
return formatNumber(usdcAmount, '$');
}
return formatNumber(num, '₦');
}
// Load NGN/USDC rate
async function loadRate() {
try {
const rateData = await fetchSheetData(CONFIG.STATS_ID, CONFIG.RATE_RANGE);
if (rateData === null) {
console.warn(`No rate found in SnappQuestData!D2. Using fallback rate: ${CONFIG.FALLBACK_RATE}`);
showError(`Failed to fetch rate. Using fallback rate (${CONFIG.FALLBACK_RATE} NGN/USDC).`);
usdcRate = CONFIG.FALLBACK_RATE;
} else {
const cleanedRate = rateData.toString().replace(/[^0-9.]/g, '').replace(/(\..*?)\..*/g, '$1');
console.log(`Cleaned rate value: "${cleanedRate}"`);
usdcRate = parseFloat(cleanedRate) || 0;
console.log(`Fetched NGN/USDC rate: ${usdcRate}`);
if (usdcRate <= 0 || isNaN(usdcRate)) {
console.warn(`Invalid NGN/USDC rate: ${usdcRate}. Using fallback: ${CONFIG.FALLBACK_RATE}`);
showError(`Invalid rate (${rateData}). Using fallback rate (${CONFIG.FALLBACK_RATE} NGN/USDC).`);
usdcRate = CONFIG.FALLBACK_RATE;
}
}
} catch (error) {
console.error('Error fetching rate:', error);
showError(`Failed to load rate: ${error.message}. Displaying NGN.`);
usdcRate = CONFIG.FALLBACK_RATE;
currentCurrency = 'NGN';
DOM.currencyToggle.checked = false;
DOM.currencyToggle.disabled = true;
}
}
// Populate leaderboard
async function populateLeaderboard() {
clearError();
const data = await fetchSheetData(CONFIG.SPREADSHEET_ID, CONFIG.RANGE);
if (!data.length) return;
leaderboardData = data.sort((a, b) => {
const earningsA = parseFloat(a['Total Earnings']?.replace(/[^0-9.]/g, '') || 0);
const earningsB = parseFloat(b['Total Earnings']?.replace(/[^0-9.]/g, '') || 0);
return earningsB - earningsA;
});
DOM.leaderboardBody.innerHTML = '';
leaderboardData.forEach((user, index) => {
const row = document.createElement('tr');
const displayName = user.Name || user.Access || 'Unknown';
row.innerHTML = `
<td class="rank">${index + 1}</td>
<td>${displayName}</td>
<td>${formatCurrency(user['Total Earnings'], currentCurrency)}</td>
<td>${formatNumber(user.TotalQuestsCompleted, '')}</td>
`;
DOM.leaderboardBody.appendChild(row);
});
}
// Event listeners
function setupEventListeners() {
DOM.disconnectBtn.addEventListener('click', () => {
console.log('Disconnect Wallet clicked');
window.location.href = 'index.html';
});
DOM.hamburger.addEventListener('click', () => {
console.log('Hamburger menu toggled');
DOM.hamburger.classList.toggle('active');
DOM.navContainer.classList.toggle('active');
DOM.overlay.classList.toggle('active');
});
DOM.navContainer.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
console.log('Nav link clicked:', link.href);
DOM.hamburger.classList.remove('active');
DOM.navContainer.classList.remove('active');
DOM.overlay.classList.remove('active');
});
});
DOM.overlay.addEventListener('click', () => {
console.log('Overlay clicked');
DOM.hamburger.classList.remove('active');
DOM.navContainer.classList.remove('active');
DOM.overlay.classList.remove('active');
});/*
DOM.learnMoreLink.addEventListener('click', (e) => {
e.preventDefault();
console.log('Learn More link clicked');
DOM.learnMoreModal.style.display = 'block';
setTimeout(() => DOM.learnMoreModal.classList.add('active'), 10);
});
DOM.closeButtons.forEach(button => {
button.addEventListener('click', () => {
console.log('Modal close button clicked');
DOM.learnMoreModal.classList.remove('active');
setTimeout(() => DOM.learnMoreModal.style.display = 'none', 400);
});
});
window.addEventListener('click', (event) => {
if (event.target === DOM.learnMoreModal) {
console.log('Clicked outside modal');
DOM.learnMoreModal.classList.remove('active');
setTimeout(() => DOM.learnMoreModal.style.display = 'none', 400);
}
});*/
window.addEventListener('scroll', () => {
console.log('Scroll position:', window.scrollY);
DOM.backToTopButton.classList.toggle('visible', window.scrollY > 300);
});
DOM.backToTopButton.addEventListener('click', () => {
console.log('Back to top clicked');
window.scrollTo({ top: 0, behavior: 'smooth' });
});
DOM.currencyToggle.addEventListener('change', () => {
currentCurrency = DOM.currencyToggle.checked ? 'USDC' : 'NGN';
console.log(`Currency toggled to: ${currentCurrency}`);
populateLeaderboard();
});
}
// Initialize
window.addEventListener('load', () => {
console.log('Page loaded, setting up event listeners');
setupEventListeners();
loadRate().then(populateLeaderboard);
console.log('Checking footer assets...');
if (!document.querySelector('footer')) {
console.error('Footer element not found in DOM');
}
if (!DOM.learnMoreModal) {
console.error('Learn More modal not found in DOM');
}
if (!DOM.backToTopButton) {
console.error('Back to top button not found in DOM');
}
});
</script>
</body>
</html>