Skip to content

Conversation

@SeniorZhai
Copy link
Member

…eposit refresh logic

@SeniorZhai SeniorZhai requested a review from Copilot August 19, 2025 03:02
Copy link
Contributor

Copilot AI left a 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 clearPendingDepositsByAssetId method from WalletViewModel

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)
Copy link

Copilot AI Aug 19, 2025

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.

Suggested change
delay(10_000)
success = true
},
)
// Exponential backoff logic
if (success) {
currentDelay = baseDelay
} else {
currentDelay = (currentDelay * 2).coerceAtMost(maxDelay)
}
delay(currentDelay)

Copilot uses AI. Check for mistakes.
delay(10_000)
}
} catch (e: Exception) {
Timber.e(e, "Error refreshing pending deposits")
Copy link

Copilot AI Aug 19, 2025

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.

Suggested change
Timber.e(e, "Error refreshing pending deposits")
Timber.e(e, "Error refreshing pending deposits")
throw e

Copilot uses AI. Check for mistakes.
return@let
}
snapshots.map { it.assetId }.distinct().forEach {
walletViewModel.findOrSyncAsset(it)
Copy link

Copilot AI Aug 19, 2025

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.

Suggested change
walletViewModel.findOrSyncAsset(it)
kotlinx.coroutines.coroutineScope {
snapshots.map { it.assetId }
.distinct()
.map { assetId ->
async { walletViewModel.findOrSyncAsset(assetId) }
}
.awaitAll()

Copilot uses AI. Check for mistakes.
@SeniorZhai SeniorZhai marked this pull request as ready for review September 22, 2025 05:00
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants