-
Notifications
You must be signed in to change notification settings - Fork 635
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
Conversation
0
decimals.0
decimals
minimumFractionDigits: Math.min(2, dec), | ||
maximumFractionDigits: dec, |
There was a problem hiding this comment.
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.
const inputDecimals = inputAsset?.networks[inputAsset.chainId]?.decimals || inputAsset?.decimals; | ||
const outputDecimals = outputAsset?.networks[outputAsset.chainId]?.decimals || outputAsset?.decimals; |
There was a problem hiding this comment.
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
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 ??
There was a problem hiding this 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 👍🏽
Fixes APP-2024
What changed (plus any additional context for devs)
Tokens with
0
decimals was forcing our fallback case of18
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 (akatypeof decimals !== 'number'
).Screen recordings / screenshots
Simulator.Screen.Recording.-.iPhone.16.Pro.-.2024-11-12.at.13.40.09.mp4
What to test