diff --git a/supernode/index.html b/supernode/index.html
index 8773c3f..a2609db 100644
--- a/supernode/index.html
+++ b/supernode/index.html
@@ -10534,39 +10534,50 @@
if (localbitcoinplusplus.master_configurations.validTradingAmount.includes(btc_buy_price)) {
if(!localbitcoinplusplus.master_configurations.tradableAsset2.includes(currency)) return false;
let current_btc_price = localbitcoinplusplus.trade.prototype.get_current_btc_price_in_fiat(currency);
- if (current_btc_price > 0) {
- return parseFloat(btc_buy_price / current_btc_price).toFixed(8);
+ if (typeof current_btc_price=="object" && current_btc_price.rate > 0) {
+ return parseFloat(btc_buy_price / current_btc_price.rate).toFixed(8);
}
}
- return null;
+ throw new Error("Failed to calculate BTC equivalent of cash.");
},
get_current_btc_price_in_fiat(currency_code) {
- return eval(`localbitcoinplusplus.trade.current_btc_price_in_${currency_code}`);
+ return localbitcoinplusplus.trade[`current_btc_price_in_${currency_code}`];
},
- set_current_btc_price_in_fiat(currency_code) {
- let url = `https://api.coindesk.com/v1/bpi/currentprice/${currency_code}.json`;
- helper_functions.ajaxGet(url, function (res) {
- if (typeof res == "string" && res.length > 0) {
- try {
- let res_object = JSON.parse(res);
- return Object.defineProperty(localbitcoinplusplus.trade,
- `current_btc_price_in_${currency_code}`, {
- value: {rate:eval(`res_object.bpi.${currency_code}.rate_float`),
- timestamp: + new Date()},
- writable: false,
- configurable: true,
- enumerable: true
- });
- } catch (error) {
- console.error(error);
- return false;
- }
+ async resolve_current_btc_price_in_fiat(currency_code) {
+ let today = + new Date();
+ let last_update_of_fiat_price_obj = localbitcoinplusplus.trade.prototype.get_current_btc_price_in_fiat(currency_code);
+ if(typeof last_update_of_fiat_price_obj!=="object"
+ || (today-last_update_of_fiat_price_obj.timestamp>3600000)) {
+ last_update_of_fiat_price_obj = await localbitcoinplusplus.trade.prototype.set_current_btc_price_in_fiat(currency_code);
+ return last_update_of_fiat_price_obj;
+ } else {
+ return last_update_of_fiat_price_obj;
+ }
+ },
+ async set_current_btc_price_in_fiat(currency_code) {
+ const url = `https://api.coindesk.com/v1/bpi/currentprice/${currency_code}.json`;
+ const res = await helper_functions.ajaxGet(url);
+ if (typeof res == "object" && typeof res.bpi =="object") {
+ try {
+ let new_price = res.bpi[`${currency_code}`].rate_float;
+ await Object.defineProperty(localbitcoinplusplus.trade,
+ `current_btc_price_in_${currency_code}`, {
+ value: {rate:new_price,
+ timestamp: + new Date()},
+ writable: true,
+ configurable: false,
+ enumerable: true
+ });
+ return localbitcoinplusplus.trade[`current_btc_price_in_${currency_code}`];
+ } catch (error) {
+ console.error(error);
+ return false;
}
- });
+ }
},
sendTransaction(utxo_addr, utxo_addr_wif, receiver_address, receiving_amount, receiving_amount_currency="USD", change_adress, callback) {
let url = `${localbitcoinplusplus.flocha}/api/addr/${utxo_addr}/utxo`;
- helper_functions.ajaxGet(url, function (res) {
+ helper_functions.ajaxGet(url).then(res=>{
if (res.length > 0) {
try {
@@ -10929,41 +10940,36 @@