Skip to content

[react-native-app] ProductCard shows wrong price, nanos divided by 1e8 instead of 1e9 #3751

Description

@bhuvan-somisetty

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

  1. 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).
  2. Look at any product card's displayed price.
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions