From d56ad7599b87d92b8bc1b0998c99578a6ebafb4c Mon Sep 17 00:00:00 2001 From: jwinterm Date: Tue, 17 Feb 2026 20:21:32 -0500 Subject: [PATCH] fix admin balance display --- html/admin.html | 19 ++++++++++++------- src/index.js | 6 ++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/html/admin.html b/html/admin.html index bab6db8..d30e737 100644 --- a/html/admin.html +++ b/html/admin.html @@ -450,6 +450,8 @@ let currentTab = 'overview'; let usersOffset = 0; let outcomesChart = null; + let atomicDivisor = 1e11; // Default WOW, updated from server on login + let cryptoSymbol = 'WOW'; // Updated from server on login // Check if already logged in if (apiKey) { @@ -562,10 +564,13 @@ document.getElementById('statFailed').textContent = `${failed} failed`; document.getElementById('statFailed').className = 'subtext' + (failed > 0 ? ' danger' : ''); + // Update divisor and symbol from server + if (overview.atomicDivisor) atomicDivisor = overview.atomicDivisor; + if (overview.cryptoType) cryptoSymbol = overview.cryptoType; + // Wallet balance if (overview.walletBalance) { const walletEl = document.getElementById('walletStatus'); - const cryptoType = window.location.hostname.includes('monerogue') ? 'XMR' : 'WOW'; if (overview.walletBalance.error) { // Wallet RPC error - show error state @@ -577,11 +582,11 @@ } else { // Wallet connected - show balance const bal = overview.walletBalance.unlocked_balance || 0; - const formatted = (bal / 1e12).toFixed(4); + const formatted = (bal / atomicDivisor).toFixed(4); document.getElementById('statBalance').textContent = formatted; document.getElementById('statUnlocked').textContent = `Unlocked: ${formatted}`; - walletEl.className = 'wallet-status' + (bal < 100000000000 ? ' warning' : ' healthy'); - document.getElementById('walletBalance').textContent = `${formatted} ${cryptoType}`; + walletEl.className = 'wallet-status' + (bal < atomicDivisor ? ' warning' : ' healthy'); + document.getElementById('walletBalance').textContent = `${formatted} ${cryptoSymbol}`; } } else { document.getElementById('statBalance').textContent = '-'; @@ -724,7 +729,7 @@ tbody.innerHTML = data.payouts.map(p => ` ${p.id} - ${(p.amount / 1e12).toFixed(6)} + ${(p.amount / atomicDivisor).toFixed(6)} ${p.address ? p.address.substring(0, 12) + '...' : '-'} ${p.status} ${p.txHash ? p.txHash.substring(0, 16) + '...' : '-'} @@ -781,7 +786,7 @@ ${g.status} ${g.outcome || '-'} ${g.duration ? g.duration + 's' : '-'} - ${g.payoutAmount ? (g.payoutAmount / 1e12).toFixed(6) : '-'} + ${g.payoutAmount ? (g.payoutAmount / atomicDivisor).toFixed(6) : '-'} ${new Date(g.createdAt).toLocaleString()} `).join(''); @@ -813,7 +818,7 @@ ${u.credits || 0} ${u.gamesPlayed || 0} ${u.gamesWon || 0} - ${u.totalWon ? (parseInt(u.totalWon) / 1e12).toFixed(4) : '0'} + ${u.totalWon ? (parseInt(u.totalWon) / atomicDivisor).toFixed(4) : '0'} ${new Date(u.createdAt).toLocaleDateString()} `).join(''); diff --git a/src/index.js b/src/index.js index cac92e9..19d4fce 100644 --- a/src/index.js +++ b/src/index.js @@ -1180,6 +1180,10 @@ app.get('/api/admin/stats/overview', adminAuth, asyncHandler(async (req, res) => const payout = payoutStats.rows[0]; const game = gameStats.rows[0]; + const cryptoType = gameModeManager.cryptoType || process.env.CRYPTO_TYPE || 'WOW'; + const { inferCurrencyDecimals, getDecimalDivisor } = require('./game/helpers/gameModeUtils'); + const atomicDivisor = getDecimalDivisor(inferCurrencyDecimals(cryptoType)); + res.json({ totalUsers: parseInt(user.total_users) || 0, totalGamesPlayed: parseInt(user.total_games) || 0, @@ -1189,6 +1193,8 @@ app.get('/api/admin/stats/overview', adminAuth, asyncHandler(async (req, res) => failedPayouts: parseInt(payout.failed_payouts) || 0, completedPayouts: parseInt(payout.completed_payouts) || 0, walletBalance: walletBalance, + cryptoType, + atomicDivisor, last24h: { games: parseInt(game.games_24h) || 0, wins: parseInt(game.wins_24h) || 0,