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

[Feature] New Decimal Format Applied In Accounts Tab #3587

Closed
wants to merge 14 commits into from

Conversation

shamim-emon
Copy link
Member

@shamim-emon shamim-emon commented Oct 6, 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 fixed applied new decimal formatting system in Accounts tab

6057671498786782891

6057671498786782888

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.

Didn't review much but we need to fix the format usecase to always say ".00" instead of ".0" on some places because it looks weird and inconsistent. Money formatting is standardized to always 2 decimal places

@shamim-emon
Copy link
Member Author

Didn't review much but we need to fix the format usecase to always say ".00" instead of ".0" on some places because it looks weird and inconsistent. Money formatting is standardized to always 2 decimal places

@ILIYANGERMANOV updated accordingly

val context = LocalContext.current
val scope = rememberCoroutineScope()
var formattedAmount by remember { mutableStateOf(amount.toDecimalFormatWithFraction()) }
scope.launch {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use LaunchedEffect this will result in countless coritines launched when recomposition happens

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

return useCase.format(this)
}

fun Double.toDecimalFormatWithFraction(fraction: Int = 2): String {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need this? Let's use only the FormatMoneyUseCase. My comment is about fixing its decimal format

Copy link
Member Author

Choose a reason for hiding this comment

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

@ILIYANGERMANOV Removed this change. Now we see ".0" in place of ".00" again. Please note that this issue is only limited to preview only. In actual app it works as expected.
I tried to use FormatMoneyUseCase for preview. So, I created a non-suspending version of format() here but in such case we can't get preview where it's used(refer to sc below)
Capture

So for preview, going back to normal double to string conversion.
Please let me know your comment on this.
Thanks

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ahaa, you can plug-in a FormarMoneyUsaCase isntance for previews that works. Ideally, this formatting logic should happen in the VM and not in the UI

Copy link
Member Author

@shamim-emon shamim-emon Oct 7, 2024

Choose a reason for hiding this comment

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

How would you recommend using the formatting(for preview) in concerned composable?

1.Passing the ViewModel function or the formatted value itself through the composable hierarchy to concernd composable?

2.Inject the viewmodel within an extension function( haven’t done it before) and call the method there and do the formatting?

3.Any other suggestion?

Copy link
Member Author

Choose a reason for hiding this comment

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

@ILIYANGERMANOV How about now? For preview we only need to make sure to show 2 decimal places right? So, how about using existing extension function Double.format(digits) ?
Please let me know if you see any issue with current implemented approach.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@shamim-emon the existing function should be deleted at some point. Proper fix:

  1. Provide the format usecase as composition local
  2. Provide a format usecsee instance for preview

Goals:

  • use only the format usecase
  • don't couple the code with legacy code that we need to cleanup

If that doesn't work, the proper but harder solution is to rework the VMs to return String instead of Double for the amount that's already formatted. That must be done at some point for performance reasons

}

interface FormatMoneyUseCase {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the purpose of this interface?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted to use @Binds instead of @Provides for corresponding dependency. Using @provides now and so removed it.

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.

This PR is quite dangerous, I'd wait for more community reviews and testing

@ILIYANGERMANOV ILIYANGERMANOV added the requested changes Changes are needed. Please, apply them label Oct 6, 2024
@ILIYANGERMANOV ILIYANGERMANOV added the dangerous PR that has risk of breaking something label Oct 7, 2024
@suyash01
Copy link
Contributor

suyash01 commented Oct 7, 2024

I see lots of test screen shots missing proper formatting for the total amount shown at the top. To be exact comma(,) is missing from the amount which previously was there.
If this was removed intentionally for making space for more digits, I would recommend having a dynamic text size instead of hampering redability.

@shamim-emon shamim-emon marked this pull request as draft October 8, 2024 05:16
@github-actions github-actions bot added the Stale No activity, will be automatically closed soon. label Oct 11, 2024
@github-actions github-actions bot closed this Oct 13, 2024
@shamim-emon shamim-emon deleted the fix-issue-3574 branch October 13, 2024 08:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
dangerous PR that has risk of breaking something 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] Apply Decimal number formatting in Accounts Tab
3 participants