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(`