Skip to content

feat(backend): centralize amount and currency validation across API and service layers - #139

Open
woahwhattheheck wants to merge 4 commits into
RemitFlow:mainfrom
woahwhattheheck:wire/rfb-130-currency-policy
Open

woahwhattheheck wants to merge 4 commits into
RemitFlow:mainfrom
woahwhattheheck:wire/rfb-130-currency-policy

Conversation

@woahwhattheheck

Copy link
Copy Markdown

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.
  • Transfer and quote validators call the same policy (transfer enforces max; quote does not).
  • quoteService / rateService.convert round with the destination currency's minor units (JPY stays whole).
  • Unsupported currencies and sub-minor-unit amounts fail before any store mutation.

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 new test/currencyPolicy.test.js).
  • Coverage: currency matrix, JPY zero-decimal, overflow, transfer max, preview/settlement contract agreement, HTTP 400 for unsupported codes.

Design tradeoffs

  • Policy table must stay aligned with SUPPORTED_CURRENCIES (boot-time assert). Adding a corridor means updating both the rate table and metadata in one change.
  • Quotes skip the transfer max so informational previews still work for large amounts; create-transfer still enforces it.

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.
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.

feat(backend): centralize amount and currency validation across API and service layers

1 participant