Bug Report
Commit 92df8a2 (main).
Symptom
ProductCard in src/react-native-app/components/ProductCard/ProductCard.tsx converts a product's Money price to a display string like this:
const price = (priceUsd?.units + priceUsd?.nanos / 100000000).toFixed(2);
Per src/react-native-app/protos/demo.ts, nanos is documented as nano (10^-9) units of the amount, e.g. $-1.75 is represented as units=-1, nanos=-750,000,000. Converting nanos back to a fractional dollar amount requires dividing by 1,000,000,000 (1e9), not 100,000,000 (1e8). The divisor here is off by a factor of 10.
The frontend web app does this correctly in src/frontend/components/ProductPrice/ProductPrice.tsx (units + nanos / 1000000000), the react-native-app's ProductCard.tsx even has a comment at the top saying it was "Copied with modification from src/frontend/components/ProductCard/ProductCard.tsx", the modification appears to be where the wrong divisor was introduced.
What is the expected behavior?
The price shown on the product card should match the actual Money value, e.g. a product priced at units=24, nanos=990000000 ($24.99) should render as $ 24.99.
What is the actual behavior?
The fractional part of the price is inflated by 10x. For units=24, nanos=990000000:
24 + 990000000 / 100000000 = 24 + 9.9 = 33.90
so the card shows $ 33.90 instead of $ 24.99.
Reproduce
- Run the react-native-app against the demo backend (or just read
ProductCard.tsx line 49 alongside any Money value where nanos is non-zero).
- Look at any product card's displayed price.
- Compare to the same product's price shown in the web frontend, the react-native price will be inflated whenever the product's cents aren't
.00.
Additional Context
Same class of bug as #3742 and #3747 (mishandling the Money.nanos field), this time in a price shown directly to the user rather than in telemetry. nanos needs to be divided by 1_000_000_000, not 100_000_000.
Component(s)
react-native-app
Bug Report
Commit 92df8a2 (main).
Symptom
ProductCardinsrc/react-native-app/components/ProductCard/ProductCard.tsxconverts a product'sMoneyprice to a display string like this:Per
src/react-native-app/protos/demo.ts,nanosis documented as nano (10^-9) units of the amount, e.g.$-1.75is represented asunits=-1, nanos=-750,000,000. Convertingnanosback to a fractional dollar amount requires dividing by1,000,000,000(1e9), not100,000,000(1e8). The divisor here is off by a factor of 10.The frontend web app does this correctly in
src/frontend/components/ProductPrice/ProductPrice.tsx(units + nanos / 1000000000), the react-native-app'sProductCard.tsxeven has a comment at the top saying it was "Copied with modification from src/frontend/components/ProductCard/ProductCard.tsx", the modification appears to be where the wrong divisor was introduced.What is the expected behavior?
The price shown on the product card should match the actual
Moneyvalue, e.g. a product priced atunits=24, nanos=990000000($24.99) should render as$ 24.99.What is the actual behavior?
The fractional part of the price is inflated by 10x. For
units=24, nanos=990000000:so the card shows
$ 33.90instead of$ 24.99.Reproduce
ProductCard.tsxline 49 alongside anyMoneyvalue wherenanosis non-zero)..00.Additional Context
Same class of bug as #3742 and #3747 (mishandling the
Money.nanosfield), this time in a price shown directly to the user rather than in telemetry.nanosneeds to be divided by1_000_000_000, not100_000_000.Component(s)
react-native-app