@@ -33,6 +33,8 @@ $(document).ready(function() {
33
33
34
34
// Layer 2's
35
35
edit_l2 ( ) ;
36
+ l2nw_toggle ( ) ;
37
+ l2nw_switch ( ) ;
36
38
submit_l2 ( ) ;
37
39
38
40
// Xpub settings
@@ -650,17 +652,17 @@ function test_rpc(rpc_input_box, rpc_data, currency) {
650
652
api_proxy ( pload ) . done ( function ( e ) {
651
653
const data = br_result ( e ) ,
652
654
rpc_result = data . result ;
653
- if ( rpc_result && ( br_issar ( rpc_result ) || rpc_result . rpc_version ) ) {
654
- const error = data . error || rpc_result . error ;
655
- if ( error ) {
656
- rpc_input_box . addClass ( "offline" ) . removeClass ( "live" ) ;
657
- topnotify ( cant_connect ) ;
658
- const error_message = error . error_message || error . message ;
659
- if ( error_message ) {
660
- popnotify ( "error" , error_message ) ;
661
- }
662
- return
655
+ const error = data . error || rpc_result . error ;
656
+ if ( error ) {
657
+ rpc_input_box . addClass ( "offline" ) . removeClass ( "live" ) ;
658
+ topnotify ( cant_connect ) ;
659
+ const error_message = error . error_message || error . message ;
660
+ if ( error_message ) {
661
+ popnotify ( "error" , error_message ) ;
663
662
}
663
+ return
664
+ }
665
+ if ( rpc_result && ( br_issar ( rpc_result ) || rpc_result . rpc_version ) ) {
664
666
rpc_input_box . addClass ( "live" ) . removeClass ( "offline" ) ;
665
667
pass_rpc_submit ( currency , rpc_data , true ) ;
666
668
}
@@ -806,54 +808,118 @@ function get_rpc_url(rpc_data) {
806
808
807
809
// Layer 2's
808
810
809
- // Function to handle editing of Layer 2 settings
811
+ // Function to handle editing of eth Layer 2 settings
810
812
function edit_l2 ( ) {
811
813
$ ( document ) . on ( "click" , ".cc_settinglist li[data-id='layer2']" , function ( ) {
812
- const current_li = $ ( this ) ,
813
- this_data = current_li . data ( ) ,
814
- options = this_data . options ;
814
+ const thiscurrency = $ ( this ) . children ( ".liwrap" ) . attr ( "data-currency" ) ,
815
+ csnode = cs_node ( thiscurrency , "layer2" , true ) ,
816
+ options = csnode . options ;
815
817
if ( options ) {
816
- const thiscurrency = current_li . children ( ".liwrap" ) . attr ( "data-currency" ) ,
817
- selected = this_data . selected ,
818
- ddat = [ {
819
- "div" : {
820
- "class" : "popform" ,
821
- "content" : [ {
822
- "div" : {
823
- "class" : "selectbox" ,
824
- "content" : [ {
825
- "input" : {
826
- "attr" : {
827
- "type" : "text" ,
828
- "value" : selected ,
829
- "placeholder" : translate ( "layer2" ) ,
830
- "readonly" : "readonly"
831
- } ,
832
- "close" : true
833
- } ,
834
- "div" : {
835
- "class" : "selectarrows icon-menu2" ,
836
- "attr" : {
837
- "data-pe" : "none"
838
- }
839
- }
818
+ const ccsymbol = fetchsymbol ( thiscurrency ) ,
819
+ symbol = ccsymbol . symbol ,
820
+ ctracts = contracts ( symbol ) ,
821
+ arb_contract = ctracts . arbitrum ,
822
+ polygon_contract = ctracts . polygon ,
823
+ bnb_contract = ctracts . bnb ,
824
+ networks = [ ] ;
825
+ $ . each ( options , function ( key , value ) {
826
+ if ( key === "arbitrum" && ! arb_contract && thiscurrency !== "ethereum" ) { } else if ( key === "polygon" && ! polygon_contract && thiscurrency !== "ethereum" ) { } else if ( key === "bnb" && ! bnb_contract && thiscurrency !== "ethereum" ) { } else {
827
+ const nw_name = key === "bnb" ? "bnb smart chain" : key ,
828
+ nw_selected = value . selected ,
829
+ s_boxes = [ ]
830
+ $ . each ( value , function ( k , v ) {
831
+ if ( k === "selected" ) {
832
+
833
+ } else {
834
+ const selected = v . selected ,
835
+ apis = v . apis ,
836
+ api_push = [ ] ;
837
+ $ . each ( apis , function ( i , v2 ) {
838
+ api_push . push ( {
839
+ "span" : {
840
+ "data-pe" : "none" ,
841
+ "attr" : add_prefix_to_keys ( v2 ) ,
842
+ "content" : v2 . name
843
+ }
844
+ } ) ;
845
+ } ) ;
846
+ s_boxes . push ( {
847
+ "div" : {
848
+ "class" : "l2_apis" ,
849
+ "attr" : {
850
+ "data-type" : k
840
851
} ,
841
- {
852
+ "content" : [ {
853
+ "h3" : {
854
+ "content" : k
855
+ } ,
842
856
"div" : {
843
- "class" : "options"
857
+ "class" : "selectbox" ,
858
+ "content" : [ {
859
+ "input" : {
860
+ "attr" : {
861
+ "type" : "text" ,
862
+ "value" : selected . name ,
863
+ "placeholder" : translate ( "layer2" ) ,
864
+ "readonly" : "readonly"
865
+ } ,
866
+ "close" : true
867
+ } ,
868
+ "div" : {
869
+ "class" : "selectarrows icon-menu2" ,
870
+ "attr" : {
871
+ "data-pe" : "none"
872
+ }
873
+ }
874
+ } ,
875
+ {
876
+ "div" : {
877
+ "class" : "options single" ,
878
+ "content" : api_push
879
+ }
880
+ }
881
+ ]
844
882
}
845
- }
846
- ]
883
+ } ]
884
+ }
885
+ } ) ;
886
+ }
887
+ } ) ;
888
+ networks . push ( {
889
+ "div" : {
890
+ "class" : "nw2box" ,
891
+ "attr" : {
892
+ "data-network" : key
847
893
} ,
848
- "input" : {
849
- "class" : "submit" ,
850
- "attr" : {
851
- "type" : "submit" ,
852
- "value" : translate ( "okbttn" ) ,
853
- "data-currency" : thiscurrency
894
+ "content" : [ {
895
+ "h2" : {
896
+ "class" : "nwheading" ,
897
+ "content" : nw_name + switchpanel ( nw_selected , " custom" )
898
+ } ,
899
+ "div" : {
900
+ "class" : "sboxwrap hide" ,
901
+ "content" : s_boxes
854
902
}
855
- }
856
- } ]
903
+ } ]
904
+ }
905
+ } ) ;
906
+ }
907
+ } ) ;
908
+ networks . push ( {
909
+ "input" : {
910
+ "class" : "submit" ,
911
+ "attr" : {
912
+ "type" : "submit" ,
913
+ "value" : translate ( "okbttn" ) ,
914
+ "data-currency" : thiscurrency
915
+ }
916
+ }
917
+ } ) ;
918
+ const sb_render = render_html ( networks ) ,
919
+ ddat = [ {
920
+ "div" : {
921
+ "class" : "popform" ,
922
+ "content" : sb_render
857
923
}
858
924
} ] ,
859
925
content = template_dialog ( {
@@ -863,30 +929,73 @@ function edit_l2() {
863
929
"elements" : ddat
864
930
} ) ;
865
931
popdialog ( content , "triggersubmit" ) ;
866
- const optionlist = $ ( "#l2_formbox" ) . find ( ".options" ) ,
867
- ccsymbol = fetchsymbol ( thiscurrency ) ,
868
- arb_contract = contracts ( ccsymbol . symbol , "arbitrum" ) ;
869
- $ . each ( options , function ( i , value ) {
870
- if ( ! ( value === "Arbitrum (L2)" && arb_contract === false && thiscurrency !== "ethereum" ) ) {
871
- optionlist . append ( "<span data-pe='none'>" + value + "</span>" ) ;
872
- }
873
- } ) ;
874
932
}
875
933
} )
876
934
}
877
935
936
+ function l2nw_toggle ( ) {
937
+ $ ( document ) . on ( "mouseup" , "#l2_formbox h2.nwheading" , function ( e ) {
938
+ const target = $ ( e . target ) ;
939
+ if ( target . hasClass ( "switchpanel" ) ) {
940
+ return // prevent selection when deleting
941
+ }
942
+ const all_bws = $ ( "#l2_formbox" ) . find ( ".sboxwrap" ) ,
943
+ this_boxwrap = $ ( this ) . next ( ".sboxwrap" ) ;
944
+ if ( this_boxwrap . is ( ":visible" ) ) {
945
+ all_bws . slideUp ( 200 ) ;
946
+ return
947
+ }
948
+ all_bws . not ( this_boxwrap ) . slideUp ( 200 ) ;
949
+ this_boxwrap . slideDown ( 200 ) ;
950
+ } )
951
+ }
952
+
953
+ function l2nw_switch ( ) {
954
+ $ ( document ) . on ( "mouseup" , "#l2_formbox h2.nwheading .switchpanel" , function ( ) {
955
+ const this_switch = $ ( this ) ,
956
+ sboxwrap = this_switch . parent ( "h2.nwheading" ) . next ( ".sboxwrap" ) ;
957
+ if ( this_switch . hasClass ( "true" ) ) {
958
+ this_switch . removeClass ( "true" ) . addClass ( "false" ) ;
959
+ sboxwrap . slideUp ( 300 ) ;
960
+ return
961
+ }
962
+ this_switch . removeClass ( "false" ) . addClass ( "true" ) ;
963
+ } )
964
+ }
965
+
878
966
// Function to handle submission of Layer 2 settings
879
967
function submit_l2 ( ) {
880
968
$ ( document ) . on ( "click" , "#l2_formbox input.submit" , function ( e ) {
881
969
e . preventDefault ( ) ;
882
- const thiscurrency = $ ( this ) . attr ( "data-currency" ) ,
883
- thisvalue = $ ( "#l2_formbox" ) . find ( "input:first" ) . val ( ) ,
884
- csnode = cs_node ( thiscurrency , "layer2" ) ;
970
+ const payment = $ ( this ) . attr ( "data-currency" ) ,
971
+ csnode = cs_node ( payment , "layer2" ) ;
885
972
if ( csnode ) {
886
- csnode . data ( "selected" , thisvalue ) . find ( "p" ) . html ( thisvalue ) ;
973
+ const cs_node_dat = csnode . data ( "options" ) ,
974
+ nw2box = $ ( "#l2_formbox" ) . find ( ".popform > .nw2box" ) ;
975
+ nw2box . each ( function ( ) {
976
+ const this_box = $ ( this ) ,
977
+ this_network = this_box . data ( "network" ) ,
978
+ this_switch = this_box . find ( ".switchpanel" ) ,
979
+ selected = this_switch . hasClass ( "true" ) ,
980
+ l2_apis = this_box . find ( ".l2_apis" ) ;
981
+ cs_node_dat [ this_network ] . selected = selected ;
982
+ l2_apis . each ( function ( ) {
983
+ const this_nw = $ ( this ) ,
984
+ input = this_nw . find ( ".selectbox > input" ) ,
985
+ input_data = input . data ( ) ;
986
+ if ( ! $ . isEmptyObject ( input_data ) ) {
987
+ const this_type = this_nw . data ( "type" ) ,
988
+ new_selected = q_obj ( cs_node_dat , this_network + "." + this_type ) ;
989
+ if ( new_selected ) {
990
+ new_selected . selected = input_data ;
991
+ }
992
+ }
993
+ } ) ;
994
+ } ) ;
995
+ csnode . data ( "options" , cs_node_dat ) . find ( "p" ) . html ( "" ) ;
887
996
canceldialog ( ) ;
888
997
notify ( translate ( "datasaved" ) ) ;
889
- save_cc_settings ( thiscurrency , true ) ;
998
+ save_cc_settings ( payment , true ) ;
890
999
}
891
1000
} )
892
1001
}
0 commit comments