@@ -781,11 +781,11 @@ function validate_payment_amounts(rd, rdo) {
781
781
if ( first_transaction_time ) {
782
782
const is_crypto = rd . iscrypto ,
783
783
pending_status = rd . pending ,
784
- required_confirmations = rd . set_confirmations ,
785
- confirmation_interval = required_confirmations === false ? 0 : ( required_confirmations ? parseInt ( required_confirmations ) : 1 ) ,
786
- minimum_confirmations = rd . lightning ? 1 : confirmation_interval , // set minimum confirmations to 1
784
+ set_confirmations = rd . set_confirmations || 1 , // set minimum confirmations to 1
787
785
first_transaction = transaction_items . first ( ) ,
788
786
first_confirmations = first_transaction . data ( "confirmations" ) ,
787
+ no_conf = rd . no_conf || first_confirmations === false ,
788
+ conf = no_conf ? 0 : first_confirmations ,
789
789
latest_transaction_time = first_transaction . data ( "transactiontime" ) ,
790
790
time_offset = Math . abs ( now ( ) - ( first_transaction_time - glob_const . timezone ) ) ,
791
791
single_transaction = transaction_count === 1 ,
@@ -808,27 +808,27 @@ function validate_payment_amounts(rd, rdo) {
808
808
transaction_counter ++ ;
809
809
const current_transaction = $ ( this ) ,
810
810
transaction_data = current_transaction . data ( ) ,
811
- correction_confirmations = transaction_data . instant_lock ? 0 : minimum_confirmations ; // correction if dash instant_lock
811
+ correction_confirmations = transaction_data . instant_lock ? 0 : set_confirmations ; // correction if dash instant_lock
812
812
crypto_confirmations = transaction_data . confirmations ,
813
813
crypto_payment_timestamp = transaction_data . transactiontime ,
814
814
crypto_transaction_hash = transaction_data . txhash ,
815
815
total_crypto_amount += parseFloat ( transaction_data . ccval ) || 0 ; // sum of outputs
816
- if ( crypto_confirmations >= correction_confirmations || rd . no_conf || transaction_data . setconfirmations === false ) { // check all confirmations + whitelist for currencies unable to fetch confirmations
816
+ if ( crypto_confirmations >= correction_confirmations || no_conf || transaction_data . setconfirmations === false ) { // check all confirmations + whitelist for currencies unable to fetch confirmations
817
817
is_crypto_confirmed = true ;
818
818
if ( total_crypto_amount >= crypto_amount * amount_margin ) { // compensation for small fluctuations in rounding amount
819
819
current_transaction . addClass ( "exceed" ) . nextAll ( ) . addClass ( "exceed" ) ;
820
- return
820
+ return false ;
821
821
}
822
822
} else {
823
823
is_crypto_confirmed = false ;
824
824
}
825
- const confirmation_bar = current_transaction . find ( ".confbar" ) ;
826
- if ( confirmation_bar . length > 0 ) {
827
- confirmation_bar . each ( function ( bar_index ) {
828
- animate_confbar ( $ ( this ) , bar_index ) ;
829
- } ) ;
830
- } ;
831
825
} ) ;
826
+ const conf_bar = transaction_items . find ( ".confbar" ) ;
827
+ if ( conf_bar . length ) {
828
+ conf_bar . each ( function ( i ) {
829
+ animate_confbar ( $ ( this ) , i ) ;
830
+ } ) ;
831
+ } ;
832
832
if ( total_crypto_amount >= crypto_amount * amount_margin ) { // compensation for small fluctuations in rounding amount
833
833
if ( is_crypto_confirmed === false ) { // check confirmations outside the loop
834
834
crypto_status = "pending" ,
@@ -860,7 +860,7 @@ function validate_payment_amounts(rd, rdo) {
860
860
}
861
861
}
862
862
} else {
863
- init_fiat_history ( rd , rdo , first_confirmations , latest_transaction_time , first_transaction_time ) ;
863
+ init_fiat_history ( rd , rdo , conf , latest_transaction_time , first_transaction_time ) ;
864
864
return
865
865
}
866
866
}
@@ -879,7 +879,7 @@ function validate_payment_amounts(rd, rdo) {
879
879
finalize_request_state ( rdo ) ;
880
880
return
881
881
}
882
- init_fiat_history ( rd , rdo , first_confirmations , latest_transaction_time , first_transaction_time ) ;
882
+ init_fiat_history ( rd , rdo , conf , latest_transaction_time , first_transaction_time ) ;
883
883
return
884
884
}
885
885
}
@@ -904,19 +904,20 @@ function update_transaction_count(status_panel, count) {
904
904
// ** Historical Data Processing: **
905
905
906
906
// Triggers historical fiat data retrieval for transactions based on confirmation status
907
- function init_fiat_history ( rd , rdo , conf , latestinput , firstinput ) {
908
- const confirm_level = conf || 0 ,
909
- no_confirm = rd . no_conf || conf === false ,
910
- latest_confirm = no_confirm ? 0 : confirm_level , // only update on change
907
+ function init_fiat_history ( rd , rdo , latestconf , latest_input , firstinput ) {
908
+ const cache_value = latest_input + latestconf . toString ( ) , // only update on change
911
909
cache_prefix = "historic_" + rd . requestid ,
912
- historic_cache = br_get_session ( cache_prefix ) ,
913
- cache_value = parseInt ( latestinput ) + parseInt ( latest_confirm ) ;
914
- if ( ( latest_confirm || no_confirm ) && cache_value > historic_cache ) { //new input detected; call historic api
910
+ cache_timestamp = br_get_session ( cache_prefix ) , // set to small amount to trigger lookup exchange rates
911
+ cache_session = cache_timestamp || 1 ,
912
+ latest_input_slice = cache_timestamp ? cache_session . slice ( 0 , 13 ) : latest_input ,
913
+ latestinput = parseInt ( latest_input_slice ) ,
914
+ historic_cache = parseInt ( cache_session ) ;
915
+ if ( cache_value > historic_cache ) { //new input detected; call historic api
915
916
br_remove_session ( cache_prefix ) ; // remove historic price cache
916
917
const historic_payload = $ . extend ( rd , {
917
- "latestinput" : latestinput ,
918
- " latestconf" : latest_confirm ,
919
- "firstinput" : firstinput
918
+ latestinput,
919
+ latestconf,
920
+ firstinput
920
921
} ) ,
921
922
api_list = "historic_fiat_price_apis" ,
922
923
fiat_api = $ ( "#fiatapisettings" ) . data ( "selected" ) ,
@@ -1052,8 +1053,8 @@ function fetch_crypto_rates(rd, rdo, fiat_api, api_list, api, currency_rate, usd
1052
1053
coin_id = api === "coincodex" ? crypto_symbol : // coincodex id
1053
1054
api === "coingecko" ? payment_method : // coingecko id
1054
1055
crypto_symbol + "-" + payment_method , // coinpaprika id
1055
- start_time_sec = ( first_input - glob_const . timezone ) / 1000 ,
1056
- end_time_sec = ( latest_input - glob_const . timezone ) / 1000 ,
1056
+ start_time_sec = parseInt ( ( first_input - glob_const . timezone ) / 1000 ) ,
1057
+ end_time_sec = parseInt ( ( latest_input - glob_const . timezone ) / 1000 ) ,
1057
1058
erc20_contract = rd . token_contract ,
1058
1059
history_api = api ,
1059
1060
search = history_api === "coincodex" ? get_payload_historic_coincodex ( coin_id , start_time_sec , end_time_sec ) :
@@ -1080,18 +1081,15 @@ function fetch_crypto_rates(rd, rdo, fiat_api, api_list, api, currency_rate, usd
1080
1081
tx_reverse = tx_list_length > 1 ? tx_list . get ( ) . reverse ( ) : tx_list ,
1081
1082
latest_confirm = rd . latestconf ,
1082
1083
total_amount = rd . amount ,
1083
- get_confirmations = rd . set_confirmations ,
1084
- confirm_interval = get_confirmations === false ? 0 : ( get_confirmations ? parseInt ( get_confirmations ) : 1 ) ,
1085
- is_lightning = rd . lightning ,
1086
- set_confirmations = is_lightning ? 1 : confirm_interval , // set minimum confirmations to 1
1087
- is_erc20 = rd . erc20 ,
1084
+ set_confirmations = rd . set_confirmations || 1 ; // Default to 1
1085
+ is_erc20 = rd . erc20 ,
1088
1086
historic_usd_value = ( total_amount / currency_rate ) * usd_rate ,
1089
1087
margin = historic_usd_value < 2 ? 0.60 : 0.95 ; // be flexible with small amounts
1090
1088
let tx_counter = 0 ,
1091
1089
confirmations = 0 ,
1092
- payment_timestamp ,
1093
- tx_hash ,
1094
- received_crypto = 0 ,
1090
+ paymenttimestamp ,
1091
+ txhash ,
1092
+ receivedamount = 0 ,
1095
1093
received_usd = 0 ,
1096
1094
confirmed = false ,
1097
1095
status = "pending" ,
@@ -1115,9 +1113,9 @@ function fetch_crypto_rates(rd, rdo, fiat_api, api_list, api, currency_rate, usd
1115
1113
conf_correct = node_data . instant_lock ? 0 : set_confirmations ; // correction if dash instant_lock
1116
1114
current_node . data ( "historic" , historic_object ) ;
1117
1115
confirmations = node_data . confirmations , // check confirmations
1118
- payment_timestamp = transaction_timestamp ,
1119
- tx_hash = node_data . txhash ,
1120
- received_crypto += parseFloat ( transaction_value ) || 0 ; // sum of outputs CC
1116
+ paymenttimestamp = transaction_timestamp ,
1117
+ txhash = node_data . txhash ,
1118
+ receivedamount += parseFloat ( transaction_value ) || 0 ; // sum of outputs CC
1121
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
1122
1120
confirmed = true ;
1123
1121
} else {
@@ -1126,19 +1124,20 @@ function fetch_crypto_rates(rd, rdo, fiat_api, api_list, api, currency_rate, usd
1126
1124
let current_usd_sum = received_usd += parseFloat ( historic_price * transaction_value ) || 0 ;
1127
1125
if ( current_usd_sum >= historic_usd_value * margin ) { //minus 5% dollar for volatility compensation
1128
1126
current_node . addClass ( "exceed" ) . nextAll ( ) . addClass ( "exceed" ) ;
1127
+ return false ;
1129
1128
}
1130
- const conf_bar = current_node . find ( ".confbar" ) ;
1131
- if ( conf_bar . length > 0 ) {
1132
- conf_bar . each ( function ( i ) {
1133
- animate_confbar ( $ ( this ) , i ) ;
1134
- } ) ;
1135
- } ;
1136
1129
} ) ;
1130
+ const conf_bar = tx_list . find ( ".confbar" ) ;
1131
+ if ( conf_bar . length ) {
1132
+ conf_bar . each ( function ( i ) {
1133
+ animate_confbar ( $ ( this ) , i ) ;
1134
+ } ) ;
1135
+ } ;
1137
1136
if ( received_usd ) {
1138
1137
if ( received_usd >= historic_usd_value * margin ) { // check total incoming amount // minus 5% dollar for volatility compensation
1139
1138
if ( confirmed === false ) { // check confirmations outside the loop
1140
1139
status = "pending" ,
1141
- pending = tx_counter === 1 && tx_hash ? "polling" : pending ; // switch to tx polling if there's only one transaction and txhash is known
1140
+ pending = tx_counter === 1 && txhash ? "polling" : pending ; // switch to tx polling if there's only one transaction and txhash is known
1142
1141
} else {
1143
1142
status = "paid" ,
1144
1143
pending = "no" ;
@@ -1149,17 +1148,17 @@ function fetch_crypto_rates(rd, rdo, fiat_api, api_list, api, currency_rate, usd
1149
1148
}
1150
1149
update_request ( {
1151
1150
"requestid" : rd . requestid ,
1152
- "status" : status ,
1153
- " receivedamount" : received_crypto ,
1151
+ status,
1152
+ receivedamount,
1154
1153
"fiatvalue" : ( received_usd / usd_rate ) * currency_rate ,
1155
- " paymenttimestamp" : payment_timestamp ,
1156
- " txhash" : tx_hash ,
1157
- "confirmations" : confirmations ,
1158
- "pending" : pending ,
1159
- "lightning" : is_lightning
1154
+ paymenttimestamp,
1155
+ txhash,
1156
+ confirmations,
1157
+ pending,
1158
+ "lightning" : rd . lightning
1160
1159
} , false ) ;
1161
1160
if ( pending !== "no" ) {
1162
- const cache_value = parseInt ( latest_input ) + parseInt ( latest_confirm ) ;
1161
+ const cache_value = latest_input + latest_confirm . toString ( ) ;
1163
1162
br_set_session ( "historic_" + rd . requestid , cache_value ) ; // 'cache' historic data
1164
1163
}
1165
1164
finalize_request_state ( rdo ) ;
0 commit comments