Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Updated FormatMoneyUseCase #3657

Closed
wants to merge 5 commits into from

Conversation

shamim-emon
Copy link
Member

@shamim-emon shamim-emon commented Nov 1, 2024

Pull request (PR) checklist

Please check if your pull request fulfills the following requirements:

  • I've read the Contribution Guidelines and my PR doesn't break the rules.
  • I've read and understand the Developer Guidelines.
  • I confirm that I've run the code locally and everything works as expected.
  • My PR includes only the necessary changes to fix the issue (i.e., no unnecessary files or lines of code are changed).
  • 🎬 I've attached a screen recording of using the new code to the next paragraph (if applicable).

Screen recording of your changes (if applicable):

What's changed?

Describe with a few bullets what's new:
I've added below in FormatMoneyUseCase

  • Crypto formatting
  • KDocumentation

Risk factors

What may go wrong if we merge your PR?

  • N/A

In what cases won't your code work?

  • N/A

Does this PR close any GitHub issues? (do not delete)

Troubleshooting GitHub Actions (CI) failures ❌

Pull request checks failing? Read our CI Troubleshooting guide.

Copy link
Collaborator

@ILIYANGERMANOV ILIYANGERMANOV left a comment

Choose a reason for hiding this comment

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

Left some comments but "1,234.000000000000" isn't expected

* @return The formatted string representation of the value.
*/
suspend fun format(value: Double, shortenAmount: Boolean, isCrypto: Boolean = false): String {
val result = if (isCrypto) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can directly return, no need for result var

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

private fun formatCrypto(value: Double): String {
val result = cryptoFormatter.format(value)
return when {
result.lastOrNull() == localDecimalSeparator().firstOrNull() -> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't like this logic - can we just fix the formatter?

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed the function, just relying on the suggested formatter now

@@ -23,25 +32,69 @@ class FormatMoneyUseCase @Inject constructor(
private val withoutDecimalFormatter = DecimalFormat("###,###", DecimalFormatSymbols(locale))
private val withDecimalFormatter = DecimalFormat("###,###.00", DecimalFormatSymbols(locale))
private val shortenAmountFormatter = DecimalFormat("###,###.##", DecimalFormatSymbols(locale))
private val cryptoFormatter =
DecimalFormat("###,###,##0.${"0".repeat(9)}", DecimalFormatSymbols(locale))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you try fixing the formatter by "#".repeat(9)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

shortenAmount = false,
isCrypto = true,
locale = Locale.ENGLISH,
expectedOutput = "123,456.000000000"
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't expect such zeros

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated the result as-per the suggested formatter expected result

@ILIYANGERMANOV ILIYANGERMANOV added the requested changes Changes are needed. Please, apply them label Nov 1, 2024
@@ -23,25 +32,35 @@ class FormatMoneyUseCase @Inject constructor(
private val withoutDecimalFormatter = DecimalFormat("###,###", DecimalFormatSymbols(locale))
private val withDecimalFormatter = DecimalFormat("###,###.00", DecimalFormatSymbols(locale))
private val shortenAmountFormatter = DecimalFormat("###,###.##", DecimalFormatSymbols(locale))
private val cryptoFormatter = DecimalFormat("#".repeat(9), DecimalFormatSymbols(locale))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, I mean we need to support showing any arbitrary crypto with up to 9 decimals precision without showing unnecessary trailing digits. The correct pattern should be:

  • "###,###." + "#".repeat(9)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

locale = Locale.ENGLISH,
expectedOutput = "123456"
),
GERMAN_SHOW_DECIMAL_CRYPTO(
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need a tear case for "0.000345 BTC" for example

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -56,7 +56,7 @@ import com.ivy.navigation.navigation
import com.ivy.navigation.screenScopedViewModel
import com.ivy.ui.R
import com.ivy.wallet.domain.data.CustomExchangeRateState
import com.ivy.wallet.domain.data.IvyCurrency
import com.ivy.legacy.domain.data.IvyCurrency
Copy link
Collaborator

Choose a reason for hiding this comment

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

What caused this package change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Package directive of IvyCurrency data class was wrong. It resides in com.ivy.legacy.domain.data.IvyCurrency but directive was com.ivy.wallet.domain.data.IvyCurrency in the data class file. I fixed it thus these changes appeared as-per correct package directive in places where it's used.

@github-actions github-actions bot added the Stale No activity, will be automatically closed soon. label Nov 5, 2024
@ILIYANGERMANOV
Copy link
Collaborator

Thank you for your contribution to the Ivy Wallet project. We appreciate the time and effort you've invested in this pull request.

As of Nov 5th, 2024, Ivy Wallet is no longer maintained. We are closing all open pull requests as part of the project shutdown.

While we won't be merging this pull request, you're welcome to fork the repository and continue development independently under the terms of the GPL-3.0 License.

For more information, please refer to the shutdown notice in our README file.

We apologize for any inconvenience and thank you again for your interest in improving Ivy Wallet.

@shamim-emon shamim-emon deleted the fix-issue-3642 branch November 5, 2024 16:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
requested changes Changes are needed. Please, apply them Stale No activity, will be automatically closed soon.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Add KDoc And Crypto Formatting
2 participants