-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreference_code.html
732 lines (650 loc) · 25 KB
/
reference_code.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/ico" href="images/icon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://cdn.tailwindcss.com"></script>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css"
integrity="sha512-Kc323vGBEqzTmouAECnVceyQqyqdsSiqLQISBL29aUW4U/M7pSPA/gEUZQqv1cwx4OnYxTxve5UMg5GT6L4JJg=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
/>
<title>SOL Coups</title>
</head>
<body>
<!-- wallet 1 -->
<div
class="flex iems-center justify-center p-20 h-[100vh] w-full text-slate-300"
>
<div class="flex justify-center items-center flex-col">
<div
class="flex border h-[90vh] w-[80vh] border-black bg-[#232223] justify-center items-center"
>
<div class="page-1 flex flex-col items-center justify-center">
<div class="flex flex-row justify-center items-center p-4 mb-5">
<img src="images\logo.png" alt="Logo" />
<h1 class="mt-10 text-center mb-10 font-semibold text-5xl ml-10">
SOL COUPS
</h1>
</div>
<h2 class="text-center font-bold font-roboto text-2xl mb-5">
Enter Your Email
</h2>
<div
class="final-email-holder flex items-center justify-center mb-8"
>
<input
type="email"
id="email"
placeholder="Enter your email"
class="placeholder:font-semibold rounded-l-lg placeholder:text-slate-500 bg-[#181818] outline-none p-3 w-2/3"
style="width: 380px"
/>
<button
class="save-button bg-[#96f76f] p-3 text-[#232223] font-roboto rounded-r-lg"
>
Save
</button>
</div>
<div
class="inital-email-holder flex items-center justify-center mb-8"
style="display: none"
>
<input
id="displayEmail"
placeholder="Receiving mail here"
class="bg-[#181818] outline-none p-3 rounded-l-lg placeholder:font-semibold placeholder:text-slate-500"
style="width: 290px"
readonly
/>
<button
class="edit-button bg-[#96f76f] font-roboto rounded-r-lg text-[#232223] p-3 text-black"
>
Edit
</button>
</div>
<div
class="errorEmail text-2xl text-center mb-5 -mt-6 text-red-500 font-roboto "
id="errorEmail"
></div>
<h2
for="voucherAmount"
class="text-center font-bold font-roboto text-2xl mb-5"
>
Amount
</h2>
<div class="input-group flex items-center justify-center flex-wrap">
<input
type="number"
id="voucherAmount"
placeholder="Enter Voucher Amount"
class="placeholder:font-semibold rounded-l-lg placeholder:text-slate-500 bg-[#181818] outline-none p-3"
style="width: 240px"
/>
<div class="button">
<button
onclick="checkPrize()"
class="bg-[#96f76f] p-3 text-[#232223] rounded-r-lg font-roboto "
>
Check Prize
</button>
</div>
</div>
<div
class="output mt-10 text-center font-bold font-roboto text-2xl mb-4"
id="output"
>
<label for="solAmount"></label>
</div>
<div
class="button border w-1/5 flex items-center justify-center rounded-full bg-[#96f76f] text-[#232223] font-roboto "
>
<button
onclick="goToPage2()"
class="p-2 font-roboto text-md font-semibold"
>
Next
</button>
</div>
<div
id="errorMessage"
class="error-message text-2xl text-center mb-5 text-red-500 font-roboto "
></div>
</div>
</div>
</div>
</div>
<!-- page 2 -->
<div
class="page-2 flex iems-center justify-center flex-col"
style="display: none"
>
<div class="flex iems-center justify-center text-slate-300">
<div class="flex justify-center items-center flex-col">
<div
class="flex border h-[80vh] w-[80vh] border-black bg-[#232223] -mt-[50rem] justify-center items-center"
>
<div class="flex items-center justify-center flex-col">
<i
class="back-button fa-solid fa-arrow-left -ml-[35rem] mt-6 fa-xl cursor-pointer"
onclick="goBack()"
></i>
<div
class="flex items-center justify-center text-5xl font-bold font-roboto "
>
<h1 class="mb-8">Make Payment Here</h1>
</div>
<div class="input-group flex flex-col mb-5">
<label
for="displayEmail"
class="text-center text-3xl font-bold font-roboto text-2xl mb-2"
>Email</label
>
<input
type="text"
class="placeholder:font-semibold placeholder:text-slate-500 text-slate-500 text-center rounded-full bg-[#181818] outline-none p-2 w-2/3"
style="width: 380px"
id="displayEmailPage2"
readonly
/>
</div>
<div class="input-group flex flex-col mb-5">
<label
for="paymentAmount"
class="text-center text-3xl font-semibold font-roboto text-2xl mb-2"
>INR Amount</label
>
<div
class="flex bg-[#181818] rounded-full items-center justify-center"
>
<h2 class="text-2xl text-center font-bold">₹</h2>
<input
type="text"
id="paymentAmountPage2"
class="placeholder:font-semibold placeholder:text-slate-500 text-white text-2xl rounded-full bg-[#181818] outline-none p-2 w-2/3"
readonly
/>
</div>
</div>
<div
class="input-group flex items-center justify-center flex-col"
>
<label
for="solAmountPage2"
class="text-center text-3xl font-semibold font-roboto text-2xl mb-2"
>Estimated Solana (SOL)</label
>
<input
type="text"
id="solAmountPage2"
class="placeholder:font-semibold placeholder:text-slate-500 mb-2 text-white text-2xl rounded-full bg-[#181818] outline-none p-2 w-2/3 text-center"
readonly
/>
</div>
<div
class="input-group flex items-center justify-center flex-col"
>
<label
for="senderWallet"
class="text-center text-3xl font-semibold mb-4 font-roboto text-2xl mb-2"
>Sender's Wallet Address</label
>
<div class="flex items-center mb-3">
<input
type="text"
id="senderWallet"
placeholder="Enter wallet address"
class="placeholder:font-semibold rounded-l-lg placeholder:text-slate-500 bg-[#181818] outline-none p-3 w-2/3"
style="width: 380px"
/>
<button
onclick="validateWalletAddress()"
class="bg-[#96f76f] p-3 text-[#232223] rounded-r-lg font-roboto "
>
Check
</button>
</div>
<div
id="validationResult"
class="text-xl mb-4 font-roboto "
></div>
</div>
<div class="button">
<button
onclick="goToPage3()"
class="bg-[#96f76f] p-3 text-[#232223] rounded-full font-roboto "
>
Continue
</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Page 3: Send SOL -->
<div
class="page-3 flex iems-center justify-center flex-col"
style="display: none"
>
<div class="flex iems-center justify-center text-slate-300">
<div
class="flex border h-[80vh] w-[80vh] border-black bg-[#232223] -mt-[44rem] justify-center items-center"
>
<div class="flex items-center justify-center flex-col">
<span class="text-6xl mb-10 font-bold">
<div class="timer-stopwatch"></div>
<div id="timer" class="timer">5:00</div>
</span>
<div
class="highlighted-text text-center text-3xl font-semibold mb-2 font-roboto text-2xl"
>
Send SOL to:
</div>
<div class="input-group mb-4">
<input
type="text"
id="walletAddress"
value="E1GvucNq72EiVPZoytdukF7F7Cg8RYk678Cp8mYJHg8F"
readonly
class="placeholder:font-semibold rounded-l-lg placeholder:text-slate-500 bg-[#181818] outline-none p-3 w-2/3"
style="width: 380px"
/>
<button
id="copyButton"
class="bg-[#96f76f] p-3 text-[#232223] rounded-r-lg font-roboto "
onclick="copyWalletAddress()"
>
Copy
</button>
</div>
<div
class="highlighted-text highlighted-text text-center text-3xl font-semibold mb-2 font-roboto text-2xl"
>
Send SOL Amount:
</div>
<div class="input-group mb-6">
<input
type="text"
id="solAmountDisplay"
class="placeholder:font-semibold rounded-l-lg placeholder:text-slate-500 text-slate-500 bg-[#181818] outline-none p-3 w-2/3"
style="width: 290px"
readonly
/>
<button
id="copySolAmountButton"
class="bg-[#96f76f] p-3 text-[#232223] rounded-r-lg font-roboto "
onclick="copySolAmount()"
>
Copy
</button>
</div>
<div class="qr-code">
<img src="images/qr.png" alt="QR" />
</div>
<br />
<div id="confirmationMessage" class="highlighted-text"></div>
</div>
</div>
</div>
</div>
<script src="https://unpkg.com/@solana/web3.js@latest/lib/index.iife.min.js"></script>
<script
type="text/javascript"
src="https://cdn.jsdelivr.net/npm/@emailjs/browser@4/dist/email.min.js"
></script>
<script type="text/javascript">
(function () {
emailjs.init("MiYSgZi6HUcMhkLZM"); // public key
})();
</script>
<script>
const endpoint = "https://api.devnet.solana.com";
const solanaConnection = new solanaWeb3.Connection(endpoint);
document.addEventListener("DOMContentLoaded", function () {
document.querySelector(".page-1").style.display = "flex";
});
function goToPage2() {
const email = document.getElementById("displayEmail").value;
const paymentAmount = parseFloat(
document.getElementById("output").dataset.totalAmount
);
const solAmount = parseFloat(
document.getElementById("output").dataset.solAmount
);
const errorMessage = document.getElementById("errorMessage");
errorMessage.textContent = "";
if (email && !isNaN(paymentAmount)) {
document.getElementById("displayEmailPage2").value = email;
document.getElementById("paymentAmountPage2").value = paymentAmount;
document.getElementById("solAmountPage2").value = solAmount;
document.querySelector(".page-1").style.display = "none";
document.querySelector(".page-2").style.display = "flex";
} else {
errorMessage.textContent = "Please enter a valid email and amount.";
}
}
function goBack() {
document.querySelector(".page-2").style.display = "none";
document.querySelector(".page-1").style.display = "flex";
}
var email = "";
function saveEmail() {
const Email = document.getElementById("email").value;
email = Email;
const errorEmail = document.getElementById("errorEmail");
errorEmail.textContent = "";
if (validateEmail(email)) {
document.getElementById("displayEmail").value = email;
document.querySelector(".final-email-holder").style.display = "none";
document.querySelector(".inital-email-holder").style.display = "flex";
} else {
errorEmail.textContent = "Please enter a valid email.";
}
}
function editEmail() {
document.querySelector(".inital-email-holder").style.display = "none";
document.querySelector(".final-email-holder").style.display = "flex";
document.getElementById("email").value =
document.getElementById("displayEmail").value;
}
function validateEmail(email) {
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return re.test(String(email).toLowerCase());
}
async function fetchSolToInrRate() {
try {
const response = await fetch(
"https://api.coingecko.com/api/v3/simple/price?ids=solana&vs_currencies=inr"
);
const data = await response.json();
return data.solana.inr;
} catch (error) {
console.error("Error fetching exchange rate:", error);
return null;
}
}
var voucherAmount = 0;
async function checkPrize() {
const amount = parseFloat(
document.getElementById("voucherAmount").value
);
const rate = await fetchSolToInrRate();
const output = document.getElementById("output");
if (isNaN(amount) || amount < 50) {
output.textContent = "Please enter an amount of at least ₹50";
return;
}
if (amount > 10000) {
output.textContent =
"Voucher not available for amounts above ₹10,000.";
return;
}
let feePercentage;
if (amount <= 1000 && amount >= 50) {
feePercentage = 0.15; // 15% fee
} else if (amount <= 5000) {
feePercentage = 0.09; // 9% fee
} else if (amount <= 10000) {
feePercentage = 0.03; // 3% fee
}
const voucher_amount = (amount / rate).toFixed(7);
voucherAmount = voucher_amount;
const fee = amount * feePercentage;
const totalAmount = amount + fee;
const solAmount = (totalAmount / rate).toFixed(7);
output.textContent = `Total payable amount: ₹${totalAmount}`;
output.dataset.totalAmount = totalAmount;
output.dataset.solAmount = solAmount;
}
document.addEventListener("DOMContentLoaded", function () {
document
.querySelector(".edit-button")
.addEventListener("click", editEmail);
document
.querySelector(".save-button")
.addEventListener("click", saveEmail);
});
async function validateWalletAddress() {
const walletAddress = document.getElementById("senderWallet").value;
let isValid = false;
try {
const publicKey = new solanaWeb3.PublicKey(walletAddress);
isValid = solanaWeb3.PublicKey.isOnCurve(publicKey);
} catch (error) {
isValid = false;
}
if (isValid) {
document.getElementById("validationResult").textContent =
"Valid address";
document.getElementById("validationResult").style.color = "green";
return true;
} else {
document.getElementById("validationResult").textContent =
"Invalid address";
document.getElementById("validationResult").style.color = "red";
return false;
}
}
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
async function getTransactions(senderAddress, expectedAmount) {
const senderPubKey = new solanaWeb3.PublicKey(senderAddress);
const receiverAddress = "E1GvucNq72EiVPZoytdukF7F7Cg8RYk678Cp8mYJHg8F";
let transactionList = await solanaConnection.getSignaturesForAddress(
senderPubKey,
{ limit: 5 }
);
transactionList = transactionList.filter(
(tx) => tx.confirmationStatus === "finalized"
);
if (transactionList.length === 0) {
console.log("No finalized transactions found.");
return false;
}
let signatureList = transactionList.map(
(transaction) => transaction.signature
);
for (let signature of signatureList) {
// Added delay to avoid rate-limiting
await sleep(1);
try {
let transactionDetails =
await solanaConnection.getParsedTransaction(signature);
if (
transactionDetails &&
transactionDetails.transaction &&
transactionDetails.transaction.message &&
transactionDetails.transaction.message.accountKeys
) {
const senderAddressInTx =
transactionDetails.transaction.message.accountKeys[0].pubkey.toString();
const instructions =
transactionDetails.transaction.message.instructions;
for (let instruction of instructions) {
if (
instruction.programId.toString() ===
solanaWeb3.SystemProgram.programId.toString()
) {
const parsedInfo = instruction.parsed.info;
const amountSent = parsedInfo.lamports;
const receiverAddressInTx = parsedInfo.destination;
if (
senderAddressInTx === senderAddress &&
receiverAddressInTx === receiverAddress &&
amountSent === expectedAmount * 1000000000
) {
if (
transactionDetails.meta &&
transactionDetails.meta.err === null
) {
console.log("Successful transaction");
return true;
}
}
}
}
}
} catch (error) {
console.error(
`Error fetching transaction details for signature ${signature}:`,
error
);
}
}
console.log("Failed transaction");
return false;
}
var freezeTimer = false;
function startPeriodCheck(
senderAddress,
expectedAmount,
interval = 3000 // checks every 3 seconds
) {
return new Promise((resolve) => {
const checkTransactions = async () => {
const paymentReceived = await getTransactions(
senderAddress,
expectedAmount
);
if (paymentReceived) {
console.log("Payment confirmed!");
resolve("Payment confirmed!");
clearInterval(periodicCheck);
clearTimeout(timeout);
freezeTimer = true;
sendEmail(email);
}
};
const periodicCheck = setInterval(checkTransactions, interval);
checkTransactions();
timeout = setTimeout(() => {
clearInterval(periodicCheck);
console.log("Payment failed");
resolve("Payment failed");
}, 300000);
});
}
async function goToPage3() {
const isValid = await validateWalletAddress();
if (isValid) {
document.querySelector(".page-2").style.display = "none";
document.querySelector(".page-3").style.display = "flex";
const solAmount = document.getElementById("solAmountPage2").value;
document.getElementById("solAmountDisplay").value = solAmount;
startStopwatch();
const senderAddress = document.getElementById("senderWallet").value;
const expectedAmount = parseFloat(solAmount);
const result = await startPeriodCheck(senderAddress, expectedAmount);
const confirmationMessage = document.getElementById(
"confirmationMessage"
);
if (result === "Payment confirmed!") {
confirmationMessage.style.color = "green";
} else if (result === "Payment failed") {
confirmationMessage.textContent =
"Sorry, Transaction didn't go through";
confirmationMessage.style.color = "red";
}
}
}
function copyWalletAddress() {
const walletAddressInput = document.getElementById("walletAddress");
walletAddressInput.select();
walletAddressInput.setSelectionRange(0, 99999); // For mobile devices
document.execCommand("copy");
const copyButton = document.getElementById("copyButton");
copyButton.textContent = "Copied!";
copyButton.classList.add("copied");
setTimeout(() => {
copyButton.textContent = "Copy";
copyButton.classList.remove("copied");
}, 2000);
}
function startStopwatch() {
const timerDisplay = document.getElementById("timer");
let timeLeft = 300;
const timer = setInterval(() => {
if (freezeTimer) {
timerDisplay.textContent = "Payment Successful!";
return;
}
const minutes = Math.floor(timeLeft / 60);
const seconds = timeLeft % 60;
timerDisplay.textContent = `${minutes}:${
seconds < 10 ? "0" : ""
}${seconds}`;
timeLeft--;
if (timeLeft < 0) {
clearInterval(timer);
timerDisplay.textContent = "Time's up!";
}
}, 1000);
}
function copyWalletAddress() {
const walletAddressInput = document.getElementById("walletAddress");
walletAddressInput.select();
walletAddressInput.setSelectionRange(0, 99999); // For mobile devices
document.execCommand("copy");
const copyButton = document.getElementById("copyButton");
copyButton.textContent = "Copied!";
copyButton.classList.add("copied");
setTimeout(() => {
copyButton.textContent = "Copy";
copyButton.classList.remove("copied");
}, 2000);
}
function copySolAmount() {
const solAmountInput = document.getElementById("solAmountDisplay");
solAmountInput.select();
solAmountInput.setSelectionRange(0, 99999); // For mobile devices
document.execCommand("copy");
const copyButton = document.getElementById("copySolAmountButton");
copyButton.textContent = "Copied!";
copyButton.classList.add("copied");
setTimeout(() => {
copyButton.textContent = "Copy";
copyButton.classList.remove("copied");
}, 2000);
}
function generate_voucher() {
const alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const numbers = "0123456789";
function getRandomCharacters(length, characterSet) {
let result = "";
for (let i = 0; i < length; i++) {
result += characterSet.charAt(
Math.floor(Math.random() * characterSet.length)
);
}
return result;
}
const part1 = getRandomCharacters(4, alphabets);
const part2 = getRandomCharacters(4, numbers);
const part3 = getRandomCharacters(4, numbers);
const voucher = `${part1}-${part2}-${part3}`;
return voucher;
}
function sendEmail(userEmail) {
const voucherCode = generate_voucher();
console.log("Sending email to:", userEmail);
console.log("Using voucher code:", voucherCode);
emailjs
.send("service_o1gdu2l", "template_74b26u7", {
voucher_code: voucherCode,
to_email: userEmail,
})
.then(
function (response) {
confirmationMessage.textContent = "Voucher sent over mail";
},
function (error) {
confirmationMessage.textContent = `Failed to mail because of ${error}`;
}
);
}
</script>
</body>
</html>