fix: fixed reset button and safeguards on rebalance feature
This commit is contained in:
@@ -43,12 +43,13 @@ export default function RebalancePage() {
|
|||||||
const maxSingle = Math.floor(available * 0.8);
|
const maxSingle = Math.floor(available * 0.8);
|
||||||
|
|
||||||
const errors: string[] = [];
|
const errors: string[] = [];
|
||||||
|
const warnings: string[] = [];
|
||||||
if (rows.some((r) => r.targetCents < 0)) errors.push("No category can be negative.");
|
if (rows.some((r) => r.targetCents < 0)) errors.push("No category can be negative.");
|
||||||
if (available > 0 && rows.some((r) => r.targetCents > maxSingle))
|
if (available > 0 && rows.some((r) => r.targetCents > maxSingle))
|
||||||
errors.push("No category can exceed 80% of available.");
|
warnings.push("A category exceeds 80% of available.");
|
||||||
if (total !== available) errors.push(`Totals must equal available ($${(available / 100).toFixed(2)}).`);
|
if (total !== available) warnings.push(`Totals differ from available ($${(available / 100).toFixed(2)}).`);
|
||||||
if ((savingsTotal < savingsBefore || savingsTotal < savingsFloor) && !forceSavings)
|
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;
|
const canSubmit = errors.length === 0;
|
||||||
|
|
||||||
@@ -224,6 +225,14 @@ export default function RebalancePage() {
|
|||||||
</div>
|
</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">
|
<div className="flex gap-3">
|
||||||
<button className="btn primary" type="button" onClick={submit} disabled={!canSubmit}>
|
<button className="btn primary" type="button" onClick={submit} disabled={!canSubmit}>
|
||||||
Apply rebalance
|
Apply rebalance
|
||||||
@@ -234,7 +243,11 @@ export default function RebalancePage() {
|
|||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
setForceSavings(false);
|
setForceSavings(false);
|
||||||
setAdjustValue("");
|
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
|
Reset
|
||||||
|
|||||||
Reference in New Issue
Block a user