fix: fixed reset button and safeguards on rebalance feature
All checks were successful
Deploy / deploy (push) Successful in 57s
Security Tests / security-non-db (push) Successful in 19s
Security Tests / security-db (push) Successful in 23s

This commit is contained in:
2026-03-11 21:56:12 -05:00
parent 51510f1685
commit d39928a3f7

View File

@@ -43,12 +43,13 @@ export default function RebalancePage() {
const maxSingle = Math.floor(available * 0.8);
const errors: string[] = [];
const warnings: string[] = [];
if (rows.some((r) => r.targetCents < 0)) errors.push("No category can be negative.");
if (available > 0 && rows.some((r) => r.targetCents > maxSingle))
errors.push("No category can exceed 80% of available.");
if (total !== available) errors.push(`Totals must equal available ($${(available / 100).toFixed(2)}).`);
warnings.push("A category exceeds 80% of available.");
if (total !== available) warnings.push(`Totals differ from available ($${(available / 100).toFixed(2)}).`);
if ((savingsTotal < savingsBefore || savingsTotal < savingsFloor) && !forceSavings)
errors.push("Lowering savings requires confirmation.");
errors.push("Confirm lowering savings / below 20% floor.");
const canSubmit = errors.length === 0;
@@ -224,6 +225,14 @@ export default function RebalancePage() {
</div>
)}
{warnings.length > 0 && (
<div className="toast-warn space-y-1">
{warnings.map((w) => (
<div key={w}>{w}</div>
))}
</div>
)}
<div className="flex gap-3">
<button className="btn primary" type="button" onClick={submit} disabled={!canSubmit}>
Apply rebalance
@@ -234,7 +243,11 @@ export default function RebalancePage() {
onClick={async () => {
setForceSavings(false);
setAdjustValue("");
await refetch();
const refreshed = await refetch();
if (refreshed.data?.categories) {
setRows(refreshed.data.categories.map((c) => ({ ...c, targetCents: c.balanceCents })));
setAdjustId(refreshed.data.categories[0]?.id ?? "");
}
}}
>
Reset