Skip to content

Fix: Preserve Row-Level Validation When Batch Amounts Are Malformed #702

Description

@jahrulezfrancis

Problem

A single malformed amount in an uploaded batch crashes summary generation
and wipes out the row-level validation results that had already been
computed — leaving the user with a generic error instead of the specific
row that needs fixing.

Severity: Medium
Location: lib/stellar/summary.ts:7-20, contexts/BatchFlowContext.tsx:296-321,327-340

Description

getBatchSummary calls totalAmount.plus(instruction.amount) using
big.js before calling validatePaymentInstruction on that same
instruction. An amount like "not-a-number" throws immediately inside
big.js, before validation gets a chance to flag it as an ordinary invalid
row. In handleFileSelect
(contexts/BatchFlowContext.tsx:372-389), setValidationResult(parsed) is
called first with correct row-level data, but the subsequent
getBatchSummary throw is caught by the surrounding try/catch, which then
calls setValidationResult(null) — discarding the already-correct
validation data — and shows a generic "Failed to parse payment file" toast.
handleManualContinue (contexts/BatchFlowContext.tsx:392-406) calls
getBatchSummary with no surrounding try/catch at all, so the same input
would throw uncaught on that path.

Steps to Reproduce

  1. Upload an otherwise valid CSV with one row containing amount=not-a-number.
  2. parsePaymentFile correctly returns row-level validation info,
    including the specific bad row.
  3. getBatchSummary throws before that validation info is surfaced.
  4. The UI clears the validation result and shows only a generic parse
    error — the actionable per-row error is lost.

Expected Behavior

A malformed amount should behave as an ordinary invalid row; valid rows and
the summary for them should remain visible and usable for review/correction.

Suggested Fix Approach

Validate each instruction before performing arithmetic on it, and sum only
already-validated amounts — or wrap the per-row arithmetic in its own
try/catch that preserves the parser's validation result instead of
discarding it.

Acceptance Criteria

  • A malformed amount in one row no longer clears validation results for
    the rest of the batch
  • The specific invalid row and its reason are still shown to the user
  • handleManualContinue no longer throws uncaught on a malformed manual
    entry
  • Test covers both file-upload and manual-entry paths with a malformed
    amount

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions