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

Match logic of balance badge to format max input value #5901

Merged
merged 1 commit into from
Jun 27, 2024

Conversation

jinchung
Copy link
Member

@jinchung jinchung commented Jun 27, 2024

Fixes APP-1627

What changed (plus any additional context for devs)

  1. The formatting for max input value was using the valueBasedDecimalFormatter which is slightly different from the logic that the balance badge uses. This PR ports over the essential logic of the balance badge into a worklet and uses that for formatting.
  2. This also fixes an issue with the non-worklet handleSignificantDecimals function that was copied over from helpers/utilities. A comment is added inline below describing the issue.

What to test

  • Tap max on various input assets (native and non-native) across multiple networks.
  • For non-native assets, the max formatted input value should match the balance badge.
  • For native assets, the max formatted input value should look similarly formatted to the balance badge, though the max input amount will be slightly less than what is shown in the balance badge since it needs to account for gas + some buffer.

Screen recordings / screenshots

Simulator Screenshot - iPhone 15 Pro - 2024-06-27 at 22 54 32
Simulator Screenshot - iPhone 15 Pro - 2024-06-27 at 22 54 04
Simulator Screenshot - iPhone 15 Pro - 2024-06-27 at 22 53 28
Simulator Screenshot - iPhone 15 Pro - 2024-06-27 at 22 53 14

export const handleSignificantDecimals = (value: BigNumberish, decimals: number, buffer = 3, skipDecimals = false): string => {
let dec;
if (lessThan(new BigNumber(value).abs(), 1)) {
dec = new BigNumber(value).toFixed()?.slice?.(2).search(/[^0]/g) + buffer;
dec = Math.min(decimals, 8);
dec = Math.min(dec, 8);
Copy link
Member Author

@jinchung jinchung Jun 27, 2024

Choose a reason for hiding this comment

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

fixing this as this was copied over incorrectly from the original helpers/utilities file: https://github.com/rainbow-me/rainbow/blob/develop/src/helpers/utilities.ts#L217

this line was ignoring the result of line 171 where it finds the index of the first significant (non-zero) digit and adds a buffer.

@jinchung jinchung merged commit 7931f74 into develop Jun 27, 2024
6 checks passed
@jinchung jinchung deleted the @jin/max-input-decimals branch June 27, 2024 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants