diff --git a/basicswap/static/js/offerstable.js b/basicswap/static/js/offerstable.js index cec3412..cfd8dd2 100644 --- a/basicswap/static/js/offerstable.js +++ b/basicswap/static/js/offerstable.js @@ -1264,7 +1264,7 @@ function getEmptyPriceData() { async function fetchLatestPrices() { const PRICES_CACHE_KEY = 'prices_coingecko'; - const RETRY_DELAY = 2000; // 2 sec + const RETRY_DELAY = 5000; const MAX_RETRIES = 3; const cachedData = CacheManager.get(PRICES_CACHE_KEY); @@ -1651,30 +1651,23 @@ async function updateOffersTable() { const PRICES_CACHE_KEY = 'prices_coingecko'; const cachedPrices = CacheManager.get(PRICES_CACHE_KEY); - - if (!cachedPrices || !cachedPrices.remainingTime || cachedPrices.remainingTime < 80000) { - console.log('Fetching fresh price data...'); - const priceData = await fetchLatestPrices(); - if (priceData) { - latestPrices = priceData; - } - } else { - latestPrices = cachedPrices.value; - } + + latestPrices = cachedPrices?.value || getEmptyPriceData(); const validOffers = getValidOffers(); - - if (!isSentOffers) { - const networkOffersSpan = document.querySelector('a[href="/offers"] span.inline-flex.justify-center'); - if (networkOffersSpan) { - networkOffersSpan.textContent = validOffers.length; - } - } - const startIndex = (currentPage - 1) * itemsPerPage; const endIndex = Math.min(startIndex + itemsPerPage, validOffers.length); const itemsToDisplay = validOffers.slice(startIndex, endIndex); + fetchLatestPrices().then(freshPrices => { + if (freshPrices) { + latestPrices = freshPrices; + updateProfitLossDisplays(); + } + }).catch(error => { + console.warn('Price fetch failed:', error); + }); + const identityPromises = itemsToDisplay.map(offer => offer.addr_from ? getIdentityData(offer.addr_from) : Promise.resolve(null) ); @@ -1682,10 +1675,6 @@ async function updateOffersTable() { const identities = await Promise.all(identityPromises); if (validOffers.length === 0) { - const existingRows = offersBody.querySelectorAll('tr'); - existingRows.forEach(row => { - cleanupRow(row); - }); handleNoOffersScenario(); finishTableRender(); return; @@ -1725,25 +1714,47 @@ async function updateOffersTable() { }); lastRefreshTime = Date.now(); - if (newEntriesCountSpan) { - newEntriesCountSpan.textContent = validOffers.length; - } - if (lastRefreshTimeSpan) { - lastRefreshTimeSpan.textContent = new Date(lastRefreshTime).toLocaleTimeString(); - } - + updateLastRefreshTime(); + } catch (error) { console.error('[Debug] Error in updateOffersTable:', error); - offersBody.innerHTML = ` -