test: guard decimals:0 against the falsy trap, and de-duplicate toDecimals #325
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Found by the independent review of #321 (#321 (comment)). The code is correct today; the regression guard is missing.
The gap.
resolveTokenDecimals()insrc/shared/approvalAmount.jshandlesdecimals: 0correctly, but nothing asserts it. The reviewer mutated bothif (d !== null) return d;guards to a truthyif (d)— the same falsy-zero trap already filed as #318 — and all 788 tests stayed green while a 0-decimal token silently fell through to the unknown-scale rendering. A zero-decimal ERC-20 is legitimate and would render as "decimals unknown" instead of its true quantity.The duplication.
toDecimalsexists byte-identically insrc/shared/approvalAmount.jsandsrc/shared/transferAmount.js. It is a pure uint8 parser carrying no refusal semantics, so sharing it does not couple the two screens' deliberately different unknown-scale behaviour, andMAX_DECIMALSalready crosses that module boundary. The only thing the duplicate adds is drift risk — one copy losing thebigintbranch would silently change which scales one screen accepts, with no test noticing.Both are one small PR. The author of #306 correctly declined to touch
transferAmount.jswhile it was another unit's freshly reviewed work; it has since landed, so the coupling concern is gone.Definition of done
toDecimalsis exported fromsrc/shared/transferAmount.jsand the copy insrc/shared/approvalAmount.jsis deleted.decimals: 0assertion at the resolver level and at the rendered amount-line level.d !== nullguard to a truthyif (d)fails a test. State the mutation and the observed result.make checkgreen.