Repository navigation
Description
Overview
PoolDepositButton in src/app/milestones/MilestoneActions.tsx is the UI for depositing into a recurring maintenance pool — real money moving into a Soroban escrow. Its amount field is a plain, unvalidated string:
export function PoolDepositButton({ poolId }: { poolId: string }) {
const router = useRouter();
const { address, connect, connecting } = useWallet();
const [amount, setAmount] = useState("100");
...
async function handleDeposit() {
setError(null);
setPending(true);
try {
const walletAddress = address ?? (await connect());
if (!walletAddress) {
setError("Connect a Stellar wallet to deposit.");
return;
}
await apiPost(`/maintenance-pools/${poolId}/deposit`, {
amount,
funderAddress: walletAddress,
});
...and the input itself:
<input
type="number"
min="1"
value={amount}
onChange={(e) => setAmount(e.target.value)}
className="w-24 rounded-lg border border-slate-200 bg-white px-3 py-1.5 text-sm ..."
/>min="1" on a bare <input type="number"> is only a hint enforced by the browser's built-in form-constraint validation — and it only kicks in when the input is inside a <form> whose submission triggers native constraint validation (e.g. via a <button type="submit"> inside that <form>, or an explicit .reportValidity() call). Here there is no <form> at all: handleDeposit is wired directly to the Button's onClick, so min, and type="number"'s soft numeric-input hinting, are never actually consulted before amount — whatever raw string is currently in React state — gets sent straight to apiPost. Concretely, today a user can:
- Clear the field entirely and click Deposit →
amount: ""is POSTed. - Type
-50(most browsers'numberinputs do accept a leading-even withmin="1"set, sinceminisn't a keystroke-level filter) →amount: "-50"is POSTed. - Type
0→amount: "0"is POSTed. - Type
1e50,NaN,Infinity, or1.999999999999→ all pass straight through as literal strings. - Type non-numeric text via paste (number inputs block most non-digit keystrokes but not all paste paths across browsers) → still just forwarded as
amount.
None of this is caught client-side; handleDeposit has no validation branch at all, unlike handleFund/handleClaim/handleRefund in IssueActions.tsx which at least always check for a wallet address before proceeding. Whatever guards exist against a malformed/negative deposit amount today live entirely on the backend (mergefi-backend), which this frontend has no visibility into — and even if the backend does reject it, the user experience is an opaque backend error string surfacing through ApiRequestError instead of instant, specific client-side feedback.
Requirements
- Change
amountstate to be validated on every change, or validated at submit time (or both): reject/disable submission for empty, non-numeric, zero, negative, or non-finite values. - Decide and enforce a sane precision limit consistent with the pool's asset (
MaintenancePool.asset: "USDC" | "XLM"— USDC conventionally supports 2 decimal places at the application layer even though it's a 7-decimal Soroban asset like everything else here; XLM needs up to 7). Reject amounts with more fractional digits than the asset supports rather than silently truncating or forwarding them. - Disable the "Deposit" button whenever the current
amountvalue fails validation, with an inline error message explaining why (mirroring theerrorstate pattern already used elsewhere in this same component for wallet-connect failures). - Send
amountto the backend as a normalized value (e.g., a canonical decimal string with a fixed, asset-appropriate number of digits) rather than whatever raw string is sitting in input state, so"1.0","1.00", and"1"don't produce three different wire payloads for what should be the same request. - Apply the same treatment anywhere else in the codebase that accepts a free-form monetary amount from a text/number input with no client-side numeric validation (audit
MilestoneFundButtonandIssueActions.tsx's action handlers for the same gap, even though as reviewed today neither of those actually collects a user-entered amount — confirm and document that, or fix it if an amount field is added there per issue #16 in this batch aboutMilestoneFundButton's missing amount input).
Acceptance Criteria
- Clicking "Deposit" with an empty, zero, negative, non-numeric,
Infinity, or NaN-producingamountvalue is impossible — the button is disabled and/or the click is a no-op with a visible inline error. - An amount with more fractional digits than the pool's asset supports is rejected client-side with a specific error message (not silently truncated, not silently forwarded).
- A valid amount (e.g.
"100","12.5") still successfully callsapiPost('/maintenance-pools/{poolId}/deposit', ...)exactly as before. - The value sent over the wire is a normalized decimal string, verified by inspecting the actual
apiPostcall arguments in a test or via a network inspection during manual QA. - A new test file (or an addition to an existing one) covers: empty string,
"0","-5","abc","1e10", an over-precision decimal, and a valid amount, asserting the correct enabled/disabled and error-message behavior for each.
Additional Notes
Precise references:
src/app/milestones/MilestoneActions.tsx:45-88— the fullPoolDepositButtoncomponent;amountstate declared at line 48, the unguardedapiPostcall at lines 61-64, the<input type="number" min="1" ...>at lines 75-81.- Contrast with
src/app/issues/[id]/IssueActions.tsx:19-36(withWallet), which at least validates that a wallet address exists before proceeding — there is no equivalent existence/shape check for a monetary amount anywhere in the current codebase. src/types/index.ts:74-80—MaintenancePool.asset: "USDC" | "XLM", confirming the asset-dependent precision requirement is a real, typed distinction this component already has access to viapool.asset(not currently passed intoPoolDepositButton, which only receivespoolId— will need to be threaded through fromsrc/app/milestones/page.tsx:80where<PoolDepositButton poolId={pool.id} />is rendered, sincepool.assetis available there).
Edge cases:
- A user rapidly clicking Deposit multiple times before the first request resolves is a separate, already-tracked concern (see Deduplicate in-flight mutating requests and add rate-limit-aware error handling #44 "Deduplicate in-flight mutating requests and add rate-limit-aware error handling") — this issue is scoped to input validity, not request deduplication; note the cross-reference in the PR rather than re-solving Deduplicate in-flight mutating requests and add rate-limit-aware error handling #44's scope here.
- Locale-formatted input (e.g. a user on a
de-DEsystem typing100,50using a comma decimal separator) —type="number"inputs are locale-aware for display in some browsers but the underlying.valueis always a period-decimal string per the HTML spec, so this shouldn't be a parsing hazard, but worth a manual check across at least Chrome and Firefox as part of QA.
Implementation sketch: extract a small parseMoneyInput(raw: string, asset: "USDC" | "XLM"): { valid: boolean; normalized?: string; error?: string } helper (a natural companion to the existing coerceDecimal/coerceNonNegative/coercePercentage family in src/lib/utils.ts, though note those are designed for display-side coercion of already-trusted backend data with silent fallbacks — this needs the opposite behavior, rejecting invalid user input loudly rather than silently falling back to 0), call it on every amount change to drive the disabled state and inline error, and call it again at submit time before constructing the apiPost body.
Test/reproduction plan: render PoolDepositButton, use userEvent.type/userEvent.clear to drive the amount input through each edge case above, assert the Deposit button's disabled attribute and any rendered error text, and for the valid case assert (via a mocked apiPost) that the request body's amount is the expected normalized string.
Activity
Songu3020 commentedon Aug 25, 2026
@Songu3020 has applied to work on this issue as part of the Stellar Wave Program's 8th wave.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @Songu3020 to this issue.
skaichima commentedon Aug 25, 2026
@skaichima has applied to work on this issue as part of the Stellar Wave Program's 8th wave.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @skaichima to this issue.
brightcli-stack commentedon Aug 25, 2026
@brightcli-stack has applied to work on this issue as part of the Stellar Wave Program's 8th wave.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @brightcli-stack to this issue.
Muyideen-js commentedon Aug 25, 2026
@Muyideen-js has applied to work on this issue as part of the Stellar Wave Program's 8th wave.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @Muyideen-js to this issue.
Thoni76 commentedon Aug 25, 2026
@Thoni76 has applied to work on this issue as part of the Stellar Wave Program's 8th wave.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @Thoni76 to this issue.
drips-wave commentedon Aug 25, 2026
Congratulations, @brightcli-stack! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on August 31, 2026.
🧑💻 @brightcli-stack: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.
Warning
When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.
🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.
🌊 Happy Wave 🌊
fix: validate deposits, fix milestone progress, XLM precision, role-b…
fix: validate deposit amounts and fix milestone progress divide-by-zero
grantfox-oss commentedon Aug 25, 2026
🎉 This issue has been marked as completed on GrantFox as part of the Third Campaign campaign!
@brightcli-stack's PR #332 was approved and merged by @chonilius.
🏆 @brightcli-stack: You earned 35 FoxPoints for this contribution! Your current tier: Explorer (640 total points). Track your full progress on GrantFox.
👏 Great work, @brightcli-stack! Keep contributing to MergeFi.
drips-wave commentedon Aug 25, 2026
This issue has been completed by @brightcli-stack as part of the Stellar Wave Program's 8th Wave 🥳
😎 @brightcli-stack: You earned 200 Points for completing this issue! After the current Wave ends, you'll be eligible for a percentage of the Wave's reward pool based on the percentage of total points you've earned. Learn more here. You can also Leave a review to share your experience working on this issue.
🧑💻 Repo maintainers: How'd the contributor do? Leave a review to share your experience working with them.