Update activityUtils.ts #253
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
1-Removed Unused Imports
Eliminated decodeAbiParameters as it was not used anywhere. Removed solanaWeb3 = require("@solana/web3.js") since you're already importing PublicKey directly.
2-Improved Error Handling & Safety Checks
Used optional chaining (?.) to prevent crashes in case transaction, receipt, or block are null or undefined. Defaulted values to "0" if missing (transaction?.value ?? "0", etc.). Wrapped fetch calls with .catch(() => []) to avoid unhandled errors.
3-Optimized timeAgo and timeLeft Functions
Reduced redundancy by using an array of time units instead of multiple if-else statements. Used division logic to simplify conversions (e.g., secondsPast / (unit / 60)). Used await Promise.all() for Parallel Requests
Fetching the transaction receipt and transaction details at the same time for better performance.
4-Ensured Proper Return Values
getEclipseTransaction() and checkDepositWithPDA() now return null explicitly if no data is found instead of being undefined.