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

Swaps: fix handling of native currency formatting/presentation #5826

Merged
merged 18 commits into from
Jun 14, 2024

Conversation

benisgold
Copy link
Contributor

@benisgold benisgold commented Jun 6, 2024

Fixes APP-1346

What changed (plus any additional context for devs)

  • created a util to handle formatting of native currency values
  • does not handle big numbers, but does not appear to be necessary for the cases where this new util is used
  • replaced existing utils convertAmountToNativeDisplay and convertAmountToNativeDisplayWithThreshold
  • removed toLocaleStringPolyfill shim since it's broken and no longer needed

Screen recordings / screenshots

Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-06-07.at.15.44.50.mp4

What to test

Copy link

linear bot commented Jun 6, 2024

@jinchung jinchung self-requested a review June 7, 2024 14:50
Copy link
Member

@jinchung jinchung left a comment

Choose a reason for hiding this comment

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

Comments inline

src/__swaps__/utils/numbers.ts Outdated Show resolved Hide resolved
src/__swaps__/screens/Swap/hooks/useSwapWarning.ts Outdated Show resolved Hide resolved
src/__swaps__/utils/numbers.ts Outdated Show resolved Hide resolved
@benisgold benisgold requested a review from jinchung June 7, 2024 23:00
/**
* @desc convert from amount value to display formatted string
*/
export const convertAmountToNativeDisplayWorklet = (
Copy link
Contributor

Choose a reason for hiding this comment

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

does this converts or just formats?
also I always get confused on what native means, my instinct is that native is the network native gas token like eth, but sometimes we use it as the user preferred currency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just formats. i kept the preexisting name for this util

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i agree it's very confusing. we use this terminology in both ways across the app

@@ -176,12 +177,10 @@ export const convertAmountToNativeAmount = (amount: BigNumberish, priceUnit: Big
export const convertAmountAndPriceToNativeDisplay = (
Copy link
Member

Choose a reason for hiding this comment

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

given that convertAmountAndPriceToNativeDisplay and convertAmountAndPriceToNativeDisplayWithThreshold are now basically the same with just the useThreshold arg being different, can we do the same and consolidate these or make a ticket to do this as clean up (ideally we would also convert the args to an object while we're at it)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what's the policy on putting args in an object or not

Copy link
Contributor

@walmat walmat left a comment

Choose a reason for hiding this comment

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

I'll go ahead and approve, but yeah the padding for nativeCurrency == eth is kinda weird with padding zeroes. Minor nitpick.

@benisgold benisgold force-pushed the @benisgold/swaps-native-currency branch from 8d403f4 to 72d52b8 Compare June 13, 2024 00:51
@benisgold benisgold requested a review from jinchung June 13, 2024 17:10
niceIncrement: initialNiceIncrement,
percentageToSwap: 0.5,
sliderXPosition: SLIDER_WIDTH / 2,
stripSeparators: true,
isStablecoin,
});

const initialInputNativeValue = toFixedWorklet(mulWorklet(initialInputAmount, initialSelectedInputAsset?.price?.value ?? 0), 2);
const nativeCurrency = store.getState().settings.nativeCurrency;
Copy link
Member

Choose a reason for hiding this comment

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

any reason we can't just use convertAmountAndPriceToNativeDisplay here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we don't want to include the denomination here

Copy link
Member

@jinchung jinchung left a comment

Choose a reason for hiding this comment

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

🌮

@benisgold benisgold merged commit 8d374db into develop Jun 14, 2024
6 checks passed
@benisgold benisgold deleted the @benisgold/swaps-native-currency branch June 14, 2024 16:10
BrodyHughes added a commit that referenced this pull request Jun 14, 2024
…o brody/swap-v2-e2e

* 'brody/swap-v2-e2e' of github.com:rainbow-me/rainbow:
  Revert "Lint on pre-commit (#5836)" (#5849)
  Lint on pre-commit (#5836)
  Swaps: fix handling of native currency formatting/presentation (#5826)
  Android crash fix from BlurView (#5844)
  Fix favorites nuances (#5846)
  fix quoted decimals issue (#5847)
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.

4 participants