-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathassets_js_bitrequest_core.js
5500 lines (5188 loc) · 201 KB
/
assets_js_bitrequest_core.js
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
// Initialize the application when the document is ready
$(document).ready(function() {
$.ajaxSetup({
"cache": false
});
close_startscreen();
if (get_urlparameters().xss) return
build_settings(); // build settings first
if (glob_const.hostlocation !== "local") { // don't add service worker on desktop
add_serviceworker();
}
//close potential websockets and pings
force_close_socket();
stop_monitors();
//Set classname for iframe
if (glob_const.inframe === true) {
glob_const.html.addClass("inframe");
const gets = get_urlparameters();
if (gets.payment) {
glob_const.html.addClass("hide_app");
}
} else {
glob_const.html.addClass("noframe");
}
//some api tests first
render_settings(); //retrieve settings from localstorage (load first to retrieve apikey)
if (glob_const.ls_support) { //check for local storage support
const bip_verified = glob_let.io.bipv,
php_enabled = glob_let.io.phpsupport;
if (bip_verified && glob_let.hasbip === true) {
glob_let.bipv = true;
}
if (php_enabled) {
glob_const.phpsupport = (php_enabled === "yes");
set_symbols();
} else {
checkphp();
}
} else {
const error_msg = "<h2 class='icon-bin'>Sorry!</h2><p>No Web Storage support..</p>";
popdialog(error_msg, "canceldialog");
}
$("#fixednav").html($("#relnav").html()); // copy nav
//startscreen
setTimeout(function() {
const splash_screen = $("#startscreen");
splash_screen.addClass("hidesplashscreen");
setTimeout(function() {
splash_screen.remove();
}, 600);
}, 600);
handle_select_input();
handle_option_selection();
canceldialog_trigger();
console.log({
glob_config
});
})
function close_startscreen() {
$(document).on("click", "#startscreen", function() {
const loc = glob_const.w_loc,
root = loc.origin + loc.pathname;
loc.href = root;
});
}
// ** Core Application Initialization: **
// Validates PHP support by testing fixer API endpoint and configures global PHP support status
function checkphp() {
api_proxy({
"api": "fixer",
"search": "symbols",
"cachetime": 86400,
"cachefolder": "1d",
"proxy": true,
"localhost": true,
"params": {
"method": "GET"
}
}).done(function(e) {
const api_result = br_result(e);
if (api_result.proxy === true) {
const currency_symbols = q_obj(api_result, "result.result.symbols");
if (currency_symbols) {
if (currency_symbols.USD) {
br_set_local("symbols", currency_symbols, true);
} else {
const api_error = data.error || "Unable to get API data";
fail_dialogs("fixer", {
"error": api_error
});
}
}
glob_let.io.phpsupport = "yes";
br_set_local("init", glob_let.io, true);
glob_const.phpsupport = true;
set_symbols();
return
}
glob_let.io.phpsupport = "no";
br_set_local("init", glob_let.io, true);
glob_const.phpsupport = false;
set_symbols();
}).fail(function(xhr, stat, err) {
glob_let.io.phpsupport = "no";
br_set_local("init", glob_let.io, true);
glob_const.phpsupport = false;
set_symbols();
});
}
// Retrieves and caches fiat currency symbols from fixer.io with 24h expiration
function set_symbols() {
//set globals
glob_let.local = (glob_const.hostlocation === "local" && glob_const.phpsupport === false),
glob_let.localserver = (glob_const.hostlocation === "local" && glob_const.phpsupport === true);
if (br_get_local("symbols")) {
get_erc20tokens();
return
}
api_proxy({
"api": "fixer",
"search": "symbols",
"cachetime": 86400,
"cachefolder": "1d",
"params": {
"method": "GET"
}
}).done(function(e) {
const api_data = br_result(e).result;
if (api_data) {
const currency_symbols = api_data.symbols;
if (currency_symbols && currency_symbols.USD) {
br_set_local("symbols", currency_symbols, true);
get_erc20tokens();
return
}
const api_error = api_data.error || "Unable to get API data";
fail_dialogs("fixer", {
"error": api_error
});
}
}).fail(function(xhr, stat, err) {
if (get_next_proxy()) {
set_symbols();
return
}
const error_msg = "<h2 class='icon-bin'>" + tl("apicallfailed") + "</h2><p class='doselect'>" + textStatus + "<br/>" + tl("apididnotrespond") + "<br/><br/><span id='proxy_dialog' class='ref'>" + tl("tryotherproxy") + "</span></p>";
popdialog(error_msg, "canceldialog");
})
}
// Fetches top 2000 ERC20 tokens from CoinMarketCap, filters Ethereum tokens, and caches results
function get_erc20tokens() {
const cached_tokens = get_cached_tokens(true);
if (cached_tokens) {
set_functions();
return
}
api_proxy({
"api": "coinmarketcap",
"search": "v1/cryptocurrency/listings/latest?cryptocurrency_type=tokens&limit=2000&aux=cmc_rank,platform",
"cachetime": glob_const.token_cache,
"cachefolder": "1w",
"proxy": true,
"params": {
"method": "GET"
}
}).done(function(e) {
const api_data = br_result(e).result,
api_status = api_data.status;
if (api_status && api_status.error_code === 0) {
const tokens_list = api_data.data;
if (tokens_list) {
// Split token_array in two and convert
const mid_point = Math.floor(tokens_list.length / 2),
tokens_first = tokens_list.slice(0, mid_point),
tokens_second = tokens_list.slice(mid_point);
if (tokens_first && tokens_second) {
store_coindata(tokens_first, tokens_second);
return
}
}
}
const error_msg = "<h2 class='icon-bin'>" + tl("apicallfailed") + "</h2><p class='doselect'>" + tl("nofetchtokeninfo") + "</p>";
popdialog(error_msg, "canceldialog");
}).fail(function(xhr, stat, err) {
if (get_next_proxy()) {
get_erc20tokens();
return
}
const error_msg = "<h2 class='icon-bin'>" + tl("apicallfailed") + "</h2><p class='doselect'>" + tl("nofetchtokeninfo") + "</p>";
popdialog(error_msg, "canceldialog");
}).always(function() {
set_functions();
});
}
// Splits and stores token data in localStorage with timestamp for cache management
function store_coindata(tokens_first, tokens_second) {
if (tokens_first) {
const converted_first = convert_coinlist(tokens_first);
if (converted_first) {
cr_push = {
"timestamp": now(),
"token_arr": converted_first
}
br_set_local("erc20tokens_init", cr_push, true);
}
}
if (tokens_second) {
const converted_second = convert_coinlist(tokens_second);
if (converted_second) {
br_set_local("erc20tokens", converted_second, true);
}
}
}
// Filters Ethereum-based tokens (platform ID 1027) and maps to simplified token object structure
function convert_coinlist(token_list) {
try {
return token_list.filter(token => token.platform && token.platform.id === 1027).map(token => ({
"name": token.slug,
"symbol": token.symbol.toLowerCase(),
"cmcid": token.id,
"contract": token.platform.token_address
}));
} catch (err) {
console.error(err.name, err.message);
return false
}
}
// Set up various functions for the application
function set_functions() {
set_locales(); //set meta attribute
set_permissions();
// ** Pincode **
pinkeypress();
//pinpressselect
pinpress_trigger();
//pinpress
pinvalidate_trigger();
pin_admin_reset();
//pinvalidate
pinback_trigger();
pinback_validate_trigger();
//pinback
seed_unlock_trigger();
phrase_login();
//remove_cashier
canceloptions_trigger();
//canceloptions
keyup();
if (is_viewonly() === true || ishome() === true) {
finish_functions();
return
}
if (check_pin_lock() === true) {
const content = pinpanel(" pinwall global");
showoptions(content, "pin");
return
}
finish_functions();
}
// Set up remaining functions for the application
function finish_functions() {
// ** Navigation & Routing: **
//loadurl
clicklink();
//loadpage
//openpage
popstate();
//loadfunction
//loadpageevent
//shownav
active_menu();
fixednav();
//cancel_url_dialogs
//ios_redirections
//ios_init
// ** Request & Payment Handling: **
triggertx();
//triggertx_function
//finishtx_function
trigger_open_tx();
//clear_savedurl
payrequest();
//close_paymentdialog
//continue_cpd
//after_scan_init
//after_scan
//cancel_after_scan
//set_recent_requests
// ** UI Components: **
toggle_currency();
toggle_address();
//check_currency
//currency_check
//currency_uncheck
toggle_switch();
show_select_options();
hide_select_options();
dialog_drawer();
//loader
closeloader_trigger();
//closeloader
//set_loader_text
// ** Scanner & QR: **
init_scan();
//start_scan
//abort_cam
cam_trigger();
close_cam_trigger();
//show_cam
//close_cam(
//set_scan_result
//handle_ln_connect
//handle_address
//handle_viewkey
//handle_node_url
// ** Helper Functions: **
open_url();
//get_blockcypher_apikey
//get_infura_apikey
//get_alchemy_apikey
//proxy_alert
//fetch_symbol
//toggle_fixed_nav
//ishome
//triggersubmit
//copy_to_clipboard
//prevent_screen_sleep
//allow_screen_sleep
//show_view_only_error
//countdown
//countdown_format
//add_serviceworker
// ** Core Navigation & State Management: **
togglenav();
//escape_and_back
//keyup
//is_opendialog
// ** Intro Flow: **
//init_bitcoin_select_dialog
init_bitcoin_select();
//init_eth_select_dialog
init_eth_select();
//choose_currency
// ** Dialog & Modal Management: **
//popdialog
//execute
canceldialog_click();
//canceldialog_trigger
//canceldialog
//render_html
//render_attributes
//template_dialog
//update_page_title
// ** Payment Dialog Control: **
block_cancel_paymentdialog();
cancel_paymentdialog_trigger();
//unfocus_inputs
//cpd_pollcheck
//cancel_paymentdialog
//hide_paymentdialog
//reset_paymentdialog
//force_close_socket
cancel_sharedialog_trigger();
//cancel_sharedialog
// ** Options & UI Panel Management: **
showoptionstrigger();
//showoptions
//canceloptions_trigger
//canceloptions
//clearoptions
//lockscreen
newrequest_alias();
newrequest();
confirm_ms_newrequest();
showtransaction_trigger();
showtransactions();
addressinfo();
show_pk();
//show_pk_cb
show_vk();
//show_vk_cb
refresh_request_states();
// ** Notifications: **
//notify
closenotifytrigger();
//closenotify
//topnotify
//popnotify
// ** Form & Input Handling: **
radio_select();
check_pk();
//pinpanel
//generate_pinpad_html
//switch_panel
//all_pinpanel
// ** Address & Seed Management: **
addcurrencytrigger();
//addcurrency
//derive_first_check
addaddress_trigger();
//addaddress
address_xpub_change();
//active_derives
get_wallet();
submit_address_trigger();
add_lightning();
trigger_add_erc20();
//add_erc20
autocomplete_erc20token();
pick_erc20_select();
//init_addressform
submit_erc20();
//validate_address_vk
//validate_address
//check_address
//check_vk
send_trigger();
showbip39_trigger();
check_recent();
// ** Request Management: **
request_history();
//recent_requests
//recent_requests_list
show_request_details();
toggle_request_meta();
showrequests();
showrequests_inline();
editaddress_trigger();
remove_address();
//remove_address_function
rec_payments();
edit_request();
submit_request_description();
receipt();
download_receipt();
share_receipt();
//get_pdf_url
// ** Archive Management: **
archive();
//archivefunction
unarchive();
//unarchive_function
remove_request();
//remove_request_function
// ** Transaction History: **
//add_historical_data
//animate_confbar
show_transaction_meta();
hide_transaction_meta();
//lnd_lookup_invoice
// ** Seed & Security: **
confirm_missing_seed();
//get_address_warning
confirm_missing_seed_toggle();
//cmst_callback
//add_seed_whitelist
//seed_wl
//add_address_whitelist
//addr_whitelist
// ** Address Reordering: **
dragstart();
//drag
dragend();
// ** URL & Link Handling: **
//set_xmr_node_access
//check_intents
//expand_shorturl
//expand_bitly_url
//open_blockexplorer_url
//blockexplorer_url
//get_blockexplorer
apisrc_shortcut();
//try_next_api
// ** App Install & Platform: **
setTimeout(function() { // wait for ios app detection
check_app_install_prompt();
console.log({
glob_const
});
}, 700);
//show_app_download_prompt
close_app_panel();
//platform_icon
gk();
glob_const.html.addClass("loaded");
//getnetwork
// ** Recent Request Management: **
//check_rr
//toggle_rr
// ** Lightning Network: **
//ln_connect
// ** Page Building & Rendering: **
rendercurrencies();
setTimeout(function() {
loadurl(); //initiate page
}, 100);
//render_currencysettings
//build_settings
//render_settings
render_requests();
//archive_button
//fetch_requests
//initiate
//buildpage
//append_coinsetting
//setting_sub_address
//append_address
//append_request
// ** Storage Management: **
//save_currencies
//save_addresses
//save_requests
//save_archive
//save_settings
//save_cc_settings
//update_changes
//reset_changes
//save_changestats
render_changes();
//change_alert
//get_total_changes
// ** Utility Functions: **
//amountshort
check_params();
const ap = all_proxies(),
all_tor_proxies = filter_object_array(ap, "tor", true);
glob_let.tor_proxies = filter_object_array(all_tor_proxies, "tor", true);
}
// Updates HTML document language and meta tag attributes based on current language code
function set_locales() {
glob_const.html.attr("lang", langcode);
$("meta[property='og:locale']").attr("content", langcode);
$("meta[property='og:url']").attr("content", glob_const.w_loc.href);
}
// Sets HTML element data-role based on user permission level
function set_permissions() {
const permission = $("#permissions").data("selected");
glob_const.html.attr("data-role", permission);
}
// Returns true if current user has cashier (view-only) permissions
function is_viewonly() {
const permission = $("#permissions").data("selected");
return permission === "cashier";
}
// ** PIN & Security: **
// Validates PIN configuration and optional locktime settings from DOM data attributes
function check_pin_enabled(check_exists) {
const pin_data = $("#pinsettings").data(),
pin_hash = pin_data.pinhash;
if (pin_hash) {
const pin_str = pin_hash.toString(),
valid_length = pin_str.length > 3;
if (valid_length) {
if (check_exists) {
return true
}
return pin_data.locktime !== "never";
}
}
return false
}
// Determines if app requires unlock based on configured timeout and last activity timestamp
function check_pin_lock() {
const url_params = get_urlparameters(),
lock_duration = $("#pinsettings").data("locktime"),
last_lock = br_get_local("locktime"),
time_since_lock = now() - last_lock,
lock_seconds = parseFloat(lock_duration);
return url_params.payment ? false : (check_pin_enabled() === true && time_since_lock > lock_seconds);
}
// Binds keyboard number inputs to PIN pad for numeric entry
function pinkeypress() {
$(document).keydown(function(e) {
const pinfloat = $("#pinfloat");
if (pinfloat.length) {
const keycode = e.keyCode;
if (keycode === 49 || keycode === 97) {
pinpressselect($("#pin1 > span"));
} else if (keycode === 50 || keycode === 98) {
pinpressselect($("#pin2 > span"));
} else if (keycode === 51 || keycode === 99) {
pinpressselect($("#pin3 > span"));
} else if (keycode === 52 || keycode === 100) {
pinpressselect($("#pin4 > span"));
} else if (keycode === 53 || keycode === 101) {
pinpressselect($("#pin5 > span"));
} else if (keycode === 54 || keycode === 102) {
pinpressselect($("#pin6 > span"));
} else if (keycode === 55 || keycode === 103) {
pinpressselect($("#pin7 > span"));
} else if (keycode === 56 || keycode === 104) {
pinpressselect($("#pin8 > span"));
} else if (keycode === 57 || keycode === 105) {
pinpressselect($("#pin9 > span"));
} else if (keycode === 48 || keycode === 96) {
pinpressselect($("#pin0 > span"));
} else if (keycode === 8) {
if (pinfloat.hasClass("enterpin")) {
pinback($("#pininput"));
} else {
pinback($("#validatepin"));
}
}
}
});
}
// Routes PIN input to either entry or validation handling based on current mode
function pinpressselect(node) {
if ($("#pinfloat").hasClass("enterpin")) {
pinpress(node);
return
}
pinvalidate(node)
}
// Initializes click handler for PIN pad numeric buttons
function pinpress_trigger() {
$(document).on("click", "#optionspop .enterpin .pinpad .pincell", function() {
pinpress($(this));
});
}
// Processes PIN digit entry, validates length, and manages visual feedback
function pinpress(pin_button) {
const pin_container = $("#pinfloat"),
digit = pin_button.text(),
pin_field = $("#pininput"),
current_pin = pin_field.val(),
updated_pin = current_pin + digit;
if (updated_pin.length === 4) {
if (pin_container.hasClass("pinwall")) {
enterapp(updated_pin);
pin_field.val(updated_pin);
return false
}
pin_field.val(updated_pin);
setTimeout(function() {
pin_container.addClass("validatepin").removeClass("enterpin");
}, 100);
return false
}
if (updated_pin.length > 4) {
return false
}
pin_field.val(updated_pin);
pin_button.addClass("activepad");
setTimeout(function() {
pin_button.removeClass("activepad");
}, 500);
$("#pincode .pinpad").not(pin_button).removeClass("activepad");
}
// Validates PIN entry and manages app access, lockouts, and security timeouts
function enterapp(pin_input) {
const pin_container = $("#pinfloat"),
pin_config = $("#pinsettings").data(),
stored_pin = pin_config.pinhash,
attempt_count = pin_config.attempts,
hashed_pin = generate_hash(pin_input),
timestamp = now(),
is_global = pin_container.hasClass("global");
if (hashed_pin == stored_pin) {
if (is_global) {
br_set_local("locktime", timestamp);
finish_functions();
setTimeout(function() {
play_audio(glob_const.waterdrop);
canceloptions(true);
}, 500);
} else if (pin_container.hasClass("admin")) {
br_set_local("locktime", timestamp);
loadpage("?p=currencies");
$(".currenciesbttn .self").addClass("activemenu");
play_audio(glob_const.waterdrop);
canceloptions(true);
} else if (pin_container.hasClass("reset")) {
br_set_local("locktime", timestamp);
$("#pintext").text(tl("enternewpin"));
pin_container.addClass("p_admin").removeClass("pinwall reset");
play_audio(glob_const.waterdrop);
setTimeout(function() {
$("#pininput").val("");
}, 200);
} else {
const pin_callback = pin_container.data("pincb");
if (pin_callback) {
pin_callback.func(pin_callback.args);
} else {
br_set_local("locktime", timestamp);
}
play_audio(glob_const.waterdrop);
canceloptions(true);
}
pin_config.attempts = 0;
save_settings(is_global);
remove_cashier();
} else {
if (!navigator.vibrate) {
play_audio(glob_const.funk);
}
shake(pin_container);
setTimeout(function() {
$("#pininput").val("");
}, 10);
if (attempt_count > 2) {
const timeout_rules = [{
"threshold": 3,
"duration": 300000
}, // 5 minutes
{
"threshold": 6,
"duration": 1800000
}, // 30 minutes
{
"threshold": 9,
"duration": 86400000
} // 24 hours
];
const current_rule = timeout_rules.find(rule => attempt_count === rule.threshold);
if (current_rule) {
const lock_until = timestamp + current_rule.duration;
pin_config.timeout = lock_until;
lockscreen(lock_until);
} else if (attempt_count > 9) {
attempt_count = 1;
}
}
pin_config.attempts = attempt_count + 1;
save_settings(is_global);
}
}
// Resets PIN lockout state by clearing timeout and attempt counters
function clearpinlock() {
const pin_config = $("#pinsettings").data();
pin_config.timeout = null;
pin_config.attempts = 0;
save_settings();
}
// Initializes click handler for PIN reset functionality
function pin_admin_reset() {
$(document).on("click", "#reset_pin", function() {
$("#pinfloat").removeClass("p_admin");
});
}
// Sets up click handlers for PIN confirmation pad
function pinvalidate_trigger() {
$(document).on("click", "#optionspop .validatepin .pinpad .pincell", function() {
pinvalidate($(this))
});
}
// Handles PIN confirmation entry and validates match with initial entry
function pinvalidate(pin_button) {
const pin_container = $("#pinfloat"),
digit = pin_button.text(),
confirm_field = $("#validatepin"),
current_input = confirm_field.val(),
updated_input = current_input + digit;
if (updated_input.length > 3) {
if (updated_input == $("#pininput").val()) {
const old_pin = get_setting("pinsettings", "pinhash"),
pin_settings = $("#pinsettings"),
pin_hash = generate_hash(updated_input),
pin_status = "pincode activated",
lock_duration = pin_settings.data("locktime");
pin_settings.data({
"pinhash": pin_hash,
"locktime": lock_duration,
"selected": pin_status
}).find("p").text(pin_status);
save_settings();
play_audio(glob_const.waterdrop);
canceloptions(true);
const pin_callback = pin_container.data("pincb");
if (pin_callback) {
pin_callback.func(pin_callback.args);
}
notify(tl("datasaved"));
encrypt_seed_data(seed_decrypt(old_pin));
} else {
topnotify(tl("pinmatch"));
if (navigator.vibrate) {} else {
play_audio(glob_const.funk);
}
shake(pin_container);
confirm_field.val("");
}
}
if (updated_input.length > 4) {
return false
}
confirm_field.val(updated_input);
pin_button.addClass("activepad");
setTimeout(function() {
pin_button.removeClass("activepad");
}, 500);
$("#pincode .pinpad").not(pin_button).removeClass("activepad");
}
// Binds click handler for PIN backspace in entry mode
function pinback_trigger() {
$(document).on("click", "#optionspop #pinfloat.enterpin #pinback", function() {
pinback($("#pininput"));
});
}
// Binds click handler for PIN backspace in validation mode
function pinback_validate_trigger() {
$(document).on("click", "#optionspop #pinfloat.validatepin #pinback", function() {
pinback($("#validatepin"));
});
}
// Removes last entered PIN digit and updates input display
function pinback(pin_field) {
const current_val = pin_field.val(),
trimmed_val = current_val.slice(0, -1);
pin_field.val(trimmed_val);
}
// Handles seed unlock button click
function seed_unlock_trigger() {
$(document).on("click", "#lockscreen #seed_unlock", function() {
$("#lockscreen #phrasewrap").addClass("showph");
});
}
// Validates recovery phrase login
function phrase_login() {
$(document).on("click", "#phrase_login", function() {
const phrase_input = $("#lockscreen #bip39phrase"),
phrase_text = phrase_input.text(),
seed_data = ls_phrase_obj(),
saved_seed = seed_data.pid,
current_seed = get_seedid(phrase_text.split(" "));
if (current_seed === saved_seed || current_seed === glob_let.cashier_seedid) {
clearpinlock();
if (!glob_const.html.hasClass("loaded")) {
finish_functions();
}
const pin_content = pinpanel(" reset");
showoptions(pin_content, "pin");
$("#pinfloat").removeClass("p_admin");
remove_cashier();
} else {
shake(phrase_input);
}
});
}
// Removes cashier role data and flags
function remove_cashier() {
if (glob_let.is_cashier) {
br_remove_local("cashier");
glob_let.cashier_dat = false,
glob_let.is_cashier = false,
glob_let.cashier_seedid = false;
}
}
// Handles navigation link clicks
function clicklink() {
$(document).on("click", ".self", function(event) {
event.preventDefault();
loadpage($(this).attr("data-rel"));
return
})
}
// Updates URL and triggers page load
function loadpage(target_url) {
const page_name = target_url.split("&")[0].split("=").pop();
openpage(target_url, page_name, "loadpage");
}
// Updates browser history and loads specified page function
function openpage(target_url, page_name, load_type) {
history.pushState({
"pagename": page_name,
"event": load_type
}, "", target_url);
loadfunction(page_name, load_type);
}
// Manages browser back/forward navigation state
function popstate() {
window.addEventListener("popstate", function(event) {
const state_data = event.state;
if (state_data && state_data.pagename) {
loadfunction(state_data.pagename, state_data.event);
return
}
cancel_url_dialogs();
});
}
// Routes to appropriate function based on page type and event
function loadfunction(page_name, event_type) {
if (event_type === "payment") { //load paymentpopup if payment is set
load_request();
return
}
if (event_type === "both") { //load paymentpopup if payment is set and load page
loadpageevent(page_name);
setTimeout(function() {
load_request("delay");
}, 1000);
return
}
loadpageevent(page_name);
const page_translation = tl(page_name),
display_title = page_translation || page_name;
update_page_title(display_title);
cancel_url_dialogs();
}
// Updates UI elements when loading new page
function loadpageevent(page_name) {
$("html, body").animate({
"scrollTop": 0
}, 400);
const target_page = $("#" + page_name);
target_page.addClass("currentpage");
$(".page").not(target_page).removeClass("currentpage");
$(".highlightbar").attr("data-class", page_name);
shownav(page_name);
const request_filter = get_urlparameters().filteraddress; // filter requests if filter parameter exists
if (request_filter && page_name === "requests") {
$("#requestlist > li").not(get_requestli("address", request_filter)).hide();
} else {
$("#requestlist > li").show();
}
}
// Toggles navigation visibility based on current page
function shownav(page_name) {
if (ishome(page_name) === true) {
glob_const.html.removeClass("showmain").addClass("hidemain");
$("#relnav .nav").slideUp(300);
return
}
glob_const.html.addClass("showmain").removeClass("hidemain")
$("#relnav .nav").slideDown(300);
}
// Manages active state of menu items
function active_menu() {
$(document).on("click", ".nav li .self", function() {
const menu_item = $(this);
$(".nav li .self").removeClass("activemenu");
menu_item.addClass("activemenu");