From d69a9a646c97dac4363e32faec3a37c15f7db153 Mon Sep 17 00:00:00 2001 From: DJObleezy <156115770+Djobleezy@users.noreply.github.com> Date: Sat, 22 Mar 2025 21:42:49 -0700 Subject: [PATCH] Update workers.js --- workers.js | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/workers.js b/workers.js index 32ba8d8..7c4feec 100644 --- a/workers.js +++ b/workers.js @@ -277,6 +277,7 @@ function fetchWorkerData(forceRefresh = false) { } // Update the worker grid with data +// UPDATED FUNCTION function updateWorkerGrid() { if (!workerData || !workerData.workers) { console.error("No worker data available"); @@ -299,8 +300,35 @@ function updateWorkerGrid() { return; } + // Calculate total unpaid earnings (from the dashboard) + const totalUnpaidEarnings = workerData.total_earnings || 0; + + // Sum up hashrates of online workers to calculate share percentages + const totalHashrate = workerData.workers + .filter(w => w.status === 'online') + .reduce((sum, w) => sum + parseFloat(w.hashrate_3hr || 0), 0); + + // Calculate share percentage for each worker + const onlineWorkers = workerData.workers.filter(w => w.status === 'online'); + const offlineWorkers = workerData.workers.filter(w => w.status === 'offline'); + + // Allocate 95% to online workers, 5% to offline workers + const onlinePool = totalUnpaidEarnings * 0.95; + const offlinePool = totalUnpaidEarnings * 0.05; + // Generate worker cards filteredWorkers.forEach(worker => { + // Calculate earnings share based on hashrate proportion + let earningsDisplay = worker.earnings; + + // Explicitly recalculate earnings share for display consistency + if (worker.status === 'online' && totalHashrate > 0) { + const hashrateShare = parseFloat(worker.hashrate_3hr || 0) / totalHashrate; + earningsDisplay = (onlinePool * hashrateShare).toFixed(8); + } else if (worker.status === 'offline' && offlineWorkers.length > 0) { + earningsDisplay = (offlinePool / offlineWorkers.length).toFixed(8); + } + // Create worker card const card = $('
'); @@ -337,7 +365,7 @@ function updateWorkerGrid() { `); - // Add additional stats + // Add additional stats - NOTE: Using recalculated earnings card.append(`