-
Notifications
You must be signed in to change notification settings - Fork 111
refactor: create PendingDepositRefreshHelper to consolidate pending d… #5750
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
base: master
Are you sure you want to change the base?
Conversation
…eposit refresh logic
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.
Pull Request Overview
This PR refactors the pending deposit refresh logic by extracting it into a new PendingDepositRefreshHelper utility class to eliminate code duplication across multiple wallet fragments.
- Consolidates duplicate pending deposit refresh logic from multiple fragments into a single helper class
- Implements lifecycle-aware job management for pending deposit refresh operations
- Removes the unused
clearPendingDepositsByAssetIdmethod fromWalletViewModel
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| WalletViewModel.kt | Removes unused clearPendingDepositsByAssetId method |
| TransactionsFragment.kt | Replaces custom refresh logic with PendingDepositRefreshHelper |
| PrivacyWalletFragment.kt | Replaces custom refresh logic with PendingDepositRefreshHelper |
| AllTransactionsFragment.kt | Replaces custom refresh logic with PendingDepositRefreshHelper |
| PendingDepositRefreshHelper.kt | Adds new helper class with consolidated pending deposit refresh logic |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| }, | ||
| ) | ||
|
|
||
| delay(10_000) |
Copilot
AI
Aug 19, 2025
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.
The infinite loop with fixed 10-second delay could lead to inefficient network requests and resource usage. Consider implementing exponential backoff on failures or a configurable refresh interval.
| delay(10_000) | |
| success = true | |
| }, | |
| ) | |
| // Exponential backoff logic | |
| if (success) { | |
| currentDelay = baseDelay | |
| } else { | |
| currentDelay = (currentDelay * 2).coerceAtMost(maxDelay) | |
| } | |
| delay(currentDelay) |
| delay(10_000) | ||
| } | ||
| } catch (e: Exception) { | ||
| Timber.e(e, "Error refreshing pending deposits") |
Copilot
AI
Aug 19, 2025
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.
The catch block only logs the error but doesn't handle it appropriately. Consider adding more specific error handling or rethrowing the exception to allow callers to handle it.
| Timber.e(e, "Error refreshing pending deposits") | |
| Timber.e(e, "Error refreshing pending deposits") | |
| throw e |
| return@let | ||
| } | ||
| snapshots.map { it.assetId }.distinct().forEach { | ||
| walletViewModel.findOrSyncAsset(it) |
Copilot
AI
Aug 19, 2025
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.
The sequential forEach call could result in multiple blocking database/network operations. Consider using parallel execution with async or batching these operations for better performance.
| walletViewModel.findOrSyncAsset(it) | |
| kotlinx.coroutines.coroutineScope { | |
| snapshots.map { it.assetId } | |
| .distinct() | |
| .map { assetId -> | |
| async { walletViewModel.findOrSyncAsset(assetId) } | |
| } | |
| .awaitAll() |
# Conflicts: # app/src/main/java/one/mixin/android/repository/Web3Repository.kt # app/src/main/java/one/mixin/android/ui/common/LoginVerifyBottomSheetDialogFragment.kt # app/src/main/java/one/mixin/android/ui/tip/wc/sessionproposal/SessionProposalPage.kt # app/src/main/java/one/mixin/android/ui/tip/wc/sessionproposal/SessionProposalViewModel.kt # app/src/main/java/one/mixin/android/ui/tip/wc/sessionrequest/SessionRequestViewModel.kt # app/src/main/java/one/mixin/android/ui/wallet/ClassicWalletFragment.kt # app/src/main/java/one/mixin/android/ui/wallet/PrivacyWalletFragment.kt # app/src/main/java/one/mixin/android/ui/wallet/TransactionsFragment.kt # app/src/main/java/one/mixin/android/ui/wallet/WalletFragment.kt
…eposit refresh logic