fix: Read TOTAL_WITHDRAWN from file instead of cached process.env

Bug: Second withdrawal showed $5.92 cumulative instead of $12.50
Root cause: process.env caches values at container startup, doesn't
update when .env file changes.

Fix: Parse TOTAL_WITHDRAWN directly from .env file content instead
of using cached process.env value.

Added: Debug logging showing calculation
Manual fix: Updated .env to $12.50 (sum of $6.58 + $5.92)

Result: Withdrawal stats now correctly show cumulative total.
This commit is contained in:
mindesbunister
2025-11-19 21:13:26 +01:00
parent 880aae9a77
commit 0d6e95bbab
2 changed files with 8 additions and 3 deletions

View File

@@ -42,11 +42,16 @@ export async function POST(request: NextRequest) {
}
// Update LAST_WITHDRAWAL_TIME and TOTAL_WITHDRAWN in .env
const currentTotal = parseFloat(process.env.TOTAL_WITHDRAWN || '0')
// IMPORTANT: Read from file, not process.env (which is cached at startup)
let envContent = fs.readFileSync(ENV_PATH, 'utf-8')
// Parse current total from file, not from cached process.env
const totalMatch = envContent.match(/^TOTAL_WITHDRAWN=(.*)$/m)
const currentTotal = totalMatch ? parseFloat(totalMatch[1]) : 0
const newTotal = currentTotal + calculation.withdrawalAmount
const now = new Date().toISOString()
let envContent = fs.readFileSync(ENV_PATH, 'utf-8')
console.log(`💾 Updating withdrawal tracking: $${currentTotal.toFixed(2)} + $${calculation.withdrawalAmount.toFixed(2)} = $${newTotal.toFixed(2)}`)
// Update LAST_WITHDRAWAL_TIME
const timeRegex = /^LAST_WITHDRAWAL_TIME=.*$/m