-
Notifications
You must be signed in to change notification settings - Fork 543
[SDK] Feature: Track insufficient funds error across SDK #7256
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
[SDK] Feature: Track insufficient funds error across SDK #7256
Conversation
…with helper functions, transaction execution/preparation tracking, and comprehensive test coverage
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
WalkthroughThe changes introduce robust detection and tracking of insufficient funds errors throughout transaction-related modules. New helper functions for error identification and detail extraction are added, with corresponding unit tests. Transaction flows in wallets and transaction utilities are updated to track insufficient funds errors with contextual information whenever such errors occur. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Wallet
participant TransactionModule
participant Helpers
participant Analytics
User->>Wallet: Initiate transaction
Wallet->>TransactionModule: Send transaction
TransactionModule->>Helpers: Try transaction, catch error
Helpers->>Helpers: isInsufficientFundsError(error)
alt Insufficient funds error detected
Helpers->>Analytics: trackInsufficientFundsError(context)
end
Helpers->>TransactionModule: Propagate error
TransactionModule->>Wallet: Propagate error
Wallet->>User: Error response
Suggested labels
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/thirdweb/src/wallets/smart/index.ts (1)
564-577
: Well-implemented error tracking with proper error flow preservation.The implementation correctly:
- Wraps existing logic without changing the success path
- Uses
resolvePromisedValue
to handle potentially promised values- Re-throws the original error to maintain existing error handling
However, consider adding error handling around the
resolvePromisedValue
calls to prevent secondary errors from masking the original transaction error.Consider wrapping the
resolvePromisedValue
calls in try-catch blocks:} catch (error) { // Track insufficient funds errors if (isInsufficientFundsError(error)) { + try { trackInsufficientFundsError({ client: options.client, error, walletAddress: options.accountContract.address, chainId: options.chain.id, - contractAddress: await resolvePromisedValue(executeTx.to ?? undefined), - transactionValue: await resolvePromisedValue(executeTx.value), + contractAddress: await resolvePromisedValue(executeTx.to ?? undefined).catch(() => undefined), + transactionValue: await resolvePromisedValue(executeTx.value).catch(() => undefined), }); + } catch { + // Ignore tracking errors to preserve original error + } } throw error; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
packages/thirdweb/src/analytics/track/helpers.test.ts
(1 hunks)packages/thirdweb/src/analytics/track/helpers.ts
(1 hunks)packages/thirdweb/src/analytics/track/transaction.test.ts
(2 hunks)packages/thirdweb/src/analytics/track/transaction.ts
(2 hunks)packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts
(2 hunks)packages/thirdweb/src/transaction/actions/estimate-gas.ts
(2 hunks)packages/thirdweb/src/transaction/actions/simulate.ts
(1 hunks)packages/thirdweb/src/transaction/extract-error.ts
(2 hunks)packages/thirdweb/src/wallets/injected/index.ts
(2 hunks)packages/thirdweb/src/wallets/smart/index.ts
(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (6)
packages/thirdweb/src/transaction/extract-error.ts (2)
packages/thirdweb/src/analytics/track/helpers.ts (1)
isInsufficientFundsError
(4-26)packages/thirdweb/src/analytics/track/transaction.ts (1)
trackInsufficientFundsError
(63-94)
packages/thirdweb/src/analytics/track/transaction.test.ts (2)
packages/thirdweb/src/exports/thirdweb.ts (1)
ThirdwebClient
(26-26)packages/thirdweb/src/analytics/track/transaction.ts (1)
trackInsufficientFundsError
(63-94)
packages/thirdweb/src/analytics/track/helpers.test.ts (1)
packages/thirdweb/src/analytics/track/helpers.ts (2)
isInsufficientFundsError
(4-26)getErrorDetails
(31-49)
packages/thirdweb/src/analytics/track/transaction.ts (2)
packages/thirdweb/src/wallets/in-app/core/wallet/types.ts (1)
Ecosystem
(20-23)packages/thirdweb/src/analytics/track/helpers.ts (1)
getErrorDetails
(31-49)
packages/thirdweb/src/wallets/injected/index.ts (3)
packages/thirdweb/src/exports/thirdweb.ts (2)
Hex
(261-261)getAddress
(307-307)packages/thirdweb/src/analytics/track/transaction.ts (2)
trackTransaction
(27-32)trackInsufficientFundsError
(63-94)packages/thirdweb/src/analytics/track/helpers.ts (1)
isInsufficientFundsError
(4-26)
packages/thirdweb/src/wallets/smart/index.ts (2)
packages/thirdweb/src/analytics/track/helpers.ts (1)
isInsufficientFundsError
(4-26)packages/thirdweb/src/analytics/track/transaction.ts (1)
trackInsufficientFundsError
(63-94)
⏰ Context from checks skipped due to timeout of 90000ms (8)
- GitHub Check: E2E Tests (pnpm, esbuild)
- GitHub Check: Size
- GitHub Check: E2E Tests (pnpm, webpack)
- GitHub Check: Build Packages
- GitHub Check: E2E Tests (pnpm, vite)
- GitHub Check: Lint Packages
- GitHub Check: Unit Tests
- GitHub Check: Analyze (javascript)
🔇 Additional comments (22)
packages/thirdweb/src/analytics/track/helpers.ts (2)
4-26
: Strong error detection logic with comprehensive pattern matching.The function correctly handles various error formats and uses case-insensitive matching for reliable detection. The logic covers multiple error structures and common insufficient funds error patterns.
31-49
: Well-structured error details extraction.The function provides a consistent interface for extracting error information from various error formats. The fallback logic ensures a valid response even for malformed errors.
packages/thirdweb/src/transaction/actions/simulate.ts (1)
92-92
: Good addition of sender context for error tracking.Adding
fromAddress
to the error extraction provides valuable context for insufficient funds error tracking without affecting the existing functionality.packages/thirdweb/src/transaction/actions/estimate-gas.ts (1)
97-97
: Consistent addition of sender context across gas estimation error paths.Both error handling paths now include
fromAddress
for better error tracking context. This enhances the insufficient funds error detection capabilities during gas estimation.Also applies to: 154-154
packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts (2)
2-4
: Clean imports for error detection and tracking functionality.The new imports are properly organized and provide the necessary functionality for insufficient funds error detection and tracking.
179-189
: Excellent implementation of insufficient funds error tracking.The error tracking logic is well-implemented with:
- Proper conditional detection using
isInsufficientFundsError
- Comprehensive context including wallet, chain, contract, and transaction details
- Correct use of
resolvePromisedValue
for async properties- Non-intrusive placement that doesn't affect the error flow
This enhances analytics capabilities while maintaining the existing error handling behavior.
packages/thirdweb/src/transaction/extract-error.ts (3)
3-4
: Clean imports for the new tracking functionality.The imports are properly structured and follow the existing import patterns in the file.
16-16
: Good addition of optional fromAddress parameter.This provides necessary context for tracking while maintaining backward compatibility with existing calls.
20-29
: Excellent fail-safe implementation of error tracking.The implementation correctly:
- Uses conditional checks to ensure tracking only occurs when appropriate
- Doesn't interfere with the existing error extraction flow
- Provides comprehensive context for analytics
The tracking call is not awaited, which is correct since it shouldn't block the error extraction process.
packages/thirdweb/src/wallets/smart/index.ts (1)
2-4
: Clean import organization.The imports are well-organized and follow the existing patterns in the file.
packages/thirdweb/src/analytics/track/transaction.test.ts (4)
5-8
: Proper import update for the new tracking function.The import statement correctly includes the new
trackInsufficientFundsError
function alongside the existing import.
134-172
: Comprehensive test coverage for insufficient funds error tracking.The test correctly verifies:
- Proper payload structure with the correct action type
- String conversion of bigint values (transactionValue)
- Handling of undefined optional fields
- Extraction of error message from the error object
This provides good coverage for the core tracking functionality.
174-199
: Excellent test for error resilience.This test ensures that tracking failures don't interfere with the main application flow, which is crucial for a tracking/analytics feature. The timeout is appropriate for ensuring the async operation completes.
201-238
: Good test coverage for transaction preparation scenario.This test verifies tracking behavior when optional fields like
transactionValue
are not provided, ensuring the function handles partial data gracefully.packages/thirdweb/src/wallets/injected/index.ts (2)
8-10
: Consistent import pattern with other wallet implementations.The imports follow the same pattern established in the smart wallet implementation, maintaining consistency across the codebase.
205-239
: Excellent implementation consistent with smart wallet error tracking.The implementation correctly:
- Preserves the existing success path unchanged
- Tracks insufficient funds errors with comprehensive context
- Maintains the original error flow by re-throwing
- Uses the same tracking pattern as the smart wallet implementation
The error tracking provides valuable analytics data including transaction value, contract address, and wallet context.
packages/thirdweb/src/analytics/track/helpers.test.ts (3)
1-3
: LGTM: Well-structured test setup.The imports are clean and appropriate. Using vitest for testing framework and importing the helper functions to be tested.
4-68
: Excellent comprehensive test coverage forisInsufficientFundsError
.The test suite thoroughly covers all the error detection patterns implemented in the helper function:
✅ Positive cases well covered:
- Basic insufficient funds messages
- Gas-related insufficient funds
- Balance-related errors
- Error codes and reason fields
- Nested data structures
- String errors
- Case insensitivity
✅ Edge cases properly handled:
- Null/undefined inputs
- Non-insufficient funds errors
The tests align perfectly with the implementation patterns in the helper function and provide robust validation.
70-109
: Comprehensive test coverage forgetErrorDetails
function.The test suite effectively validates all error extraction scenarios:
✅ Error shapes covered:
- Standard Error objects
- Objects with message and code properties
- Nested data structures
- String errors
- Null/undefined inputs
✅ Property extraction verified:
- Message extraction from various sources
- Code extraction from both
code
andreason
fields- Proper fallback handling
The tests ensure the function can handle the diverse error formats that might be encountered in the SDK.
packages/thirdweb/src/analytics/track/transaction.ts (3)
5-5
: LGTM: Appropriate import addition.The import of
getErrorDetails
from the helpers module is correctly placed and necessary for the new tracking function.
60-74
: Well-designed function signature for comprehensive error tracking.The function signature captures all the essential context needed for insufficient funds error analytics:
✅ Required parameters: Client and error object
✅ Optional context: Ecosystem, wallet address, chain ID, contract details
✅ Financial context: Transaction value, required amount, user balanceThe parameter structure enables rich analytics while maintaining flexibility for different calling contexts.
75-94
: Robust implementation with proper error detail extraction.The function implementation is well-structured:
✅ Error processing: Uses
getErrorDetails
helper for consistent error parsing
✅ Data consistency: Converts bigint values to strings for serialization
✅ Analytics structure: Follows established pattern with action and comprehensive data payload
✅ Optional handling: Properly handles optional fields (e.g.,errorCode
only included if present)The tracked data provides comprehensive context for analyzing insufficient funds scenarios across the SDK.
size-limit report 📦
|
Codecov ReportAttention: Patch coverage is
❌ Your patch status has failed because the patch coverage (45.23%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #7256 +/- ##
==========================================
+ Coverage 55.55% 55.57% +0.01%
==========================================
Files 908 909 +1
Lines 58571 58680 +109
Branches 4131 4157 +26
==========================================
+ Hits 32540 32610 +70
- Misses 25927 25963 +36
- Partials 104 107 +3
🚀 New features to boost your workflow:
|
This PR implements comprehensive tracking for insufficient funds errors throughout the thirdweb SDK. Includes helper functions for error detection, tracking during transaction execution and preparation phases, and comprehensive test coverage with 34 passing tests. Tracks errors from smart wallets, injected wallets, gas estimation, and transaction simulation. Uses existing analytics infrastructure with fail-safe implementation.
PR-Codex overview
This PR focuses on enhancing error tracking for insufficient funds in transaction processes. It introduces a new utility function to identify insufficient funds errors and integrates tracking for these errors across various transaction-related functions.
Detailed summary
isInsufficientFundsError
function to identify insufficient funds errors.estimateGas
,simulate
, and other transaction functions.useSendTransactionCore
and_sendUserOp
.Summary by CodeRabbit