Skip to content

fix(batch): reject duplicate recipient addresses and prevent floating-point total drift (#13) - #95

Open
ghzhost wants to merge 1 commit into
StellarSend:mainfrom
ghzhost:fix/batch-form-duplicate-and-drift-13
Open

fix(batch): reject duplicate recipient addresses and prevent floating-point total drift (#13)#95
ghzhost wants to merge 1 commit into
StellarSend:mainfrom
ghzhost:fix/batch-form-duplicate-and-drift-13

Conversation

@ghzhost

@ghzhost ghzhost commented Sep 2, 2026

Copy link
Copy Markdown

Summary

Enforces cross-row recipient validation and exact integer stroop total calculation for batch payments.

Closes #13.

Changes

  1. Duplicate Recipient Detection:
    • Added superRefine on batchSchema in BatchForm.tsx to detect duplicate destination addresses across batch items and attach path-specific validation errors directly under the duplicate recipient row.
  2. Self-Send Warning:
    • Passed connected wallet publicKey from useWallet() to BatchForm to display an inline non-blocking warning when any recipient matches the connected account.
  3. Integer Stroop Total Calculation:
    • Introduced parseAmountToStroops, xlmToStroops, stroopsToXlm, and calculateBatchTotal in src/lib/stellar.ts to compute batch payment sums via exact BigInt stroop arithmetic (7 decimal places) instead of naive parseFloat additions.
    • Updated BatchForm and useBatchPayment to use calculateBatchTotal, preventing floating-point precision drift across many decimal rows.
  4. Test Coverage:
    • Added tests in BatchForm.test.tsx for:
      • Disabling submission and flagging errors on duplicate recipient addresses.
      • Warning on self-send when a recipient matches senderPublicKey.
      • Validating total calculations across 100 small rows (e.g. 0.0000001 XLM) without floating point drift.

Verification

  • NODE_ENV=test pnpm test: 27 test files, 116 passed (100% green).
  • pnpm build: Completed successfully with clean Vite bundle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BatchForm allows duplicate recipient addresses and drifts on floating-point totals

1 participant