-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
1304 lines (1068 loc) · 39.9 KB
/
Copy pathscript.js
File metadata and controls
1304 lines (1068 loc) · 39.9 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
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
'use strict'
// Elements specific to the landing page (index.html)
const firstVisit = document.querySelector(".first-visit");
const firstIntro = document.querySelector(".first-intro");
const LogInForm = document.querySelector(".login");
const signUpForm = document.querySelector(".sign-up");
const mainNav = document.querySelector(".main-nav-links")
const userFname = document.querySelector(".fname");
const userLname = document.querySelector(".lname");
const mainUser = document.querySelector(".user--name");
const mainPass = document.querySelector(".user--pin");
const existingUser = document.querySelector(".existing-user--name");
const existingPass = document.querySelector(".existing-user--pin")
const passView = document.querySelectorAll(".pass-view");
const btnSignUp = document.querySelector(".btn-sign-up");
const btnLogIn = document.querySelector(".btn-log-in");
const openAccount = document.querySelector(".open--account");
const LogIn = document.querySelector(".log--in");
const mainPageContent = document.querySelector(".main-page-content");
const controlSlide = document.querySelectorAll("[data-slide]");
const allOperationsSlide = document.querySelectorAll(".slide");
const testimonialSlider = document.querySelector(".t-slider");
const controlTestimonialSlides = document.querySelectorAll("[data-t_slides]");
const allTestimonailDot = document.querySelectorAll(".btn-dot");
const prevBtn = document.querySelector(".prev");
const nextBtn = document.querySelector(".next");
// toast Notification handlers
function ShowToast(message) {
const toast = document.getElementById("toast");
toast.textContent = message;
toast.classList.add("show");
toast.classList.remove("hide")
//hide after 3 seconds
setTimeout(() => {
toast.classList.add("hide");
toast.classList.remove("show");
}, 3000)
}
function ShowToastOne(message) {
const toast = document.getElementById("toast-one");
toast.textContent = message;
toast.classList.add("show");
toast.classList.remove("hide")
//hide after 3 seconds
setTimeout(() => {
toast.classList.add("hide");
toast.classList.remove("show");
}, 3000)
}
function ShowProcessing() {
const toast = document.getElementById("processing")
toast.classList.add("show");
toast.classList.remove("hide")
//hide after 2 seconds
setTimeout(() => {
toast.classList.add("hide");
toast.classList.remove("show");
}, 2000)
}
function ShowSuccess(message) {
const toast = document.getElementById("success");
toast.textContent = message;
toast.classList.add("show");
toast.classList.remove("hide")
//hide after 3 seconds
setTimeout(() => {
toast.classList.add("hide");
toast.classList.remove("show");
}, 3000)
}
function ShowError(message) {
const toast = document.getElementById("error");
toast.textContent = message;
toast.classList.add("show");
toast.classList.remove("hide")
//hide after 3 seconds
setTimeout(() => {
toast.classList.add("hide");
toast.classList.remove("show");
}, 3000)
}
function ShowWarning(message) {
const toast = document.getElementById("warning");
toast.textContent = message;
toast.classList.add("show");
toast.classList.remove("hide")
//hide after 3 seconds
setTimeout(() => {
toast.classList.add("hide");
toast.classList.remove("show");
}, 3000)
}
// function to generate creating account number
function getAccountNumber () {
return Math.floor(Math.random() * 10000000000, + 9000000000).toString()
}
// hide all form if there's an open account && login
if(openAccount && LogIn){
const form1 = signUpForm.querySelectorAll("input");
const form2 = LogInForm.querySelectorAll("input");
// initial state of the forms "required" in first visit
form1.forEach(i => i.disabled = true);
form2.forEach(i => i.disabled = true);
//displaying form and making input required to be false
function showForm(form, inputs) {
form.classList.remove("hide-content");
form.classList.add("drop-bounce");
inputs.forEach(input => input.disabled = false);
}
//hide form and make input required to be true
function hideForm(form, inputs) {
form.classList.add("hide-content");
form.classList.remove("drop-bounce");
inputs.forEach(input => {
input.disabled = true;
input.value = "";
});
}
// Open Account button
openAccount.addEventListener("click", () => {
showForm(signUpForm, form1);
hideForm(LogInForm, form2);
openAccount.disabled = false;
LogIn.disabled = true;
});
// Login button
LogIn.addEventListener("click", () => {
showForm(LogInForm, form2);
hideForm(signUpForm, form1);
LogIn.disabled = false;
openAccount.disabled = true;
});
// Sign Up submission
btnSignUp.addEventListener("click", e => {
e.preventDefault();
const firstname = userFname.value;
const lastname = userLname.value;
const username = mainUser.value;
const password = mainPass.value;
const accountNumber = getAccountNumber();
const profileImage = [];
const newUser = {firstname, lastname, username, password, accountNumber, profileImage}
const storedUsers = JSON.parse(localStorage.getItem("Users")) || [];
storedUsers.push(newUser);
localStorage.setItem("Users", JSON.stringify(storedUsers))
// Check all inputs filled
let valid = true;
form1.forEach(input => {
if (input.value.trim() === "") valid = false;
});
if (!valid) {
ShowError("Please fill in all fields");
return;
}
// Hide form and hide main content for user to login
hideForm(signUpForm, form1);
ShowToast(`Hi ${firstname}, you've succesfully created an account! your account number is ${accountNumber}, kindly check transaction page for more details`)
openAccount.disabled = false;
LogIn.disabled = false;
})
//Login submission
btnLogIn.addEventListener("click", e => {
e.preventDefault();
// check if inputs are empty
if (existingUser.value.trim() === "" || existingPass.value.trim() === "") {
ShowError("Please enter username and pin");
return;
}
const users = JSON.parse(localStorage.getItem("Users")) || [];
const foundUser = users.find(user =>
user.username === existingUser.value &&
user.password === existingPass.value
);
if (foundUser) {
LogInForm.classList.add("hide-content");
LogIn.disabled = false;
openAccount.disabled = false;
mainPageContent.classList.remove("hide-content")
ShowToastOne(`Hi ${existingUser.value}, you've succesfully logged in!`)
firstVisit.style.display = "none";
} else {
ShowError("Incorrect Username or Pin");
existingUser.value = "";
existingPass.value = ""
}
});
}
// password type change and icon toggle for index.html page
if(passView && openAccount && LogIn){
passView.forEach(pass => {
pass.addEventListener("click", function(e){
e.preventDefault();
const span = document.querySelectorAll(".password")
span.forEach(val => {
const input = val.querySelector("input");
if(input.type === "password"){
input.type = "text"
pass.classList.remove("bi-eye")
pass.classList.add("bi-eye-slash")
}
else if(input.type === "text"){
input.type = "password"
pass.classList.remove("bi-eye-slash")
pass.classList.add("bi-eye")
}
})
})
})
}
// operations slides
if(allOperationsSlide){
/////working on Opearations slides
controlSlide.forEach((control) => {
control.addEventListener("click", function(e){
e.preventDefault();
const index = this.dataset.slide;
allOperationsSlide.forEach((slide) => {
slide.classList.remove("active")
slide.classList.add("hide-content")
})
allOperationsSlide[index].classList.add("active");
allOperationsSlide[index].classList.remove("hide-content")
})
})
}
// testimonails slides
if(testimonialSlider){
let index = 0;
// control testimonial slides
controlTestimonialSlides.forEach((control) => {
control.addEventListener("click", function() {
index = this.dataset.t_slides;
testimonialSlider.style.transform = `translateX(-${index * 100}%)`
allTestimonailDot.forEach((dot) =>{
dot.classList.add("bi-circle")
})
allTestimonailDot[index].classList.remove("bi-circle")
allTestimonailDot[index].classList.add("bi-circle-fill")
})
})
// ///////prev testimonial slides
prevBtn.addEventListener("click", function(e) {
e.preventDefault();
index--;
if(index < 0){
index = 2;
}
testimonialSlider.style.transform = `translateX(-${index * 100}%)`
})
//////next testimonial slides
nextBtn.addEventListener("click", function(e) {
e.preventDefault();
index++;
if(index > 2){
index = 0;
}
testimonialSlider.style.transform = `translateX(-${index * 100}%)` ;
})
}
// Intersection observer for index.html
// passing "argument" into handler
if(mainNav){
const handleHover = function (e) {
if (e.target.classList.contains('nav__link')) {
e.preventDefault()
const link = e.target;
const siblings = link.closest('.main-nav-links').querySelectorAll('.nav__link');
siblings.forEach(el => {
if (el !== link) el.style.opacity = this;
});
}
};
mainNav.addEventListener('mouseover', handleHover.bind(0.5));
mainNav.addEventListener('mouseout', handleHover.bind(1));
///observing the sticky nav
const header = document.querySelector(".main-header")
const navHeight = mainNav.getBoundingClientRect().height
const stickyNav = function(entries){
const [entry] = entries;
if(!entry.isIntersecting){
mainNav.classList.add("active-nav")
}
else {
mainNav.classList.remove("active-nav")
}
}
const headerObserver = new IntersectionObserver(stickyNav, {
threshold: 0,
rootMargin: `-${navHeight}px`,
})
headerObserver.observe(header)
const mainIndex = document.querySelector(".index-main")
const allSections = mainIndex.querySelectorAll("section")
const sectionObserverFunction = function (entries, observer){
const [entry] = entries;
if(!entry.isIntersecting){
allSections.forEach(sec => {
const img = sec.querySelectorAll("img");
img.forEach(img => {
img.classList.add("blur")
})
})
} else{
allSections.forEach(sec => {
const img = sec.querySelectorAll("img");
const testimonials = document.querySelector(".testimonials-section")
img.forEach(img => {
img.classList.remove("blur")
img.classList.add("drop-bounce")
})
})
observer.unobserve(entry.target)
}
}
const sectionObserver = new IntersectionObserver(sectionObserverFunction, {
threshold: 0.15,
root : null
});
allSections.forEach(section => {
sectionObserver.observe(section)
})
}
// Elements specific to the transaction page
const transactionPage = document.querySelector(".t-page")
const greetings = document.querySelector(".first--message")
const tForm = document.querySelector('.t-form');
const tlogIn = document.querySelector('.t--login');
const tUserName = document.querySelector('.tuser--name');
const tPass = document.querySelector('.tuser--pin');
const cUser = document.querySelector('.c-user');
const cPass = document.querySelector('.c-pin');
const tSignIn = document.querySelector('.tsign-in');
const balanceSection = document.querySelectorAll(".balance-section");
const btnTransfer = document.querySelector(".btn-transfer");
const btnRequest = document.querySelector(".btn-request")
const requestAmount = document.querySelector(".request-amount")
const withdrawals = document.querySelector('.withdrawal');
const deposits = document.querySelector('.deposit');
const totalBalance = document.querySelectorAll(".total-balance");
const transferAmount = document.querySelector(".t-amount");
const recipient = document.querySelector(".recipient")
const btnClose = document.querySelector(".btn-close");
const timer = document.querySelector(".timer");
const moneyIn = document.querySelector(".money-in");
const moneyOut = document.querySelector(".money-out");
const currentDate = document.querySelector(".current-date");
const currentBalContainer = document.querySelector(".current-balance");
const infoContainer = document.querySelector(".info");
const movDate = document.querySelectorAll(".mov-date");
const widthdrawDiv = document.querySelectorAll(".withdraw");
const ascend = document.querySelector(".ascend");
const descend = document.querySelector(".descend");
const In = document.querySelector(".in");
const Out = document.querySelector(".out");
const accountNumber = document.querySelector(".account-number");
const accountButton = document.querySelectorAll(".dashboard-btn");
const paymentButton = document.querySelectorAll(".bills-btn");
const transferButton = document.querySelectorAll(".transfer-btn");
const profileButton = document.querySelectorAll(".profile-btn");
const dashboard = document.querySelector(".dashboard");
const transferFunds = document.querySelector(".transfer-funds");
const payBills = document.querySelector(".pay-bills");
const billsContainer = document.querySelector(".bills-container");
const transferContainer = document.querySelector(".transfer-container");
const profileContainer = document.querySelector(".profile-container");
const airtimeBtn = document.querySelector(".airtime-purchase");
const phoneNumber = document.querySelector(".p-number")
const subscriptionBtn = document.querySelector(".subscription-purchase");
const subId = document.querySelector(".sub-id")
const electricityBtn = document.querySelector(".electricity-purchase");
const electricityId = document.querySelector(".e-id")
const airtimeAmount = document.querySelector(".airtime-amount");
const electAmount = document.querySelector(".electricity-amount");
const subAmount = document.querySelector(".subscription-amount");
const network = document.querySelector(".networks");
const tvSubscription = document.querySelector(".tv-subscription");
const distribution = document.querySelector(".distribution");
const meter = document.querySelector(".meter");
const btnCopy = document.querySelectorAll(".btn-copy");
const currentName = document.querySelector(".current-name");
const changeFirstName = document.querySelector(".change-firstname");
const changeLastName = document.querySelector(".change-lastname");
const changeUserName = document.querySelector(".change-username");
const btnChange = document.querySelector(".btn-change");
const displayChangeForm = document.querySelector(".form-container");
const submitDetails = document.querySelector(".submit-details");
const profileH1 = document.querySelector(".profile-h1");
const profileSpan = document.querySelector(".profile-span");
const profileAcc = document.querySelector(".profile-acc");
const uploadImage = document.querySelector(".uploadImage");
const fileInput = document.querySelector("#fileInput");
const preview = document.querySelector("#preview");
const btnLogOut = document.querySelector(".btn-logOut");
// password type change and icon toggle for transaction page
if(tlogIn){
const pass = document.querySelector(".pass-view");
pass.addEventListener("click", function(e){
e.preventDefault();
const span = document.querySelector(".password")
const input = span.querySelector("input");
if(input.type === "password"){
input.type = "text"
pass.classList.remove("bi-eye")
pass.classList.add("bi-eye-slash")
}
else if(input.type === "text"){
input.type = "password"
pass.classList.remove("bi-eye-slash")
pass.classList.add("bi-eye")
}
})
}
// initially hide transaction main page
if(transactionPage){
transactionPage.style.display = "none";
}
// local currency set up
const localCurrency = {
NG: "NGN",
US: "USD",
GB: "GBP",
CA: "CAD",
EU: "EUR",
};
const locale = navigator.language;
const country = locale.split("-")[1];
const currency = localCurrency[country];
function displayCurrency () {
return new Intl.NumberFormat(locale, {
style: "currency",
currency: currency
}).format(balance)
}
// Assigned Internal Balance
let balance = 1000000;
// Updated Balance
if(totalBalance && moneyIn) {
totalBalance.forEach(total => {
total.textContent = displayCurrency();
moneyIn.textContent = displayCurrency()
})
}
// diffrence between dates sections
function daysPassed (date1, date2) {
const diff = Math.abs(date2 - date1);
return Math.round(diff / (1000 * 60 * 60 * 24))
}
// Elements specific to Transaction Nav
const navToggler = document.querySelector(".nav-toggle")
const navLinks = document.querySelector(".nav-links")
if(navToggler){
navToggler.addEventListener("click", function(e){
e.preventDefault();
navLinks.classList.contains("hide-content") ? navLinks.classList.remove("hide-content") : navLinks.classList.add("hide-content")
})
}
// Submitted Form for Tansaction Page
if(tlogIn){
tlogIn.addEventListener('submit', function (e) {
e.preventDefault();
const users = JSON.parse(localStorage.getItem("Users")) || [];
const foundUser = users.find(user => user.username === tUserName.value && user.password === tPass.value);
if(foundUser){
//stored ussername and password for updating the user profile image
const usernameValue = tUserName.value;
const passwordValue = tPass.value;
//displaySavedImage function
function displaySavedImage () {
const getStoredUsers = JSON.parse(localStorage.getItem("Users"));
const foundStoredUser = getStoredUsers.find(user => user.username === usernameValue && user.password === passwordValue);
if(foundStoredUser.profileImage.length === 0){
preview.src = "./jhay-bank-logo.jpg"
} else {
preview.src = foundStoredUser.profileImage;
}
}
displaySavedImage();
// button for uploading image to the website
if(uploadImage){
uploadImage.addEventListener("click", function(e) {
fileInput.click();
fileInput.addEventListener("change", function(e) {
const file = this.files[0]
if(file){
const reader = new FileReader();
reader.onload = function(e){
const imageData = e.target.result;
preview.src = imageData;
const storedUsers = JSON.parse(localStorage.getItem("Users")) || [];
const loggedInUser = storedUsers.find(user =>
user.username === usernameValue && user.password === passwordValue
);
loggedInUser.profileImage = imageData;
if(loggedInUser){
storedUsers.push(loggedInUser);
localStorage.setItem("Users", JSON.stringify(storedUsers));
}
}
reader.readAsDataURL(file);
}
})
});
}
// Show transaction page and hide form
tForm.style.display = "none";
transactionPage.style.display = "block";
// displaySavedImage();
ShowToast(`Hi ${tUserName.value}, you've successfully logged in!`);
//update account number text content
accountNumber.textContent = foundUser.accountNumber;
profileAcc.textContent = foundUser.accountNumber;
// Capitalize firstname and lastname
const getFisrtName = foundUser.firstname;
const getLastName = foundUser.lastname;
const firstletterInFname = getFisrtName.at(0).toLocaleUpperCase();
const firstletterInLname = getLastName.at(0).toLocaleUpperCase();
const otherLettersInFname = getFisrtName.slice(1);
const otherLettersInLname = getLastName.slice(1);
const capitalizedFname = firstletterInFname + otherLettersInFname;
const capitalizedLname = firstletterInLname + otherLettersInLname;
// Greetings
const now = new Date();
const hr = now.getHours();
const message = hr < 12 ? `Good morning ${capitalizedFname}` : hr < 18 ? `Good Afternoon ${capitalizedFname}` : `Good Evening ${capitalizedFname}`;
greetings.textContent = message;
// copy account number to clipboard
btnCopy.forEach(btn => {
btn.addEventListener("click", function(e) {
e.preventDefault();
const text = accountNumber.textContent;
navigator.clipboard.writeText(text).then(() => ShowSuccess('copied successfully')).catch(() => ShowError('failed to copy'))
})
})
//Togglers for displaying different transaction features and hiding others
accountButton.forEach(acc => {
acc.addEventListener("click", function(e){
e.preventDefault();
dashboard.style.display = "block";
transferContainer.classList.remove("transfer-flex");
transferContainer.classList.add("hide-content");
billsContainer.classList.add("hide-content");
billsContainer.classList.remove("bill-flex");
profileContainer.classList.add("hide-content");
})
});
paymentButton.forEach(pay => {
pay.addEventListener("click", function(e){
e.preventDefault();
billsContainer.classList.add("bill-flex");
billsContainer.classList.remove("hide-content");
dashboard.style.display = "none";
transferContainer.classList.remove("transfer-flex");
transferContainer.classList.add("hide-content");
profileContainer.classList.add("hide-content");
});
});
transferButton.forEach(transfer => {
transfer.addEventListener("click", function(e){
e.preventDefault();
transferContainer.classList.add("transfer-flex");
transferContainer.classList.remove("hide-content");
dashboard.style.display = "none";
billsContainer.classList.remove("bill-flex");
billsContainer.classList.add("hide-content")
profileContainer.classList.add("hide-content");
});
})
profileButton.forEach(profile => {
profile.addEventListener("click", function(e){
e.preventDefault();
profileContainer.classList.remove("hide-content");
dashboard.style.display = "none";
billsContainer.classList.remove("bill-flex");
billsContainer.classList.add("hide-content")
transferContainer.classList.remove("transfer-flex");
transferContainer.classList.add("hide-content");
});
})
transferFunds.addEventListener("click", function(e){
e.preventDefault();
transferContainer.classList.add("transfer-flex");
transferContainer.classList.remove("hide-content");
dashboard.style.display = "none";
billsContainer.classList.remove("bill-flex");
billsContainer.classList.add("hide-content")
profileContainer.classList.add("hide-content");
})
payBills.addEventListener("click", function(e){
e.preventDefault();
billsContainer.classList.add("bill-flex");
billsContainer.classList.remove("hide-content")
dashboard.style.display = "none";
transferContainer.classList.remove("transfer-flex");
transferContainer.classList.add("hide-content");
profileContainer.classList.add("hide-content");
});
// Hide sub nav
tForm.style.display = "none";
// Timer
let time = 300;
const timerFunction = setInterval(()=>{
let min = Math.floor(time/60).toString().padStart(2,"0");
let sec = (time%60).toString().padStart(2,"0");
timer.textContent = `${min}:${sec}`;
if(time===60) ShowWarning(`Hello ${capitalizedFname}, you will be logged out in less than 1 minute.`);
if(time===0){
clearInterval(timerFunction);
transactionPage.style.display="none";
tForm.style.display="block";
tUserName.value="";
tPass.value="";
}
time--;
},1000);
// Current date display
function getCurrentDate() {
setTimeout(() => {
balance = new Date().toLocaleString();
currentDate.textContent = balance
}, 1000)
}
// updates the firstname to be capitalized
profileH1.textContent = capitalizedFname;
profileSpan.textContent = capitalizedLname;
// Buttons for purchasing airtime, subscription and electricity
airtimeBtn.addEventListener("click", function (e) {
e.preventDefault();
if (airtimeAmount.value && phoneNumber.value){
const amount = Number(airtimeAmount.value);
const airtimeTransaction = {
type: "Airtime",
provider: network.value,
amount: amount,
date: new Date().toISOString()
};
newAccount.addAirtime(airtimeTransaction);
newAccount.withdraw(amount);
saveAccount(newAccount);
balance = newAccount.balance();
totalBalance.forEach(total => {
return total.textContent = displayCurrency()
});
ShowProcessing();
setTimeout(() => {
balance = amount;
ShowSuccess(`Hello ${capitalizedFname}, your ${airtimeTransaction.provider} ${airtimeTransaction.type} Purchase of ${displayCurrency()} has been credited to ${phoneNumber.value} successfully`);
phoneNumber.value = "";
}, 3000);
moneyOut.textContent = new Intl.NumberFormat(locale, {
style: "currency",
currency: currency
}).format(newAccount.accAllOuts());
displayMovements(newAccount);
airtimeAmount.value = "";
} else{
ShowError(`Kindly input a phone number and amount`)
}
});
subscriptionBtn.addEventListener("click", function (e) {
e.preventDefault();
if (subAmount.value && subId.value){
const amount = Number(subAmount.value);
const subscriptionTransaction = {
type: "Subscription",
provider: tvSubscription.value,
amount: amount,
date: new Date().toISOString()
};
newAccount.addSubscription(subscriptionTransaction);
newAccount.withdraw(amount);
saveAccount(newAccount);
balance = newAccount.balance();
totalBalance.forEach(total => {
return total.textContent = displayCurrency();
});
ShowProcessing();
setTimeout(() => {
balance = amount;
ShowSuccess(`Hello ${capitalizedFname}, your ${subscriptionTransaction.provider} ${subscriptionTransaction.type} of ${displayCurrency()} for #${subId.value} has been completed successfully`);
subId.value = "";
}, 3000);
moneyOut.textContent = new Intl.NumberFormat(locale, {
style: "currency",
currency: currency
}).format(newAccount.accAllOuts());
displayMovements(newAccount);
subAmount.value = "";
} else {
ShowError(`Kindly input a subscription id and amount`)
}
});
electricityBtn.addEventListener("click", function (e) {
e.preventDefault();
if (electAmount.value && electricityId.value){
const amount = Number(electAmount.value);
const electricityTransaction = {
type: "Electricity",
provider: distribution.value,
meterType: meter.value,
amount: amount,
date: new Date().toISOString()
};
newAccount.addElectricity(electricityTransaction);
newAccount.withdraw(amount);
saveAccount(newAccount);
balance = newAccount.balance();
totalBalance.forEach(total => {
return total.textContent = displayCurrency();
});
ShowProcessing();
setTimeout(() => {
balance = amount;
ShowSuccess(`Hello ${capitalizedFname}, your ${electricityTransaction.provider} ${electricityTransaction.type} Purchase of ${displayCurrency()} for #${electricityId.value} has been completed successfully`);
electricityId.value = "";
}, 3000);
moneyOut.textContent = new Intl.NumberFormat(locale, {
style: "currency",
currency: currency
}).format(newAccount.accAllOuts());
displayMovements(newAccount);
electAmount.value = "";
} else{
ShowError(`Kindly input an electricity id and amount`)
}
});
// update the current date in the current balance
getCurrentDate();
// button for showing form for editing user profile.
btnChange.addEventListener("click", function(e) {
e.preventDefault();
displayChangeForm.classList.remove("hide-content");
});
// button for editing firstname and username as well as updating it in the local storage
submitDetails.addEventListener("click", function(e) {
e.preventDefault();
if(changeFirstName.value === "" || changeUserName.value === ""){
alert("input your firstname or lastname");
} else{
const newFirstName = changeFirstName.value;
const newLastName = changeLastName.value;
const newUserName = changeUserName.value;
const getUsers = JSON.parse(localStorage.getItem("Users"))
const getUserAccount = JSON.parse(localStorage.getItem("UserAccount"))
getUsers.find(user => {
if(user.accountNumber){
user.firstname = newFirstName;
user.username = newUserName;
user.lastname = newLastName;
localStorage.setItem("Users", JSON.stringify(getUsers))
}
});
getUserAccount.find(user => {
if(user.username){
user.username = newUserName;
localStorage.setItem("UserAccount", JSON.stringify(getUserAccount))
}
});
changeFirstName.value = "";
changeUserName.value = "";
changeLastName.value = "";
displayChangeForm.classList.add("hide-content");
transactionPage.style.display="none";
tForm.style.display="block";
clearInterval(timerFunction);
}
});
// Class Object
class Accounts {
#pin;
#movements;
#movDates;
#allOuts;
#airtime;
#electricity;
#subscription;
constructor(
username,
pin,
movements = [1000000], movDates = [new Date().toISOString()],
allOuts = [0],
airtime = [],
electricity = [],
subscription = []){
this.username = username;
this.#pin = pin;
this.#allOuts = [...allOuts];
this.#movements = [...movements];
this.#movDates = [...movDates];
this.#airtime = [...airtime];
this.#electricity = [...electricity];
this.#subscription = [...subscription];
}
deposit(val) {
this.#movements.push(val);
this.#movDates.push(new Date().toISOString());
}
withdraw(val) {
this.#allOuts.push(val);
this.#movements.push(-val);
this.#movDates.push(new Date().toISOString());
}
addAirtime(data) {
this.#airtime.push(data);
}
addElectricity(data) {
this.#electricity.push(data);
}
addSubscription(data) {
this.#subscription.push(data);
}
balance() {
return this.#movements.reduce((acc, val) => acc + val, 0);
}
interest() {
return this.balance() * 0.03;
}
request(val) {
if(val <= this.balance() * 0.03){
this.#movements.push(val);
this.#movDates.push(new Date().toISOString());
ShowProcessing();
setTimeout(() => {