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

Fix swaps crashing on tokens with 0 decimals #6263

Merged
merged 3 commits into from
Nov 13, 2024
Merged

Conversation

walmat
Copy link
Contributor

@walmat walmat commented Nov 12, 2024

Fixes APP-2024

What changed (plus any additional context for devs)

Tokens with 0 decimals was forcing our fallback case of 18 decimals. This was causing our swaps flow to underflow due to adjusting tokens that shouldn't be 18 decimals.

I've adjusted most of the places in our app that we use a default of 18 decimals to only do so if the decimals isn't a number value (aka typeof decimals !== 'number').

Screen recordings / screenshots

Simulator.Screen.Recording.-.iPhone.16.Pro.-.2024-11-12.at.13.40.09.mp4

What to test

Copy link

linear bot commented Nov 12, 2024

@walmat walmat changed the title Fix swaps crashing on tokens with 0 decimals. Fix swaps crashing on tokens with 0 decimals Nov 12, 2024
Comment on lines +223 to 224
minimumFractionDigits: Math.min(2, dec),
maximumFractionDigits: dec,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was breaking on 0 decimal assets so we need to min it.

@walmat walmat requested review from greg-schrammel, benisgold and ibrahimtaveras00 and removed request for greg-schrammel November 12, 2024 18:42
@walmat walmat marked this pull request as ready for review November 12, 2024 18:43
Comment on lines 494 to 495
const inputDecimals = inputAsset?.networks[inputAsset.chainId]?.decimals || inputAsset?.decimals;
const outputDecimals = outputAsset?.networks[outputAsset.chainId]?.decimals || outputAsset?.decimals;
Copy link
Contributor

@greg-schrammel greg-schrammel Nov 12, 2024

Choose a reason for hiding this comment

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

I think we should do

Suggested change
const inputDecimals = inputAsset?.networks[inputAsset.chainId]?.decimals || inputAsset?.decimals;
const outputDecimals = outputAsset?.networks[outputAsset.chainId]?.decimals || outputAsset?.decimals;
const inputDecimals = inputAsset?.networks[inputAsset.chainId]?.decimals ?? inputAsset?.decimals;
const outputDecimals = outputAsset?.networks[outputAsset.chainId]?.decimals ?? outputAsset?.decimals;

maybe don't have to check if is a number by using ??

Copy link
Contributor

@ibrahimtaveras00 ibrahimtaveras00 left a comment

Choose a reason for hiding this comment

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

Sanity checked the following:

  • 0 decimal tokens (WAAC and USDT)
  • 2 decimal token (GUSD)
  • 6 decimal token (USDC)
  • 18 decimal tokens (WETH, UNI)

looked good on both OS's, QA Passed 👍🏽

@walmat walmat merged commit 35daa8b into develop Nov 13, 2024
7 of 8 checks passed
@walmat walmat deleted the @matthew/APP-2024 branch November 13, 2024 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants