Skip to content

Validate PoolDepositButton's amount input before posting to the maintenance-pool deposit endpoint #69

Closed

Description

@chonilius

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' number inputs do accept a leading - even with min="1" set, since min isn't a keystroke-level filter) → amount: "-50" is POSTed.
  • Type 0 → amount: "0" is POSTed.
  • Type 1e50, NaN, Infinity, or 1.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 amount state 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 amount value fails validation, with an inline error message explaining why (mirroring the error state pattern already used elsewhere in this same component for wallet-connect failures).
  • Send amount to 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 MilestoneFundButton and IssueActions.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 about MilestoneFundButton's missing amount input).

Acceptance Criteria

  • Clicking "Deposit" with an empty, zero, negative, non-numeric, Infinity, or NaN-producing amount value 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 calls apiPost('/maintenance-pools/{poolId}/deposit', ...) exactly as before.
  • The value sent over the wire is a normalized decimal string, verified by inspecting the actual apiPost call 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 full PoolDepositButton component; amount state declared at line 48, the unguarded apiPost call 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 via pool.asset (not currently passed into PoolDepositButton, which only receives poolId — will need to be threaded through from src/app/milestones/page.tsx:80 where <PoolDepositButton poolId={pool.id} /> is rendered, since pool.asset is 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-DE system typing 100,50 using a comma decimal separator) — type="number" inputs are locale-aware for display in some browsers but the underlying .value is 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

  1. added
    bug
    very hard
    security
    Maybe Rewarded
    GrantFox OSS
    Official Campaign | FWC26
    on Aug 16, 2026
  2. added
    Third Campaign
    on Aug 16, 2026
  3. added
    Stellar Wave
    on Aug 25, 2026
  4. Songu3020 commented on Aug 25, 2026

    @Songu3020

    @Songu3020 has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    Hi! I’m a full-stack developer with a strong blockchain background. I’d love to handle this issue and can deliver a clean, reliable solution. Kindly assign it to me.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @Songu3020 to this issue.

  5. skaichima commented on Aug 25, 2026

    @skaichima

    @skaichima has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    Hello! I'd love to take this on. I'll add asset-aware monetary validation and normalization to PoolDepositButton, including precision limits, inline errors, and disabled submission for invalid values. I'll thread the pool asset through the component, audit the other amount-handling paths, and add focused tests covering all specified edge cases and normalized payloads. ETD is in 8 hours tops, please assign

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @skaichima to this issue.

  6. brightcli-stack commented on Aug 25, 2026

    @brightcli-stack
    Contributor

    @brightcli-stack has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    hello can i work on this issue please

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @brightcli-stack to this issue.

  7. Muyideen-js commented on Aug 25, 2026

    @Muyideen-js

    @Muyideen-js has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    I'd like to implement client-side validation for PoolDepositButton's amount field, adding checks for empty, non-numeric, zero, negative, and non-finite values before submission. I'll also normalize the amount to a canonical decimal string matching the pool's asset precision (2 digits for USDC, 7 for XLM) and disable the Deposit button with an inline error message when validation fails.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @Muyideen-js to this issue.

  8. Thoni76 commented on Aug 25, 2026

    @Thoni76

    @Thoni76 has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    I’m a smart contract and full-stack developer who turns complex ideas into secure, production-ready blockchain code.
    With strong skills in Rust and Solidity, I build systems that are fast, safe, and built to last.
    My experience with the Stellar SDK lets me ship real-world Web3 solutions that actually move value

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @Thoni76 to this issue.

  9. drips-wave commented on Aug 25, 2026

    @drips-wave

    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 🌊

  10. added a commit that references this issue on Aug 25, 2026
    b6cb677
  11. added a commit that references this issue on Aug 25, 2026
    572f084
  12. grantfox-oss commented on Aug 25, 2026

    @grantfox-oss

    🎉 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.

  13. drips-wave commented on Aug 25, 2026

    @drips-wave

    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.

  14. removed
    Stellar Wave
    on Oct 15, 2026
  15. added
    Stellar Wave
    on Oct 15, 2026
  16. removed
    Stellar Wave
    on Oct 15, 2026
  17. added
    Stellar Wave
    on Oct 15, 2026
  18. removed
    Stellar Wave
    on Oct 15, 2026
  19. added
    Stellar Wave
    on Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

GrantFox OSSMaybe RewardedOfficial Campaign | FWC26Stellar WaveThird Campaignbugsecurityvery hard

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions