Repository navigation
[MPDX-10004] - Block savings fund transfers that would overdraw the account - #2059
Open
tjohnson009 wants to merge 6 commits into
Open
tjohnson009 wants to merge 6 commits into
tjohnson009 wants to merge 6 commits into
Conversation
…ount One-time transfers over the source fund's available balance are now blocked at the form level ($0 floor, cent-precision comparison, fail-closed when the fund balance cannot be resolved). Recurring transfers and edits show a non-blocking overdraft warning instead, since their payments process in the future against future balances. The BalanceCard transfer button now gates on the same shared availableBalance helper instead of the old deficit-limit check. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
|
Preview branch generated at https://MPDX-10004-Block-Negative-Transfers.d3dytjb8adxkk5.amplifyapp.com |
Contributor
Bundle sizes [mpdx-react]Compared against 06ca668 No significant changes found |
Contributor
Author
|
Pre-PR code review findings (multi-agent review of the initial implementation; all addressed in this PR unless noted):
🤖 Generated with Claude Code |
kegrimes
removed their request for review
September 24, 2026 13:05
dr-bizz
reviewed
Sep 24, 2026
…ance.ts Co-authored-by: Bizz (Daniel Bisgrove) <56281168+dr-bizz@users.noreply.github.com>
…tive-Transfers # Conflicts: # src/components/HrTools/SavingsFundTransfer/BalanceCard/BalanceCard.tsx # src/components/HrTools/SavingsFundTransfer/TransferModal/TransferModal.test.tsx # src/components/HrTools/SavingsFundTransfer/TransferModal/TransferModal.tsx
Completes the review suggestion: the applied suggestion block was an arrow function with braces and no return, so minimumAllowedBalance returned undefined and availableBalance was NaN, silently disabling the block. Return the expression, update the helper comment, and rewrite the deficit-limit test to assert the new floor (a -$1,000 limit makes $16,000 available on a $15,000 balance). Also restore the `within` import that the main merge needed for the HR-managed funds test. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
SAA stores deficit_limit as a positive magnitude and rejects a withdrawal when balance - amount < -deficit_limit.abs (staff_accounting_app Fund#withdrawal_would_violate_deficit?; pinned by its spec suite, mirrored by mpdx_api's asr_max_calculation and by the TransferModal warning on main). The previous floor used +deficitLimit, which was too restrictive by twice the limit and rejected transfers SAA itself accepts. Mirror SAA with a -Math.abs floor, add direct unit tests for the helper, and cover both mock sign conventions in the modal tests. BalanceCard's long-standing disable check is deliberately left alone for a follow-up. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
dr-bizz
reviewed
Oct 7, 2026
| // is the NEGATIVE of the limit; Math.abs keeps legacy negative-convention | ||
| // values correct too. Defaults to a $0 floor when the fund has no limit. | ||
| export const minimumAllowedBalance = (fund: FundFieldsFragment): number => | ||
| fund.deficitLimit ? -Math.abs(fund.deficitLimit) : 0; |
Contributor
There was a problem hiding this comment.
Suggested change
| fund.deficitLimit ? -Math.abs(fund.deficitLimit) : 0; | |
| fund.deficitLimit ? Math.abs(fund.deficitLimit) : 0; |
dr-bizz
reviewed
Oct 7, 2026
|
|
||
| // The most that can be transferred out of a fund right now. | ||
| export const availableBalance = (fund: FundFieldsFragment): number => | ||
| fund.endBalance - minimumAllowedBalance(fund); |
Contributor
There was a problem hiding this comment.
If the primary account balance is $1,000 and the deficit is $600. Will have $1,600 available.
Suggested change
| fund.endBalance - minimumAllowedBalance(fund); | |
| fund.endBalance + minimumAllowedBalance(fund); |
dr-bizz
reviewed
Oct 7, 2026
|
|
||
| // The most that can be transferred out of a fund right now. | ||
| export const availableBalance = (fund: FundFieldsFragment): number => | ||
| fund.endBalance - minimumAllowedBalance(fund); |
Contributor
There was a problem hiding this comment.
You might also want to account for pending ASR amounts. This will be approved but not yet paid ASRs. But this might be an additional PR and out of scope for this PR.
Apply the review suggestions: minimumAllowedBalance returns the positive limit magnitude and availableBalance adds it, matching the shape asr_max_calculation uses on the API (mpdx_api#3666). Same arithmetic as before — available = balance + |deficitLimit| — per SAA's balance - amount >= -(deficit_limit).abs rule. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Prevents savings fund transfers from taking an account balance below $0 (MPDX-10004).
Per Scott (via stakeholder Crystal): a transfer can never take an account below $0 — fund
deficitLimits apply to salary, not savings fund transfers. Recurring transfers get a warning rather than a block, since their payments process in the future against future balances; each payment is enforced at processing time.Behavior
availableBalancehelper (endBalance <= 0) instead of the old deficit-limit check, so the entry point and the form enforce the same rule.The balance policy lives in one place (
Helper/availableBalance.ts) with the $0 floor documented, including a warning about the two conflictingdeficitLimitsign conventions found in the tree.Not covered client-side (server-side enforcement question)
The form check can't catch a recurring transfer that overdraws in a later month, stacked pending transfers that jointly overdraw, or a balance that changed after page load. Whether SAA rejects these at processing time is pending confirmation with Ethan Tison — if it doesn't, a backend ticket is needed.
Checklist:
🤖 Generated with Claude Code