feat(backend): centralize amount and currency validation across API and service layers - #139
Open
woahwhattheheck wants to merge 4 commits into
Open
woahwhattheheck wants to merge 4 commits into
woahwhattheheck wants to merge 4 commits into
Conversation
Add a shared currency policy (ISO minor units, min/max, supported codes) used by quote/transfer validators and settlement so preview amounts match executed transfers, unsupported currencies fail before mutation, and zero-decimal corridors like JPY reject fractional sends. Closes RemitFlow#130.
This was referenced Sep 24, 2026
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.
Summary
Closes #130.
Introduces a single currency policy shared by API validators and settlement so preview quotes and executed transfers always agree on precision, supported codes, and overflow bounds.
What
src/utils/currencyPolicy.js— canonical metadata (ISO minor units, min amount, optional max) for every rate-listed currency;canonicalizeAmount/validateTransferPair/roundToCurrency.quoteService/rateService.convertround with the destination currency's minor units (JPY stays whole).Why
Different layers previously accepted different precision or unsupported codes, so a quote could succeed and settlement later fail (or vice versa). One policy table keeps preview and execution identical.
How tested
npm test— 275 passing (includes newtest/currencyPolicy.test.js).Design tradeoffs
SUPPORTED_CURRENCIES(boot-time assert). Adding a corridor means updating both the rate table and metadata in one change.