Fix roiEarned crash when chart data has fewer than 12 entries
All checks were successful
Deploy to VPS / deploy (push) Successful in 14s

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Carlos Escalante
2026-04-01 10:06:08 -06:00
parent 3c9656f416
commit 898b540b3f

View File

@@ -324,15 +324,18 @@ export default function Pensions() {
// Use real rendimientos from the API
acc[key] = Math.round(snap.rendimientos);
} else {
// Fallback: approximate from hardcoded data
// Fallback: approximate from chart data
const fund = FUNDS[key];
if (fund.isDividend) {
const len = chartData.length;
if (len >= 2 && fund.isDividend) {
acc[key] = Math.max(0, Math.round(
chartData[11][key] - chartData[10][key] - fund.monthlyContribution,
chartData[len - 1][key] - chartData[len - 2][key] - fund.monthlyContribution,
));
} else {
} else if (len > 0) {
const activeMonths = chartData.filter((d) => d[key] > 0).length;
acc[key] = Math.round(fund.startBalance * (fund.annualRate / 100) * (activeMonths / 12));
} else {
acc[key] = 0;
}
}
return acc;