Skip to content

Commit bd0e6df

Browse files
committed
fetch algo
1 parent 7ea1409 commit bd0e6df

File tree

4 files changed

+261
-296
lines changed

4 files changed

+261
-296
lines changed

assets_js_bitrequest_monitors.js

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,8 @@ function check_api(payment, iserc20) {
224224
function get_api_inputs_init(rd, api_data) {
225225
if (api_data) {
226226
const requestid = rd.requestid,
227-
rqid = (requestid) ? requestid : "",
228-
fetch_id = rqid + api_data.name;
229-
glob_api_attempts[fetch_id] = null; // reset api attempts
227+
rq_id = (requestid) ? requestid : "";
228+
glob_api_attempts[rq_id + api_data.name] = null; // reset api attempts
230229
get_api_inputs(rd, false, api_data);
231230
return
232231
}
@@ -261,18 +260,22 @@ function get_api_inputs(rd, rdod, api_data) {
261260
function select_api(rd, rdo, api_dat) {
262261
const txhash = rd.txhash,
263262
requestid = rd.requestid,
264-
fetch_id = (txhash) ? txhash : (requestid) ? requestid : "",
265-
glob_l2 = glob_l2network[fetch_id], // get cached l2 network
263+
rq_id = (requestid) ? requestid : "",
264+
glob_l2 = glob_l2network[rq_id], // get cached l2 network
266265
api_data = (glob_l2) ? glob_l2 : api_dat,
267266
api_name = api_data.name;
268-
glob_api_attempts[fetch_id] = true;
267+
glob_api_attempts[rq_id + api_name] = true;
269268
if (rd.lightning) {
270269
const l_fetch = lightning_fetch(rd, api_data, rdo);
271270
if (l_fetch == "exit") {
272271
return
273272
}
274273
}
275-
if (rd.payment == "monero") {
274+
if (api_name == "mymonero api") {
275+
monero_fetch(rd, api_data, rdo);
276+
return
277+
}
278+
if (api_name == "blockchair_xmr") {
276279
monero_fetch(rd, api_data, rdo);
277280
return
278281
}
@@ -314,7 +317,8 @@ function fail_dialogs(apisrc, error) {
314317
}
315318

316319
function scan_match(rd, api_data, rdo, counter, txdat, match, l2) {
317-
const src = rdo.source;
320+
const src = rdo.source,
321+
is_api = (api_data.api) ? true : false;
318322
if (src == "list") {
319323
tx_count(rdo.statuspanel, counter);
320324
}
@@ -330,7 +334,7 @@ function scan_match(rd, api_data, rdo, counter, txdat, match, l2) {
330334
}
331335
glob_pinging[txhash] = setInterval(function() {
332336
if (glob_paymentpopup.hasClass("active")) { // only when request is visible
333-
if (api_data.api) {
337+
if (is_api) {
334338
select_api(rd, rdo, api_data);
335339
} else {
336340
select_rpc(rd, rdo, api_data);
@@ -349,10 +353,12 @@ function scan_match(rd, api_data, rdo, counter, txdat, match, l2) {
349353
}
350354
if (l2) { // Save L2 Network to session storage
351355
const requestid = rd.requestid,
352-
fetchid = (txhash) ? txhash : (requestid) ? requestid : "";
353-
if (glob_l2network[fetchid] != api_data) {
354-
glob_l2network[fetchid] = api_data;
355-
br_set_session("l2source", glob_l2network, true);
356+
rq_id = (requestid) ? requestid : "";
357+
if (rq_id.length) {
358+
if (glob_l2network[rq_id] != api_data) {
359+
glob_l2network[rq_id] = api_data;
360+
br_set_session("l2source", glob_l2network, true);
361+
}
356362
}
357363
}
358364
return
@@ -362,7 +368,7 @@ function scan_match(rd, api_data, rdo, counter, txdat, match, l2) {
362368
"error": "Scanning next l2 rpc",
363369
"console": true
364370
};
365-
if (api_data.api) {
371+
if (is_api) {
366372
handle_api_fails(rd, rdo, console_l2, api_data);
367373
return
368374
}
@@ -449,8 +455,8 @@ function get_next_api(this_payment, api_name, requestid) {
449455
if (!$.isEmptyObject(apilist)) {
450456
const next_scan = apilist[apilist.findIndex(option => option.name == api_name) + 1],
451457
next_api = (next_scan) ? next_scan : apilist[0],
452-
rqid = (requestid) ? requestid : "";
453-
if (glob_api_attempts[rqid + next_api.name] !== true) {
458+
rq_id = (requestid) ? requestid : "";
459+
if (glob_api_attempts[rq_id + next_api.name] !== true) {
454460
return next_api;
455461
}
456462
}
@@ -583,7 +589,9 @@ function api_callback(requestid, nocache) {
583589
}
584590

585591
function get_rpc_inputs_init(rd, api_data) {
586-
glob_rpc_attempts[rd.requestid + api_data.url] = null; // reset api attempts
592+
const requestid = rd.requestid,
593+
rq_id = (requestid) ? requestid : "";
594+
glob_rpc_attempts[rq_id + api_data.url] = null; // reset api attempts
587595
get_rpc_inputs(rd, false, api_data);
588596
}
589597

@@ -615,10 +623,10 @@ function get_rpc_inputs(rd, rdod, api_data) {
615623
function select_rpc(rd, rdo, api_dat) {
616624
const txhash = rd.txhash,
617625
requestid = rd.requestid,
618-
fetch_id = (txhash) ? txhash : (requestid) ? requestid : "",
619-
glob_l2 = glob_l2network[fetch_id], // get cached l2 network
626+
rq_id = (requestid) ? requestid : "",
627+
glob_l2 = glob_l2network[rq_id], // get cached l2 network
620628
api_data = (glob_l2) ? glob_l2 : api_dat;
621-
glob_rpc_attempts[fetch_id] = true;
629+
glob_rpc_attempts[rq_id + api_data.url] = true;
622630
if (is_btchain(rd.payment) === true) {
623631
mempoolspace_rpc(rd, api_data, rdo, true);
624632
return
@@ -690,8 +698,8 @@ function get_next_rpc(this_payment, api_url, requestid) {
690698
if (!$.isEmptyObject(restlist)) {
691699
const next_scan = restlist[restlist.findIndex(option => option.url == api_url) + 1],
692700
next_rpc = (next_scan) ? next_scan : restlist[0],
693-
rqid = (requestid) ? requestid : "";
694-
if (glob_rpc_attempts[rqid + next_rpc.url] !== true) {
701+
rq_id = (requestid) ? requestid : "";
702+
if (glob_rpc_attempts[rq_id + next_rpc.url] !== true) {
695703
return next_rpc;
696704
}
697705
}
@@ -896,7 +904,7 @@ function init_historical_fiat_data(rd, conf, latestinput, firstinput) {
896904
hc_prefix = "historic_" + thisrequestid,
897905
historiccache = br_get_session(hc_prefix),
898906
cacheval = latestinput + latestconf;
899-
if (cacheval != historiccache) { //new input detected; call historic api
907+
if ((cacheval - historiccache) > 1) { //new input detected; call historic api
900908
br_remove_session(hc_prefix); // remove historic price cache
901909
const historic_payload = $.extend(rd, {
902910
"latestinput": latestinput,

assets_js_bitrequest_payments.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2914,7 +2914,9 @@ function saverequest(direct) {
29142914
function pendingdialog(pr) { // show pending dialog if tx is pending
29152915
request.received = true;
29162916
const prdata = pr.data(),
2917-
status = prdata.status,
2917+
requestid = prdata.requestid;
2918+
request.requestid = requestid;
2919+
const status = prdata.status,
29182920
txhash = prdata.txhash,
29192921
tl_txhash = pr.find(".transactionlist li:first").data("txhash"),
29202922
smart_txhash = (txhash) ? txhash : tl_txhash,
@@ -2968,19 +2970,6 @@ function pendingdialog(pr) { // show pending dialog if tx is pending
29682970
return
29692971
}
29702972
adjust_paymentdialog("pending", "polling", translate("txbroadcasted"));
2971-
if (thispayment == "monero") {
2972-
const address = prdata.address,
2973-
vk = request.viewkey;
2974-
if (vk) {
2975-
const account = (vk.account) ? vk.account : address,
2976-
viewkey = vk.vk;
2977-
closenotify();
2978-
init_xmr_node(34, account, viewkey, null, smart_txhash, true);
2979-
return
2980-
}
2981-
notify(translate("notmonitored"), 500000, "yes");
2982-
return
2983-
}
29842973
pick_monitor(smart_txhash, false);
29852974
}
29862975
}

0 commit comments

Comments
 (0)