Skip to content

Commit ee51214

Browse files
committed
calculate amounts
1 parent a127c2f commit ee51214

7 files changed

+188
-152
lines changed

assets_js_bitrequest_core.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5283,6 +5283,7 @@ function append_request(rd) {
52835283
</div>\
52845284
<p class='rq_date' title='" + date_full + "'>" + time_display + "</p><br/>\
52855285
<div class='pmetastatus' data-count='0'>+ 0</div>\
5286+
<div class='tx_loader'>" + loading_dots("scanning transactions") + "</div>\
52865287
<div data-rel='" + payment_url + "' class='payrequest button" + crypto_class + "'>\
52875288
<span class='icon-qrcode'>" + tl("pay") + "</span>\
52885289
</div>\

assets_js_bitrequest_fetchblocks.js

Lines changed: 48 additions & 89 deletions
Large diffs are not rendered by default.

assets_js_bitrequest_monitors.js

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ function process_transaction_data(rd, dl) {
182182
br_set_session("monitor_timer", now());
183183
}
184184
const api_info = check_api(rd.payment),
185-
api_data = api_info.data;
186-
rdo.thislist.removeClass("pmstatloaded");
187-
update_transaction_count(rdo.statuspanel, "reset");
185+
api_data = api_info.data,
186+
current_list = rdo.thislist
187+
current_list.addClass("loading").removeClass("pmstatloaded");
188188
route_network_request(rd, api_data, rdo);
189189
return
190190
}
@@ -206,7 +206,7 @@ function finalize_request_state(rdo) {
206206
// src === "requests"
207207
const current_list = rdo.thislist;
208208
if (current_list && current_list.hasClass("scan")) {
209-
current_list.removeClass("scan open").addClass("pmstatloaded");
209+
current_list.removeClass("scan open loading").addClass("pmstatloaded");
210210
const request_id = rdo.requestid,
211211
transaction_list = rdo.transactionlist,
212212
transaction_items = transaction_list.children("li");
@@ -348,15 +348,12 @@ function route_blockchain_rpc(rd, api_data, rdo) {
348348
}
349349

350350
// Processes transaction scan results and handles Ethereum L2, confirmations, and UI updates based on match type
351-
function process_scan_results(rd, api_data, rdo, counter, tx_details, l2) {
351+
function process_scan_results(rd, api_data, rdo, tx_details, l2) {
352352
glob_let.apikey_fails = false;
353353
const src = rdo.source,
354354
pending = rdo.pending
355355
tx_hash = tx_details.txhash || rd.txhash;
356356
if (src === "requests") {
357-
if (counter) {
358-
update_transaction_count(rdo.statuspanel, counter);
359-
}
360357
const current_list = rdo.thislist;
361358
if (current_list) {
362359
current_list.removeClass("no_network");
@@ -722,7 +719,7 @@ function create_transaction_item(tx_details, request_type) {
722719
unconfirmed_text = tl("unconfirmedtx"),
723720
checked_span = "<span class='icon-checkmark' title='" + confirmation_title + "'></span>",
724721
confirmation_span = is_confirmed ? checked_span : confirmations ? "<div class='txli_conf' title='" + confirmation_title + "'><div class='confbar'></div><span>" + confirmation_title + "</span></div>" :
725-
"<div class='txli_conf' title='" + unconfirmed_text + "'><div class='confbar'></div><span>" + unconfirmed_text + "</span></div>",
722+
"<div class='txli_conf unconfirmed' title='" + unconfirmed_text + "'><div class='confbar'></div><span>" + unconfirmed_text + "</span></div>",
726723
tx_list_item = $("<li><div class='txli_content'>" + formatted_date + confirmation_span + "<div class='txli_conf txl_canceled'><span class='icon-blocked'></span>" + tl("canceled") + "</div><span class='tx_val'> + " + value_string + " <span class='icon-eye show_tx' title='view on blockexplorer'></span></span></div></li>");
727724
if (glob_let.tx_list.includes(tx_hash)) { // check for indexed transaction id's
728725
return request_type === "outgoing" ? null : tx_list_item;
@@ -787,11 +784,12 @@ function validate_payment_amounts(rd, rdo) {
787784
no_conf = rd.no_conf || first_confirmations === false,
788785
conf = no_conf ? 0 : first_confirmations,
789786
latest_transaction_time = first_transaction.data("transactiontime"),
790-
time_offset = Math.abs(now() - (first_transaction_time - glob_const.timezone)),
791-
single_transaction = transaction_count === 1,
792-
is_recent = time_offset < 300000 && single_transaction,
787+
timezone = glob_const.timezone,
788+
first_time_offset = parseInt(now() - (first_transaction_time - timezone)),
789+
last_time_offset = parseInt(now() - (latest_transaction_time - timezone)),
790+
is_recent = (first_time_offset < 300000 && last_time_offset < 300000),
793791
crypto_amount = parseFloat(rd.cc_amount),
794-
amount_margin = 0.95;
792+
amount_margin = 0.97;
795793
let recent_data = false,
796794
transaction_counter = 0,
797795
crypto_status = "pending",
@@ -813,16 +811,19 @@ function validate_payment_amounts(rd, rdo) {
813811
crypto_payment_timestamp = transaction_data.transactiontime,
814812
crypto_transaction_hash = transaction_data.txhash,
815813
total_crypto_amount += parseFloat(transaction_data.ccval) || 0; // sum of outputs
816-
if (crypto_confirmations >= correction_confirmations || no_conf || transaction_data.setconfirmations === false) { // check all confirmations + whitelist for currencies unable to fetch confirmations
817-
is_crypto_confirmed = true;
818-
if (total_crypto_amount >= crypto_amount * amount_margin) { // compensation for small fluctuations in rounding amount
819-
current_transaction.addClass("exceed").nextAll().addClass("exceed");
820-
return false;
814+
if (total_crypto_amount >= crypto_amount * amount_margin) { // compensation for small fluctuations in rounding amount
815+
current_transaction.prevAll().remove();
816+
if (crypto_confirmations >= correction_confirmations || no_conf || transaction_data.setconfirmations === false) { // check all confirmations + whitelist for currencies unable to fetch confirmations
817+
is_crypto_confirmed = true;
818+
} else {
819+
is_crypto_confirmed = false;
821820
}
822-
} else {
823-
is_crypto_confirmed = false;
821+
return false;
824822
}
825823
});
824+
if (transaction_counter) {
825+
update_transaction_count(rdo.statuspanel, transaction_counter);
826+
}
826827
const conf_bar = transaction_items.find(".confbar");
827828
if (conf_bar.length) {
828829
conf_bar.each(function(i) {
@@ -832,7 +833,7 @@ function validate_payment_amounts(rd, rdo) {
832833
if (total_crypto_amount >= crypto_amount * amount_margin) { // compensation for small fluctuations in rounding amount
833834
if (is_crypto_confirmed === false) { // check confirmations outside the loop
834835
crypto_status = "pending",
835-
crypto_pending = single_transaction && crypto_transaction_hash ? "polling" : pending_status; // switch to tx polling if there's only one transaction and txhash is known
836+
crypto_pending = transaction_count === 1 && crypto_transaction_hash ? "polling" : pending_status; // switch to tx polling if there's only one transaction and txhash is known
836837
} else {
837838
crypto_status = "paid",
838839
crypto_pending = "no";
@@ -851,7 +852,7 @@ function validate_payment_amounts(rd, rdo) {
851852
local_exchange_rate = fiat_exchange_rates ? fiat_exchange_rates[rd.fiatcurrency] : null,
852853
usd_eur_exchange_rate = fiat_exchange_rates ? fiat_exchange_rates.usd : null;
853854
if (local_exchange_rate && usd_eur_exchange_rate) {
854-
const usd_rate = crypto_exchange_rates ? crypto_exchange_rates.ccrate : null;
855+
const usd_rate = crypto_exchange_rates.ccrate || null;
855856
if (usd_rate) {
856857
const usd_value = total_crypto_amount * usd_rate,
857858
eur_value = usd_value / usd_eur_exchange_rate;
@@ -892,11 +893,9 @@ function update_transaction_count(status_panel, count) {
892893
status_panel.attr("data-count", 0).text("+ " + 0);
893894
return
894895
}
895-
const current_count = parseInt(status_panel.attr("data-count")),
896-
new_count = current_count + count;
897-
if (!new_count) return
898-
status_panel.attr("data-count", new_count).text("+ " + new_count);
899-
if (new_count > 1) {
896+
if (!count) return
897+
status_panel.attr("data-count", count).text("+ " + count);
898+
if (count > 1) {
900899
status_panel.closest(".rqli").find(".metalist .show_tx").hide();
901900
}
902901
}
@@ -935,7 +934,8 @@ function fetch_fiat_rates(rd, rdo, api_list, fiat_api) {
935934
const fiat_currency = rd.fiatcurrency;
936935
if (fiat_currency) {
937936
const currency_symbol = fiat_currency.toUpperCase(),
938-
payload = get_historic_fiatprice_api_payload(fiat_api, currency_symbol, rd.latestinput);
937+
payload = get_historic_fiatprice_api_payload(fiat_api, currency_symbol, rd.latestinput),
938+
current_list = rdo.thislist;
939939
api_proxy({
940940
"api": fiat_api,
941941
"search": payload,
@@ -1076,16 +1076,14 @@ function fetch_crypto_rates(rd, rdo, fiat_api, api_list, api, currency_rate, usd
10761076
api_result;
10771077
if (data && !data.error) {
10781078
const request_list = rdo.thislist,
1079-
tx_list = request_list.find(".transactionlist li"),
1080-
tx_list_length = tx_list.length,
1081-
tx_reverse = tx_list_length > 1 ? tx_list.get().reverse() : tx_list,
1079+
transaction_items = request_list.find(".transactionlist li"),
1080+
transaction_reverse = transaction_items.length > 1 ? transaction_items.get().reverse() : transaction_items,
10821081
latest_confirm = rd.latestconf,
10831082
total_amount = rd.amount,
1084-
set_confirmations = rd.set_confirmations || 1; // Default to 1
1085-
is_erc20 = rd.erc20,
1083+
set_confirmations = rd.set_confirmations || 1, // Default to 1
10861084
historic_usd_value = (total_amount / currency_rate) * usd_rate,
1087-
margin = historic_usd_value < 2 ? 0.60 : 0.95; // be flexible with small amounts
1088-
let tx_counter = 0,
1085+
margin = historic_usd_value < 2 ? 0.60 : 0.97; // be flexible with small amounts
1086+
let transaction_counter = 0,
10891087
confirmations = 0,
10901088
paymenttimestamp,
10911089
txhash,
@@ -1094,12 +1092,13 @@ function fetch_crypto_rates(rd, rdo, fiat_api, api_list, api, currency_rate, usd
10941092
confirmed = false,
10951093
status = "pending",
10961094
pending = rd.pending;
1097-
$(tx_reverse).each(function(i) {
1098-
tx_counter++;
1099-
const current_node = $(this),
1100-
node_data = current_node.data(),
1101-
transaction_timestamp = node_data.transactiontime,
1102-
transaction_value = node_data.ccval,
1095+
$(transaction_reverse).each(function(i) {
1096+
transaction_counter++;
1097+
const current_transaction = $(this),
1098+
transaction_data = current_transaction.data(),
1099+
correction_confirmations = transaction_data.instant_lock ? 0 : set_confirmations; // correction if dash instant_lock
1100+
transaction_timestamp = transaction_data.transactiontime,
1101+
transaction_value = transaction_data.ccval,
11031102
values = {
11041103
"fiatapisrc": fiat_api,
11051104
"apisrc": api,
@@ -1110,24 +1109,27 @@ function fetch_crypto_rates(rd, rdo, fiat_api, api_list, api, currency_rate, usd
11101109
},
11111110
historic_object = match_price_timestamps(api, values, data, transaction_timestamp),
11121111
historic_price = historic_object.price,
1113-
conf_correct = node_data.instant_lock ? 0 : set_confirmations; // correction if dash instant_lock
1114-
current_node.data("historic", historic_object);
1115-
confirmations = node_data.confirmations, // check confirmations
1112+
conf_correct = transaction_data.instant_lock ? 0 : set_confirmations; // correction if dash instant_lock
1113+
current_transaction.data("historic", historic_object);
1114+
confirmations = transaction_data.confirmations, // check confirmations
11161115
paymenttimestamp = transaction_timestamp,
1117-
txhash = node_data.txhash,
1116+
txhash = transaction_data.txhash,
11181117
receivedamount += parseFloat(transaction_value) || 0; // sum of outputs CC
1119-
if ((historic_price && confirmations >= conf_correct) || rd.no_conf === true || node_data.setconfirmations === false) { // check all confirmations + whitelist for currencies unable to fetch confirmations
1120-
confirmed = true;
1121-
} else {
1122-
confirmed = false;
1123-
}
11241118
let current_usd_sum = received_usd += parseFloat(historic_price * transaction_value) || 0;
11251119
if (current_usd_sum >= historic_usd_value * margin) { //minus 5% dollar for volatility compensation
1126-
current_node.addClass("exceed").nextAll().addClass("exceed");
1120+
current_transaction.prevAll().remove();
1121+
if ((historic_price && confirmations >= conf_correct) || rd.no_conf === true || transaction_data.setconfirmations === false) { // check all confirmations + whitelist for currencies unable to fetch confirmations
1122+
confirmed = true;
1123+
} else {
1124+
confirmed = false;
1125+
}
11271126
return false;
11281127
}
11291128
});
1130-
const conf_bar = tx_list.find(".confbar");
1129+
if (transaction_counter) {
1130+
update_transaction_count(rdo.statuspanel, transaction_counter);
1131+
}
1132+
const conf_bar = transaction_items.find(".confbar");
11311133
if (conf_bar.length) {
11321134
conf_bar.each(function(i) {
11331135
animate_confbar($(this), i);
@@ -1137,7 +1139,7 @@ function fetch_crypto_rates(rd, rdo, fiat_api, api_list, api, currency_rate, usd
11371139
if (received_usd >= historic_usd_value * margin) { // check total incoming amount // minus 5% dollar for volatility compensation
11381140
if (confirmed === false) { // check confirmations outside the loop
11391141
status = "pending",
1140-
pending = tx_counter === 1 && txhash ? "polling" : pending; // switch to tx polling if there's only one transaction and txhash is known
1142+
pending = transaction_counter === 1 && txhash ? "polling" : pending; // switch to tx polling if there's only one transaction and txhash is known
11411143
} else {
11421144
status = "paid",
11431145
pending = "no";

assets_js_bitrequest_payments.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3349,15 +3349,14 @@ function update_request(update_args, should_save) {
33493349
request_element.addClass("shownotification");
33503350
}
33513351
const transaction_list = request_element.find(".transactionlist"),
3352-
valid_transactions = current_status === "archive_pending" ? transaction_list.find("li") : transaction_list.find("li.exceed"); // save all when archiving
3352+
valid_transactions = transaction_list.find("li");
33533353
if (valid_transactions.length > 0) {
33543354
const transaction_data = [];
33553355
valid_transactions.each(function() {
33563356
transaction_data.push($(this).data());
33573357
});
33583358
update_args.txhistory = transaction_data;
33593359
}
3360-
transaction_list.find("li").not(valid_transactions).slideUp(300);
33613360
setTimeout(function() {
33623361
request_element.removeClass("shownotification");
33633362
}, 3000);

assets_js_lib_global_queries.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ let request = null,
366366
//sanitize_url
367367
//is_valid_url_or_ip
368368

369+
// ** Animations: **
370+
// loading_dots();
371+
369372
// ** Core Storage Functions: **
370373

371374
// Tests browser's localStorage API availability through write and remove operations
@@ -1619,4 +1622,11 @@ function is_valid_url_or_ip(input) {
16191622
is_valid_ipv6(clean_url) ||
16201623
is_valid_localhost(clean_url) ||
16211624
is_valid_onion(clean_url);
1625+
}
1626+
1627+
// ** Animations: **
1628+
1629+
// loading_dots;
1630+
function loading_dots(text) {
1631+
return "<div class='loading-container'> <div class='loading-text'>" + text + "</div><div class='loading-dots'><div class='dot'></div><div class='dot'></div><div class='dot'></div></div></div>";
16221632
}

assets_styles_payments.css

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,58 @@ html.inframe #paymentdialogbox #view_tx,
283283
padding: 0 0 0 0.5em;
284284
}
285285

286+
.loading-container {
287+
display: flex;
288+
align-items: center;
289+
}
290+
291+
.loading-text {
292+
margin-right: 0.25em;
293+
}
294+
295+
.loading-dots {
296+
position: relative;
297+
padding-top: 0.2em;
298+
}
299+
300+
.dot {
301+
position: absolute;
302+
top: 0.25em;
303+
transform: translateY(-50%);
304+
width: 0.35em;
305+
height: 0.35em;
306+
border-radius: 50%;
307+
background-color: #aaa;
308+
opacity: 0;
309+
}
310+
311+
.dot:nth-child(1) {
312+
left: 0;
313+
animation: showdot 2s infinite;
314+
}
315+
316+
.dot:nth-child(2) {
317+
left: 0.5em;
318+
animation: showdot 2s infinite 0.5s;
319+
}
320+
321+
.dot:nth-child(3) {
322+
left: 1em;
323+
animation: showdot 2s infinite 1s;
324+
}
325+
326+
@keyframes showdot {
327+
328+
0%,
329+
100% {
330+
opacity: 0;
331+
}
332+
333+
50% {
334+
opacity: 1;
335+
}
336+
}
337+
286338

287339
/* structure */
288340

0 commit comments

Comments
 (0)