Skip to content

feat(validate): reject amounts with more than 2 decimal places - #207

Open
arisu6804 wants to merge 1 commit into
QuickLendX:mainfrom
arisu6804:validate/currency-amount-2-decimals-68
Open

feat(validate): reject amounts with more than 2 decimal places#207
arisu6804 wants to merge 1 commit into
QuickLendX:mainfrom
arisu6804:validate/currency-amount-2-decimals-68

Conversation

@arisu6804

Copy link
Copy Markdown

Closes #68

Summary

This repo already had parseInvoiceAmount, but it intentionally allows up to 7 decimal places (the chain's stroops precision, 1 XLM = 10_000_000 stroops) -- tightening that one to 2 decimals would silently break on-chain amount parsing (and its own existing round-trip tests against formatStroops, which always emits 7 decimal digits).

Adds a separate parseCurrencyAmount for currency-style amount input (e.g. an invoice's face value in a fiat-like denomination) where more than 2 decimal places is invalid input, not a precision nicety. Rejects at the boundary rather than passing a bad amount deeper into the call graph, matching the existing convention in this file.

Tests

lib/money.test.ts: accepts whole amounts and up to 2 decimals, rejects more than 2 decimals and non-numeric input.

Verification

npx vitest run lib/money.test.ts -- 15/15 passing. Full suite (npx vitest run, 164/164), npx tsc --noEmit, npx eslint . all clean.

Adds parseCurrencyAmount, distinct from parseInvoiceAmount (which
intentionally allows the full 7-decimal stroops precision the chain
uses, e.g. for on-chain payment amounts). This is for currency-style
amount inputs (e.g. an invoice's face value) where more than 2 decimal
places is invalid input, not a precision nicety -- rejected at the
boundary rather than silently truncated deeper in the call graph.
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.

Validate: reject amounts with more than 2 decimal places

1 participant