fix: error state when amount exceed wallet balance#649
fix: error state when amount exceed wallet balance#649jjramirezn merged 1 commit intopeanut-walletfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThe pull request focuses on improving error handling for transaction fee calculations and user balance checks. Changes are implemented in two files: Changes
Possibly related PRs
Suggested reviewers
Poem
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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
src/utils/sdkErrorHandler.utils.tsx (1)
100-101: LGTM! Consider standardizing error message format.The new error handling case correctly addresses the insufficient balance scenario. The message is clear and actionable.
Consider standardizing the error message format with other messages in the file:
- Some messages end with a period
- Some messages don't have punctuation
- Some start with "Please"
- return 'You do not have enough balance to cover the transaction fees, try again with a lower amount' + return 'You do not have enough balance to cover the transaction fees. Please try again with a lower amount.'src/components/Create/Link/Input.view.tsx (2)
181-188: Add null safety checks for undefined values.The comparison might fail if
transactionCostUSDis undefined.Consider adding explicit null safety checks:
- if (totalAmount > walletBalance) { + if (!transactionCostUSD) { + console.warn('Transaction cost estimation failed') + return + } + if (totalAmount.gt(walletBalance)) {
185-185: Extract duplicate error message to a constant.The same error message is duplicated at lines 185 and 215.
Consider extracting it to a constant:
+const INSUFFICIENT_BALANCE_ERROR = 'You do not have enough balance to cover the transaction fees, try again with a lower amount' // Then use it in both places: - errorMessage: - 'You do not have enough balance to cover the transaction fees, try again with a lower amount', + errorMessage: INSUFFICIENT_BALANCE_ERROR,Also applies to: 215-215
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/components/Create/Link/Input.view.tsx(2 hunks)src/utils/sdkErrorHandler.utils.tsx(1 hunks)
🔇 Additional comments (1)
src/components/Create/Link/Input.view.tsx (1)
178-189: LGTM! The balance check implementation aligns with PR objectives.The implementation correctly:
- Calculates total amount including gas fees
- Prevents proceeding if balance is insufficient
- Provides clear user feedback
| const totalAmount = parseFloat(tokenValue ?? '0') + (transactionCostUSD ?? 0) | ||
| const walletBalance = parseFloat(maxValue ?? '0') |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Use safer number handling for financial calculations.
The current implementation uses floating-point arithmetic which can lead to precision issues in financial calculations.
Consider using a decimal arithmetic library like decimal.js or bignumber.js:
- const totalAmount = parseFloat(tokenValue ?? '0') + (transactionCostUSD ?? 0)
- const walletBalance = parseFloat(maxValue ?? '0')
+ const totalAmount = new BigNumber(tokenValue ?? '0').plus(transactionCostUSD ?? '0')
+ const walletBalance = new BigNumber(maxValue ?? '0')Committable suggestion skipped: line range outside the PR's diff.
send amount + gasexceeds wallet balancefixes TASK-8303
Summary by CodeRabbit