Skip to content

Commit 5685b28

Browse files
committed
misc improvements
1 parent f7c5851 commit 5685b28

8 files changed

+84
-76
lines changed

assets_js_bitrequest_bip39.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ $(document).ready(function() {
133133
phrase_info();
134134
//phrase_info_pu
135135
//list_compatible_wallets
136-
//get_wallet_icon_url
137136
phrase_coin_info();
138137
toggle_dpaths();
139138
//display_coin_info
@@ -1793,7 +1792,7 @@ function phrase_info_pu(selected_coin) {
17931792
if (platform_url && wallet_config.seed === true) {
17941793
const wallet_name = wallet_config.name,
17951794
wallet_site = wallet_config.website,
1796-
wallet_logo = "<img src='" + get_wallet_icon_url(wallet_name) + "' class='wallet_icon' onerror=\"this.src='wp_holder.png'\">";
1795+
wallet_logo = get_aws_icon_url(wallet_name);
17971796
wallet_list += "<li><a href='" + wallet_site + "' target='_blank' class='exit app_dll'>" + wallet_logo + wallet_name +
17981797
"</a><a href='" + platform_url + "' target='_blank' class='exit store_tag'>" + store_badge + "</a></li>";
17991798
}
@@ -1886,7 +1885,7 @@ function list_compatible_wallets(coin) {
18861885
if (platform_url && wallet_config.seed === true) {
18871886
const wallet_name = wallet_config.name,
18881887
wallet_site = wallet_config.website,
1889-
wallet_logo = "<img src='" + get_wallet_icon_url(wallet_name) + "' class='wallet_icon' onerror=\"this.src='wp_holder.png'\">";
1888+
wallet_logo = get_aws_icon_url(wallet_name);
18901889
wallet_list += "<li><a href='" + wallet_site + "' target='_blank' class='exit app_dll'>" + wallet_logo + wallet_name +
18911890
"</a><a href='" + platform_url + "' target='_blank' class='exit store_tag'>" + store_badge + "</a></li>";
18921891
}
@@ -1903,11 +1902,6 @@ function list_compatible_wallets(coin) {
19031902
});
19041903
}
19051904

1906-
// Builds wallet icon URL with wallet name
1907-
function get_wallet_icon_url(wallet_name) {
1908-
return glob_const.aws_bucket + "img_icons_wallet-icons_" + wallet_name + ".png";
1909-
}
1910-
19111905
// Handles coin icon click to show coin-specific info
19121906
function phrase_coin_info() {
19131907
$(document).on("click", "#pi_icons img", function() {

assets_js_bitrequest_config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1937,7 +1937,7 @@ const glob_multi_wallets = {
19371937
{
19381938
"id": "api_proxy",
19391939
"heading": "API Proxy",
1940-
"selected": glob_const.hosted_proxy,
1940+
"selected": glob_const.hosted_proxy.proxy,
19411941
"custom_proxies": [],
19421942
"icon": "icon-sphere"
19431943
},

assets_js_bitrequest_ethl2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ function edit_l2() {
334334
$.each(apis, function(i, v2) {
335335
const node_name = v2.name,
336336
node_icon_url = get_node_icon(node_name),
337-
node_icon = (node_icon_url) ? "<img src='" + fetch_aws(node_icon_url) + ".png' class='icon' onerror=\"this.src='wp_holder.png'\">" : "";
337+
node_icon = (node_icon_url) ? "<img src='" + fetch_aws(node_icon_url) + ".png' class='icon'/>" : "";
338338
api_push.push({
339339
"span": {
340340
"class": "optionwrap",

assets_js_bitrequest_payments.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3034,7 +3034,7 @@ function download_wallet(currency) {
30343034
if (platform_url) {
30353035
const wallet_name = wallet_info.name,
30363036
wallet_website = wallet_info.website,
3037-
wallet_icon = is_lightning ? "<img src='img_logos_btc-lnd.png' class='wallet_icon'/>" : "<img src='" + get_wallet_icon_url(wallet_name) + "' class='wallet_icon' onerror=\"this.src='wp_holder.png'\">",
3037+
wallet_icon = is_lightning ? "<img src='img_logos_btc-lnd.png' class='wallet_icon'/>" : get_aws_icon_url(wallet_name),
30383038
wallet_item = "<li><a href='" + wallet_website + "' target='_blank' class='exit app_dll'>" + wallet_icon + wallet_name + "</a><a href='" + platform_url + "' target='_blank' class='exit store_tag'>" + store_tag + "</a></li>";
30393039
wallet_container.append(wallet_item);
30403040
}

assets_js_bitrequest_rpcs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ function create_rpc_node_element(api_list, is_live, node_id, node_config, is_sel
486486
display_name = setting_sub_address(node_name, stripped_url, node_config.custom) + vendor_string + version_string,
487487
node_icon_url = get_node_icon(node_name),
488488
default_class = custom ? "" : " default",
489-
node_icon = (node_icon_url) ? "<img src='" + fetch_aws(node_icon_url) + ".png' class='icon' onerror=\"this.src='wp_holder.png'\">" : "",
489+
node_icon = (node_icon_url) ? "<img src='" + fetch_aws(node_icon_url) + ".png' class='icon'/>" : "",
490490
node_element = $("<div class='optionwrap" + status_class + selected_class + default_class + "' style='display:none' data-pe='none' title='" + stripped_url + "'><span data-value='" + node_url + "' data-pe='none'>" + node_icon + "<span class='cstat'>•</span> " + display_name + "</span><div class='opt_icon_box' data-pe='none'><div class='opt_icon icon-bin' data-pe='none'></div></div>");
491491
node_element.data(node_config).appendTo(api_list);
492492
node_element.slideDown(500);

assets_js_bitrequest_settings.js

Lines changed: 52 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,8 +2629,8 @@ function trigger_proxy_dialog() {
26292629
function pick_api_proxy() {
26302630
$(document).on("click", "#api_proxy", function() {
26312631
const proxies = all_proxies("display"),
2632-
proxy = d_proxy();
2633-
const content = "\
2632+
proxy = d_proxy(),
2633+
content = "\
26342634
<div class='formbox' id='proxyformbox'>\
26352635
<h2 class='icon-sphere'>API Proxy</h2>\
26362636
<div class='popnotify'></div>\
@@ -2658,12 +2658,17 @@ function pick_api_proxy() {
26582658
</div>";
26592659
popdialog(content, "triggersubmit");
26602660
if (glob_const.phpsupport === true) {
2661-
const protocol = glob_const.localserver ? glob_const.w_loc.protocol + "//" : "",
2661+
const protocol = glob_let.localserver ? glob_const.w_loc.protocol + "//" : "",
26622662
port = glob_const.w_loc.port,
26632663
portstr = port.length ? ":" + port : "",
2664-
url = complete_url(protocol + glob_const.thishostname + portstr + location.pathname);
2665-
if ($.inArray(url, proxies) === -1) {
2666-
proxies.push(url);
2664+
url = complete_url(protocol + glob_const.thishostname + portstr + location.pathname),
2665+
proxy_object = {
2666+
"proxy": url,
2667+
"display": true,
2668+
"tor": false
2669+
}
2670+
if ($.inArray(proxy_object, proxies) === -1) {
2671+
proxies.push(proxy_object);
26672672
}
26682673
}
26692674
if ($.inArray(glob_const.hosted_proxy, proxies) === -1) {
@@ -2672,19 +2677,20 @@ function pick_api_proxy() {
26722677
const options = $("#proxyformbox").find(".options");
26732678
$.each(proxies, function(key, value) {
26742679
const selected = (value === proxy),
2675-
dfault = objectkey_in_array(glob_const.proxy_list, "proxy", value);
2680+
dfault = objectkey_in_array(glob_const.proxy_list, "proxy", value.proxy);
26762681
test_append_proxy(options, key, value, selected, dfault);
26772682
});
26782683
})
26792684
}
26802685

26812686
// Validates proxy endpoint availability via API ping test
26822687
function test_append_proxy(options, key, value, selected, dfault) {
2688+
const proxy = value.proxy;
26832689
$.ajax({
26842690
"method": "POST",
26852691
"cache": false,
26862692
"timeout": 5000,
2687-
"url": value + "/proxy/v1/ln/api/",
2693+
"url": proxy + "/proxy/v1/ln/api/",
26882694
"data": {
26892695
"ping": true
26902696
}
@@ -2702,10 +2708,11 @@ function test_append_proxy(options, key, value, selected, dfault) {
27022708

27032709
// Renders proxy option with online status indicator and delete button
27042710
function proxy_option_li(options, live, key, value, selected, dfault) {
2705-
const status = live ? " live" : " offline",
2706-
icon = live ? "connection" : "wifi-off",
2711+
const proxy = value.proxy,
2712+
status = live ? " live" : " offline",
2713+
tor = value.tor ? "<div class='opt_icon c_stat icon-tor' title='TOR support' data-pe='none'></div>" : "",
27072714
def = dfault ? " default" : "",
2708-
option = $("<div class='optionwrap" + status + def + "' style='display:none' data-pe='none'><span data-value='" + value + "' data-pe='none'>" + value + "</span><div class='opt_icon_box' data-pe='none'><div class='opt_icon c_stat icon-" + icon + "' data-pe='none'></div><div class='opt_icon icon-bin' data-pe='none'></div></div>");
2715+
option = $("<div class='optionwrap" + status + def + "' style='display:none' data-pe='none'><span data-value='" + proxy + "' data-pe='none'><span class='cstat'>•</span> " + proxy + "</span><div class='opt_icon_box' data-pe='none'>" + tor + "<div class='opt_icon icon-bin' data-pe='none'></div></div>");
27092716
options.append(option);
27102717
option.slideDown(500);
27112718
}
@@ -2760,17 +2767,17 @@ function test_custom_proxy(value) {
27602767
const node = $("#api_proxy"),
27612768
data = node.data(),
27622769
proxies = data.custom_proxies,
2763-
url = complete_url(value);
2764-
if ($.inArray(url, proxies) !== -1 || objectkey_in_array(glob_const.proxy_list, "url", url)) {
2770+
proxy = complete_url(value);
2771+
if (objectkey_in_array(glob_const.proxy_list, "proxy", proxy) || objectkey_in_array(proxies, "proxy", proxy)) {
27652772
popnotify("error", tl("proxyexists"));
27662773
return false;
27672774
}
2768-
if (url.indexOf("http") > -1) {
2775+
if (proxy.indexOf("http") > -1) {
27692776
$.ajax({
27702777
"method": "POST",
27712778
"cache": false,
27722779
"timeout": 5000,
2773-
"url": url + "/proxy/v1/",
2780+
"url": proxy + "/proxy/v1/",
27742781
"data": {
27752782
"custom": "add",
27762783
"api_url": "x" // dummy value, don't remove
@@ -2787,12 +2794,19 @@ function test_custom_proxy(value) {
27872794
return
27882795
}
27892796
}
2790-
if (resp.custom) {
2791-
proxies.push(url);
2797+
if (resp.custom === "add") {
2798+
const tor = q_obj(e, "ping.tor"),
2799+
display = true,
2800+
proxy_object = {
2801+
proxy,
2802+
display,
2803+
tor
2804+
}
2805+
proxies.push(proxy_object);
27922806
set_setting("api_proxy", {
2793-
"selected": url,
2807+
"selected": proxy_object.proxy,
27942808
"custom_proxies": proxies
2795-
}, url);
2809+
}, proxy);
27962810
canceldialog();
27972811
notify(tl("datasaved"));
27982812
save_settings();
@@ -2803,7 +2817,7 @@ function test_custom_proxy(value) {
28032817
}
28042818
}
28052819
popnotify("error", tl("unabletopost", {
2806-
"fixed_url": url
2820+
"fixed_url": proxy
28072821
}));
28082822
}).fail(function(xhr, stat, err) {
28092823
popnotify("error", tl("unabletoconnect"));
@@ -2820,32 +2834,30 @@ function remove_proxy() {
28202834
const node = "api_proxy",
28212835
proxies = get_setting(node, "custom_proxies");
28222836
if (proxies.length > 0) {
2823-
const opt = $(this).closest(".optionwrap"),
2824-
isDefault = opt.hasClass("default"),
2825-
val = opt.find("> span").attr("data-value");
2826-
if (isDefault === true) {
2837+
const opt = $(this).closest(".optionwrap");
2838+
if (opt.hasClass("default")) {
28272839
play_audio(glob_const.funk);
28282840
topnotify(tl("removedefaultnode"));
2829-
} else {
2830-
const result = confirm(tl("confirmremovenode", {
2841+
return
2842+
}
2843+
const val = opt.find("> span").attr("data-value"),
2844+
result = confirm(tl("confirmremovenode", {
28312845
"thisval": val
28322846
}));
2833-
if (result) {
2834-
const filtered = $.grep(proxies, function(value) {
2835-
return value !== val;
2836-
});
2837-
opt.slideUp(500, function() {
2838-
$(this).remove();
2839-
});
2840-
set_setting(node, {
2841-
"custom_proxies": filtered
2842-
});
2843-
notify(tl("proxyremoved"));
2844-
save_settings();
2845-
}
2847+
if (result) {
2848+
const filtered = $.grep(proxies, function(value) {
2849+
return value.proxy !== val;
2850+
});
2851+
opt.slideUp(500, function() {
2852+
$(this).remove();
2853+
});
2854+
set_setting(node, {
2855+
"custom_proxies": filtered
2856+
});
2857+
notify(tl("proxyremoved"));
2858+
save_settings();
28462859
}
28472860
}
2848-
return false;
28492861
})
28502862
}
28512863

assets_js_lib_global_queries.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ const br_bipobj = br_get_local("bpdat", true),
3030
"tor": true
3131
}
3232
],
33-
displayed_proxies = extrac_filtered_keys(br_proxy_list, "proxy", "display"),
33+
displayed_proxies = filter_object_array(br_proxy_list, "display", true),
3434
br_hosted_proxy = random_array_item(displayed_proxies), // load balance proxies
35-
tor_proxies = extrac_filtered_keys(br_proxy_list, "proxy", "tor"),
35+
tor_proxies = filter_object_array(br_proxy_list, "tor", true),
3636
tor_proxy = random_array_item(tor_proxies), // pick tor proxy
3737
br_firebase_dynamic_link_domain = "bitrequest.page.link",
3838
br_androidpackagename = "io.bitrequest.app",
@@ -279,6 +279,7 @@ let request = null,
279279
//adjust_objectarray
280280
//dom_to_array
281281
//clone
282+
//objectkey_in_array
282283
//objectkey_from_array
283284
//value_in_array
284285
//find_object_index
@@ -290,6 +291,7 @@ let request = null,
290291
//getcc_icon
291292
//click_pop
292293
//highlight_json_syntax
294+
//get_aws_icon_url
293295

294296
// ** Device & Platform Detection: **
295297
//detect_device_type
@@ -315,8 +317,7 @@ let request = null,
315317
//d_proxy
316318
//all_global_proxies
317319
//all_proxies
318-
//extract_keys
319-
//extrac_filtered_keys
320+
//filter_object_array
320321
//fetch_aws
321322

322323
// ** Data Access & Query Functions: **
@@ -775,6 +776,11 @@ function highlight_json_syntax(json) {
775776
});
776777
}
777778

779+
// Builds wallet icon URL with wallet name
780+
function get_aws_icon_url(wallet_name, clas = "wallet_icon", ext = "png") {
781+
return "<img src='" + glob_const.aws_bucket + "img_icons_wallet-icons_" + wallet_name + "." + ext + "' class='" + clas + "' onerror=\"this.src='wp_holder.png'\">";
782+
}
783+
778784
// ** Device & Platform Detection: **
779785

780786
// Rotates to next available proxy server while preventing request overflow
@@ -1094,7 +1100,7 @@ function api_proxy(ad, p_proxy) {
10941100
// add tor proxy and stringify payload
10951101
if (payload) {
10961102
if (is_onion) {
1097-
payload.tor_proxy = glob_const.tor_proxy;
1103+
payload.tor_proxy = glob_const.tor_proxy.proxy;
10981104
}
10991105
ad.params.data = JSON.stringify(payload);
11001106
}
@@ -1211,7 +1217,7 @@ function d_proxy() {
12111217
// Returns (filtered) default proxy lists
12121218
function all_global_proxies(filter) {
12131219
const global_proxies = glob_const.proxy_list,
1214-
proxy_list = (filter) ? extrac_filtered_keys(global_proxies, "proxy", filter) : extract_keys(global_proxies, "proxy");
1220+
proxy_list = (filter) ? filter_object_array(global_proxies, filter, true) : global_proxies;
12151221
return proxy_list;
12161222
}
12171223

@@ -1223,14 +1229,9 @@ function all_proxies(filter) {
12231229
return proxy_list.concat(custom_proxies);
12241230
}
12251231

1226-
// Extracts object from array
1227-
function extract_keys(array, key) {
1228-
return array.map(item => item[key]);
1229-
}
1230-
1231-
// Extracts object from array by filter value
1232-
function extrac_filtered_keys(array, extract, filter) {
1233-
return array.filter(item => item[filter] === true).map(item => item[extract]);
1232+
// Filters array by object key value
1233+
function filter_object_array(array, key, val) {
1234+
return array.filter(item => item[key] === val);
12341235
}
12351236

12361237
// Constructs complete AWS S3 URL for given filename

0 commit comments

Comments
 (0)