From 23bc9a85009ba498984eac6066881a4f119fe848 Mon Sep 17 00:00:00 2001 From: yahorbukhta Date: Tue, 16 Apr 2024 15:30:28 +0200 Subject: [PATCH] fix rate --- calculator.js | 6 +++--- main.js | 2 +- stats.js | 45 +++++++++++++++++++++++---------------------- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/calculator.js b/calculator.js index 706ff81..3aea959 100644 --- a/calculator.js +++ b/calculator.js @@ -56,12 +56,12 @@ function generateTable(calculatorForm) { const currencyValue = "USD"; const electricityCostsValue = calculatorForm.electricity_costs.value; - Promise.all([fetchRate(), fetchPoolProfit()]).then(function([object1, object2]) { + Promise.all([fetchRate(), fetchPoolProfit()]).then(function([{rate}, {profit}]) { let tbody = document.getElementsByTagName('tbody')[0]; tbody.innerHTML = ""; - let reward = object2.profit * hashrateValue; - let income = getPoolProfitUSD(object1.rate, reward); + let reward = profit * hashrateValue; + let income = getPoolProfitUSD(rate.value, reward); addRow( tbody, diff --git a/main.js b/main.js index a932701..6edbc9e 100644 --- a/main.js +++ b/main.js @@ -84,7 +84,7 @@ function showPoolLatestBlockAt(date) { function init() { fetchPoolProfit().then(({ profit }) => { showPoolProfit(profit); - fetchCurrencyInfo().then(({ rate }) => showPoolProfitUSD(profit, rate)); + fetchCurrencyInfo().then(({ rate: {value} }) => showPoolProfitUSD(profit, value)); }); fetchPoolHashRate().then(({ hashrate }) => { diff --git a/stats.js b/stats.js index c3ab22b..5646a38 100644 --- a/stats.js +++ b/stats.js @@ -96,16 +96,16 @@ function amountUSD(amountInAlph, currencyRate) { function showMyPayouts({day, hour}, currencyRate) { document.getElementById('my_payouts_1h').textContent = parseFloat(hour.amount).toFixed(8) - document.getElementById('my_payouts_1h_usd').textContent = amountUSD(hour.amount, currencyRate.rate) + document.getElementById('my_payouts_1h_usd').textContent = amountUSD(hour.amount, currencyRate) document.getElementById('my_payouts_24h').textContent = parseFloat(day.amount).toFixed(8) - document.getElementById('my_payouts_24h_usd').textContent = amountUSD(day.amount, currencyRate.rate) + document.getElementById('my_payouts_24h_usd').textContent = amountUSD(day.amount, currencyRate) } function showMyBalance(myBalanceData, currencyRate) { document.getElementById('balance').textContent = parseFloat(myBalanceData.amount).toFixed(8) - document.getElementById('balance_usd').textContent = amountUSD(myBalanceData.amount, currencyRate.rate) + document.getElementById('balance_usd').textContent = amountUSD(myBalanceData.amount, currencyRate) } function showPayoutsTable(payouts) { @@ -124,11 +124,11 @@ function showEventsTable(events) { tableBody.innerHTML = ''; events.forEach((event) => { - const row = tableBody.insertRow(); - row.insertCell(0).textContent = event.worker ?? 'N/A'; - row.insertCell(1).textContent = event.message; - row.insertCell(2).textContent = event.count; - row.insertCell(3).textContent = new Date(event.latest).toLocaleString(); + const row = tableBody.insertRow(); + row.insertCell(0).textContent = event.worker ?? 'N/A'; + row.insertCell(1).textContent = event.message; + row.insertCell(2).textContent = event.count; + row.insertCell(3).textContent = new Date(event.latest).toLocaleString(); }); } @@ -170,9 +170,9 @@ function drawData(wallet) { day: {hashrate: hashrate24h, units: hashrate1hResponse.units} }); showWorkersTable(hashrate1hResponse.workers, hashrate24hResponse.workers); - showMyPayouts({hour: {amount: payouts1h}, day: {amount: payouts24h}}, currencyRate); + showMyPayouts({hour: {amount: payouts1h}, day: {amount: payouts24h}}, currencyRate.rate.value); showPayoutsTable(payouts24hResponse.payouts) - showMyBalance(myBalanceResponse, currencyRate); + showMyBalance(myBalanceResponse, currencyRate.rate.value); showEventsTable(myEventsResponse.events); showStats(); enableButton(); @@ -238,19 +238,20 @@ function assignFormListener() { function switchTab(event, tabId) { - document.querySelectorAll('.tab').forEach(tab => { - tab.classList.remove('active') - }) - - document.querySelectorAll('.tab-links .button').forEach(tab => { - tab.classList.remove('button-outline') - tab.classList.add('button-clear') - }) - - document.getElementById(tabId).classList.add('active') - event.currentTarget.classList.add('button-outline') - event.currentTarget.classList.remove('button-clear') + document.querySelectorAll('.tab').forEach(tab => { + tab.classList.remove('active') + }) + + document.querySelectorAll('.tab-links .button').forEach(tab => { + tab.classList.remove('button-outline') + tab.classList.add('button-clear') + }) + + document.getElementById(tabId).classList.add('active') + event.currentTarget.classList.add('button-outline') + event.currentTarget.classList.remove('button-clear') } + function init() { assignFormListener();