Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(mobile): Create a new fiat formatter and implement its usage #5205

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

Jonathansoufer
Copy link
Contributor

What it solves

This PR resolves an issue in formatting fiat balance above 1000.

Resolves #

How this PR fixes it

It implements a new format util to handle all possible scenarios.

How to test it

Load the app and check if balance is shown correctly.
This wallet can be imported and used to see a different amount.

Screenshots

Screen.Recording.2025-03-06.at.21.29.19.mov

Checklist

  • I've tested the branch on mobile 📱
  • I've documented how it affects the analytics (if at all) 📊
  • I've written a unit/e2e test for it (if applicable) 🧑‍💻

Copy link

github-actions bot commented Mar 6, 2025

Comment on lines +80 to +93
let formattedValue: string
if (numericValue >= 1_000_000_000) {
// Billions
formattedValue = `${(numericValue / 1_000_000_000).toFixed(decimalPlaces)}B`
} else if (numericValue >= 1_000_000) {
// Millions
formattedValue = `${(numericValue / 1_000_000).toFixed(decimalPlaces)}M`
} else if (numericValue >= threshold) {
// Thousands
formattedValue = `${(numericValue / 1_000).toFixed(decimalPlaces)}k`
} else {
// Regular numbers
formattedValue = numericValue.toFixed(decimalPlaces)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance we can use Intl.NumberFormat like the web app instead of custom logic? The compact option does exactly the same.

Copy link
Contributor Author

@Jonathansoufer Jonathansoufer Mar 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the web code provided, that does seem to be way more verbose than this implementation. Although with room for leveraging Intl.NumberFormat, I think this would be more easy to follow specially because we're not dealing with different currencies, locales YET. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fiat/token amount formatting should be consistent across clients. I'm not suggesting here to make it a shared package (although this would be ideal) as it's out of scope, but we should re-use the code as much as possible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from that, this should be covered by unit tests. The web code is already covered.

@katspaugh katspaugh changed the title Fix(mobile): Creates a new fiat formatter and implement its usage Fix(mobile): Create a new fiat formatter and implement its usage Mar 7, 2025
@Jonathansoufer Jonathansoufer requested a review from katspaugh March 7, 2025 11:53
{amount[1] && (
<H1 fontWeight={600} color="$textSecondaryDark">
.{amount[1].slice(0, 2)}
{formattedAmount.includes('k') ? (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it checking specifically for k?

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.

2 participants