From d6ed5ba24c48929643f154c5e6b961d8f0bab97c Mon Sep 17 00:00:00 2001 From: gerlofvanek Date: Fri, 22 Dec 2023 13:26:29 +0100 Subject: [PATCH] ui: Chart API update - Updated with a new default Chart API Key - Implemented Chart error handling --- basicswap/static/css/style.css | 11 +++ basicswap/templates/offers.html | 85 +++++++++++++++++------ basicswap/ui/page_offers.py | 2 +- tests/basicswap/selenium/test_settings.py | 2 +- 4 files changed, 77 insertions(+), 23 deletions(-) diff --git a/basicswap/static/css/style.css b/basicswap/static/css/style.css index 4650ad0..c5c87ec 100644 --- a/basicswap/static/css/style.css +++ b/basicswap/static/css/style.css @@ -96,6 +96,17 @@ display: block; } +.blurred { + filter: blur(4px); + pointer-events: none; + user-select: none; +} + +.error-overlay.non-blurred { + filter: none; + pointer-events: auto; + user-select: auto; +} /* Disable opacity on disabled form elements in Chrome */ @media screen and (-webkit-min-device-pixel-ratio:0) { diff --git a/basicswap/templates/offers.html b/basicswap/templates/offers.html index b17eab5..9a4076b 100644 --- a/basicswap/templates/offers.html +++ b/basicswap/templates/offers.html @@ -59,27 +59,35 @@ {% include 'inc_messages.html' %} {% if show_chart %} -
-
-
-
-
-
-
-
-
-
- -
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
-
-
-
-
-
-
-
+ +
@@ -302,11 +310,19 @@ window.addEventListener('load', function() { const coins = ['BTC', 'PART', 'XMR', 'LTC', 'FIRO', 'DASH', 'PIVX', 'DOGE']; coins.forEach(coin => { fetch(`https://min-api.cryptocompare.com/data/pricemultifull?fsyms=${coin}&tsyms=USD,BTC&api_key=${api_key}`) - .then(response => response.json()) + .then(response => { + if (!response.ok) { + throw new Error(`Error fetching data. Status: ${response.status}`); + } + return response.json(); + }) .then(data => { displayCoinData(coin, data); }) - .catch(error => console.error(`Error fetching ${coin} data:`, error)); + .catch(error => { + console.error(`Fetching ${coin} data:`, error); + displayErrorMessage(`Unable to fetch data. Please verify your API key or try again later.`); + }); }); updateChart('BTC'); }); @@ -329,6 +345,33 @@ function displayCoinData(coin, data) { priceChangeContainer.innerHTML = negativePriceChangeHTML(priceChange1h); } } + +function displayErrorMessage(message) { + const errorContainer = document.getElementById('error-container'); + if (errorContainer) { + errorContainer.innerHTML = `
${message}
`; + } else { + document.body.innerHTML += `
${message}
`; + } +} + +function displayErrorMessage(message) { + const errorOverlay = document.getElementById('error-overlay'); + const errorContent = document.getElementById('error-content'); + const containersToBlur = document.querySelectorAll('.container-to-blur'); + + if (errorOverlay && errorContent) { + errorOverlay.classList.remove('hidden'); + errorContent.querySelector('p').textContent = `Error: ${message}`; + + containersToBlur.forEach(container => { + container.classList.add('blurred'); + }); + + errorOverlay.classList.add('non-blurred'); + } +} + function positivePriceChangeHTML(value) { return `
diff --git a/basicswap/ui/page_offers.py b/basicswap/ui/page_offers.py index a8aee64..f2b9559 100644 --- a/basicswap/ui/page_offers.py +++ b/basicswap/ui/page_offers.py @@ -445,7 +445,7 @@ def page_newoffer(self, url_split, post_string): chart_api_key = swap_client.settings.get('chart_api_key', '') if chart_api_key == '': chart_api_key_enc = swap_client.settings.get('chart_api_key_enc', '') - chart_api_key = 'cd7600e7b5fdd99c6f900673ff0ee8f64d6d4219a4bb87191ad4a2e3fc65d7f4' if chart_api_key_enc == '' else bytes.fromhex(chart_api_key_enc).decode('utf-8') + chart_api_key = '95dd900af910656e0e17c41f2ddc5dba77d01bf8b0e7d2787634a16bd976c553' if chart_api_key_enc == '' else bytes.fromhex(chart_api_key_enc).decode('utf-8') return self.render_template(template, { 'messages': messages, diff --git a/tests/basicswap/selenium/test_settings.py b/tests/basicswap/selenium/test_settings.py index f821b52..c409861 100644 --- a/tests/basicswap/selenium/test_settings.py +++ b/tests/basicswap/selenium/test_settings.py @@ -77,7 +77,7 @@ def test_settings(driver): chart_api_key = bytes.fromhex(settings.get('chart_api_key_enc', '')).decode('utf-8') assert (chart_api_key == difficult_text) - hex_text = 'cd7600e7b5fdd99c6f900673ff0ee8f64d6d4219a4bb87191ad4a2e3fc65d7f4' + hex_text = '95dd900af910656e0e17c41f2ddc5dba77d01bf8b0e7d2787634a16bd976c553' el = driver.find_element(By.NAME, 'chartapikey') el.clear() el.send_keys(hex_text)