fix(cashout): decimal-safe JMD rate on the ACTUAL JMDAmount used by cashout#450
Open
islandbitcoin wants to merge 2 commits into
Open
fix(cashout): decimal-safe JMD rate on the ACTUAL JMDAmount used by cashout#450islandbitcoin wants to merge 2 commits into
islandbitcoin wants to merge 2 commits into
Conversation
…ashout Follow-up to #449. There are two `JMDAmount` classes in the tree: `src/domain/shared/MoneyAmount.ts` (fixed in #449) and `src/domain/shared/money/JMDAmount.ts`. The barrel `domain/shared/index.ts` exports JMDAmount from `./money` (`export * from "./money"`, taking only USDTAmount from MoneyAmount.ts), so cashout — via `@domain/shared` — imports the `money/JMDAmount.ts` copy, which still did `new JMDAmount(BigInt(d) * 100n)` and threw on every fractional NCB rate. #449's conversion fix therefore had no effect on cashout (its error-map half did work). Applied the same decimal-safe rewrite (mirror `money/USDAmount.dollars`) to `money/JMDAmount.ts`. Verified: dollars(155.5)=155.50, 152.7=152.70, 0.5=0.50. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Adds a fractional-rate case to Money.spec.ts, which imports JMDAmount from @domain/shared — the exact barrel-resolved class the cashout path uses. The only pre-existing JMDAmount.dollars test used an integer (160), so the suite stayed green while every fractional NCB rate crashed cashout in prod. Verified: fails without the fix (BigIntConversionError on 155.5), passes with it; full suite 22/22, tsc --noEmit clean.
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.
Problem
After #449 deployed to TEST, JMD cashout still failed on fractional rates. Debugging the running image found two
JMDAmountclasses:src/domain/shared/MoneyAmount.ts— fixed in fix(cashout): make JMD exchange-rate conversion decimal-safe [ENG-509] #449src/domain/shared/money/JMDAmount.ts— untouched, stillBigInt(d) * 100nThe barrel
src/domain/shared/index.tsdoesexport * from "./money"and only re-exportsUSDTAmountfromMoneyAmount.ts, sogetCashoutExchangeRate(importingJMDAmountvia@domain/shared) uses themoney/JMDAmount.tscopy. #449 fixed the wrong twin — its error-map change worked (message changed) but the conversion bug remained. Proof from the deployed image: barrelJMDAmount.dollars(155.5)→BigIntConversionError; direct-file →155.50;same class? false.Fix
Apply the decimal-safe conversion (mirror the adjacent
money/USDAmount.dollars, Money-lib +HALF_TO_EVEN) tomoney/JMDAmount.ts, and add theRoundimport.Test (this is the part #449 was missing)
Added a fractional-rate regression case to
test/flash/unit/domain/shared/Money.spec.ts, which importsJMDAmountfrom@domain/shared— the exact barrel-resolved class production uses. The only pre-existingJMDAmount.dollarstest used an integer (160), which is why the suite stayed green through the entire incident.Ran for real (not just runtime-debugged):
BigIntConversionError: 155.5 cannot be converted to a BigInt.tsc -p tsconfig.json --noEmitclean.The dead twin — tracked, not hand-waved
After this PR,
MoneyAmount.ts'sJMDAmount(the one #449 patched) is dead code shadowed by the barrel — a trap that will drift again. It can't be trivially deleted (the baseMoneyAmount.from()references it), so the cleanup is its own change: ENG-518 — Collapse duplicate JMDAmount/MoneyAmount implementations.🤖 Generated with Claude Code