fix: fix percentage changes when balance is zero #25550
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR addresses a UI inconsistency observed in the account balance display, particularly when the account balance is at 0.00. Users have reported confusion over the display of a non-zero percentage change next to a +0.00 change in account value. This scenario occurs when there is no balance (neither in ETH nor in the selected fiat currency, USD in this case) in the user's account. The expectation is that if the account has not increased or decreased in value (due to having no balance), the displayed percentage change should also reflect a 0% change, aligning with the +$0.00 change displayed.
Problem: When the account balance is zero, the UI currently shows a +$0.00 change (as expected) but accompanies this with a non-zero percentage change (e.g., -1.74%), which is misleading and confusing to users. This discrepancy occurs despite the account's value not actually changing, given the lack of funds.
Solution: The proposed solution involves adjusting the logic that calculates and displays the percentage change in account value. Specifically, when the account balance is $0.00, the percentage change should also display as +0.00%, reflecting the true state of the account's value change (or lack thereof). This change ensures consistency in the UI and improves user understanding of their account's status.
Implementation Details:
Modify the calculation function to check for a $0.00 account balance condition. Upon detecting this condition, the function will automatically set the percentage change value to +0.00%.
Update the UI component responsible for displaying the percentage change to correctly render the +0.00% value when the account balance is zero.
Add unit tests to cover this scenario, ensuring that the percentage change correctly reflects a 0% change when the account balance is $0.00.
Expected Outcome: With this fix, users with a 0.00 account balance will see both a +0.00 change and a +0.00% change, eliminating confusion and providing a clearer understanding of their account's status. This update aims to enhance the user experience by ensuring consistency and clarity in the display of account value changes.
Related issues
Fixes: #25539
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist