Skip to content

Commit 38fb25f

Browse files
committed
compress l2 data
1 parent 41d00ec commit 38fb25f

File tree

4 files changed

+48
-46
lines changed

4 files changed

+48
-46
lines changed

assets_js_bitrequest_coin_settings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ function reset_coinsettings_function(currency) {
13551355
coinsettings.Xpub = xpub_settings; // don't reset xpub settings
13561356
}
13571357
if (l2) {
1358-
const cs = compress_l2obj2(currency, null, true);
1358+
const cs = compress_l2obj2(currency);
13591359
br_set_local(currency + "_settings", cs, true);
13601360
append_coinsetting(currency, cs);
13611361
} else {

assets_js_bitrequest_core.js

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ function finishfunctions() {
390390
//validateaddress_vk
391391
//set_xmr_node_access
392392
//validateaddress
393-
//compress_l2obj2
394393
//check_address
395394
//check_vk
396395
send_trigger();
@@ -2559,7 +2558,7 @@ function validateaddress(ad, vk) {
25592558
if (index === 1) {
25602559
if (iserc20 === true) {
25612560
buildpage(ad, true);
2562-
append_coinsetting(currency, compress_l2obj2(currency, ccsymbol, true));
2561+
append_coinsetting(currency, compress_l2obj2(currency, ccsymbol));
25632562
save_cc_settings(currency);
25642563
}
25652564
if (glob_const.body.hasClass("showstartpage")) {
@@ -2588,35 +2587,6 @@ function validateaddress(ad, vk) {
25882587
clear_savedurl();
25892588
}
25902589

2591-
function compress_l2obj2(currency, ccsymbol, reset) {
2592-
// Initialize the result object with the base structure
2593-
const eth_settings = JSON.parse(JSON.stringify(getcoinsettings(currency))), // make a deep clone to prevent duplicates
2594-
cc_symbol = ccsymbol || q_obj(fetchsymbol(currency), "symbol"),
2595-
symbol = cc_symbol || "eth",
2596-
l2_settings = eth_settings.layer2,
2597-
ctracts = contracts(symbol),
2598-
result = {
2599-
"icon": "new-tab",
2600-
"selected": false,
2601-
"options": {}
2602-
};
2603-
// Get all networks from options
2604-
const networks = Object.entries(l2_settings.options);
2605-
2606-
// Filter and process only networks that have selected: true
2607-
networks.forEach(([network_name, network_data]) => {
2608-
if (ctracts[network_name] || currency === "ethereum") {
2609-
// Initialize this network in result if it's selected
2610-
result.options[network_name] = reset ? {} : {
2611-
"apis": network_data.apis.selected.name,
2612-
"websockets": network_data.websockets.selected.name
2613-
};
2614-
}
2615-
});
2616-
eth_settings.layer2 = result;
2617-
return eth_settings;
2618-
}
2619-
26202590
// Validates an address for a given currency using a regex pattern
26212591
function check_address(address, currency) {
26222592
const regex = getcoindata(currency).regex;

assets_js_bitrequest_ethl2.js

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ $(document).ready(function() {
3030

3131
// ** L2 Helpers **
3232

33+
//compress_l2obj2
3334
//set_l2_status_init
3435
//set_l2_status
3536
//fertch_l2s
@@ -297,11 +298,15 @@ function bnb_apis(dat) {
297298
// Function to handle editing of eth Layer 2 settings
298299
function edit_l2() {
299300
$(document).on("click", ".cc_settinglist li[data-id='layer2']", function() {
300-
const thiscurrency = $(this).children(".liwrap").attr("data-currency"),
301-
options = fertch_l2s(thiscurrency),
302-
old_format = q_obj(options, "arbitrum.selected"),
303-
l2_options = (old_format !== undefined) ? q_obj(compress_l2obj2(thiscurrency), "layer2.options") : options, // convert to compressed l2 format
304-
eth_settings = getcoinsettings(thiscurrency),
301+
const thiscurrency = $(this).children(".liwrap").attr("data-currency");
302+
let l2_options = fertch_l2s(thiscurrency);
303+
const old_format = q_obj(l2_options, "arbitrum.selected") !== undefined; // look for uncompressed l2 format
304+
if (old_format) {
305+
l2_options = q_obj(compress_l2obj2(thiscurrency), "layer2.options"); // convert to compressed l2 format
306+
const csnode = cs_node(thiscurrency, "layer2"); // update l2 settings li data
307+
csnode.data("options", l2_options);
308+
}
309+
const eth_settings = getcoinsettings(thiscurrency),
305310
eth_l2_settings = q_obj(eth_settings, "layer2.options");
306311
if (l2_options) {
307312
const ccsymbol = fetchsymbol(thiscurrency),
@@ -317,6 +322,7 @@ function edit_l2() {
317322
select = l2_options[l2],
318323
nw_selected = !empty_obj(select),
319324
s_boxes = [];
325+
320326
$.each(l2_dat, function(k, v) {
321327
const selected = v.selected
322328
if (k === "selected") return;
@@ -473,7 +479,7 @@ function submit_l2() {
473479
const this_nw = $(this),
474480
input = this_nw.find(".selectbox > input"),
475481
input_data = input.val();
476-
if (!empty_obj(input_data)) {
482+
if (input_data) {
477483
const this_type = this_nw.data("type");
478484
l2_type_obj[this_type] = input_data;
479485
}
@@ -490,6 +496,32 @@ function submit_l2() {
490496

491497
// ** L2 Helpers **
492498

499+
function compress_l2obj2(currency, ccsymbol) {
500+
// Initialize the result object with the base structure
501+
const eth_settings = JSON.parse(JSON.stringify(getcoinsettings(currency))), // make a deep clone to prevent duplicates
502+
cc_symbol = ccsymbol || q_obj(fetchsymbol(currency), "symbol"),
503+
symbol = cc_symbol || "eth",
504+
l2_settings = eth_settings.layer2,
505+
ctracts = contracts(symbol),
506+
result = {
507+
"icon": "new-tab",
508+
"selected": false,
509+
"options": {}
510+
};
511+
// Get all networks from options
512+
const networks = Object.entries(l2_settings.options);
513+
514+
// Filter and process only networks that have selected: true
515+
networks.forEach(([network_name, network_data]) => {
516+
if (ctracts[network_name] || currency === "ethereum") {
517+
// Initialize this network in result if it's selected
518+
result.options[network_name] = {};
519+
}
520+
});
521+
eth_settings.layer2 = result;
522+
return eth_settings;
523+
}
524+
493525
// Init l2 status
494526
function set_l2_status_init(sn, stat) {
495527
if (!sn) {

assets_js_lib_global_queries.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ let request = null,
283283
//activecoinsettings
284284
//getcoindat
285285
//getcoinsettings
286+
//getcoinconfig
286287
//get_erc20_data
287288
//get_erc20_settings
288-
//getcoinconfig
289289
//add_prefix_to_keys
290290
//check_params
291291
//click_pop
@@ -1135,6 +1135,13 @@ function getcoinsettings(currency) {
11351135
return get_erc20_settings();
11361136
}
11371137

1138+
// Retrieves coin configuration for a given currency
1139+
function getcoinconfig(currency) {
1140+
return glob_config.bitrequest_coin_data.find(function(filter) {
1141+
return filter.currency === currency;
1142+
});
1143+
}
1144+
11381145
// Retrieves erc20 data
11391146
function get_erc20_data() {
11401147
return glob_config.erc20_dat;
@@ -1145,13 +1152,6 @@ function get_erc20_settings() {
11451152
return glob_config.erc20_dat.settings;
11461153
}
11471154

1148-
// Retrieves coin configuration for a given currency
1149-
function getcoinconfig(currency) {
1150-
return glob_config.bitrequest_coin_data.find(function(filter) {
1151-
return filter.currency === currency;
1152-
});
1153-
}
1154-
11551155
function add_prefix_to_keys(obj, prefix = "data-") {
11561156
return Object.entries(obj).reduce((acc, [key, value]) => {
11571157
acc[prefix + key] = value;

0 commit comments

Comments
 (0)