feat(validate): reject amounts with more than 2 decimal places - #207
Open
arisu6804 wants to merge 1 commit into
Open
feat(validate): reject amounts with more than 2 decimal places#207arisu6804 wants to merge 1 commit into
arisu6804 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 againstformatStroops, which always emits 7 decimal digits).Adds a separate
parseCurrencyAmountfor 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.