-
Notifications
You must be signed in to change notification settings - Fork 423
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
[Trade Tool]: Small QA Fixes #3803
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
4 Skipped Deployments
|
WalkthroughThe changes introduce a new parameter, Changes
Recent review detailsConfiguration used: CodeRabbit UI Files selected for processing (2)
Files skipped from review as they are similar to previous changes (1)
Additional comments not posted (2)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
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.
Actionable comments posted: 2
Outside diff range, codebase verification and nitpick comments (2)
packages/web/components/place-limit-tool/index.tsx (2)
Line range hint
73-89
: Enhance error handling intransformAmount
.The function
transformAmount
adjusts the input value based on its format and then limits the decimal places. However, it lacks error handling for non-numeric inputs which could lead to runtime errors whenparseFloat
is called infixDecimalCount
.Consider adding validation for numeric inputs at the beginning of the function to ensure stability:
const transformAmount = ( value: string, decimalCount = 18, rounding = false ) => { + if (!/^\d*\.?\d*$/.test(value)) throw new Error('Invalid numeric input'); let updatedValue = value; if (value.endsWith(".") && value.length === 1) { updatedValue = value + "0"; } ... };
Line range hint
255-311
: Review and adjust logic insetAmountSafe
function.This function is critical as it integrates the rounding and decimal precision adjustments into the main component logic. The changes made here are in line with the PR objectives, but there are a few considerations:
- The use of
undefined
formaxDecimals
in the call from line 376 might lead to unexpected behavior since the default value is2
. It should explicitly pass the correct decimal count based on the context.- The function is complex and handles multiple conditions; consider breaking it down into smaller, more manageable functions.
Refactor the function to improve readability and ensure consistent behavior by explicitly handling decimal counts and rounding:
const setAmountSafe = ( amountType: "fiat" | "token", value?: string, maxDecimals: number = 2, rounding: boolean = false ) => { ... const updatedValue = transformAmount( value, amountType === "fiat" ? maxDecimals : swapState.baseAsset?.coinDecimals, rounding ).trim(); + if (amountType === "token" && typeof maxDecimals === 'undefined') { + maxDecimals = swapState.baseAsset?.coinDecimals || 18; // Assuming 18 as a safe default + } ... };
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.
lgtm
What is the purpose of the change:
These changes adjust the following for the buy/sell tab: