diff --git a/frontend/src/pages/Pensions.tsx b/frontend/src/pages/Pensions.tsx index 8a9bfe7..29d3043 100644 --- a/frontend/src/pages/Pensions.tsx +++ b/frontend/src/pages/Pensions.tsx @@ -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;