Skip to content

Conversation

@SeniorZhai
Copy link
Member

No description provided.

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 implements a feature to prevent unnecessary gas fee recalculation by caching the TipGas object once it's been calculated. The main optimization is that when gas has already been estimated in InputFragment, it's passed along to BrowserWalletBottomSheetDialogFragment to avoid recalculating during the periodic refresh cycle.

Key changes:

  • Added TipGas caching and passing between fragments to avoid redundant gas calculations
  • Made TipGas parcelable to support passing via bundle arguments
  • Improved fee display consistency by always showing the fee symbol, even when fee is zero

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
InputFragment.kt Stores calculated tipGas and passes it to the browser wallet dialog
Web3ViewModel.kt Adds calcFeeWithTipGas() method to return both fee and TipGas object
BrowserWalletBottomSheetDialogFragment.kt Conditionally skips gas estimation if tipGas is already provided
TipGas.kt Makes the data class Parcelable for bundle passing
SessionRequestPage.kt Ensures fee symbol is displayed even when fee is zero
BrowserPage.kt Ensures fee symbol is displayed even when fee is zero
Component.kt Adjusts loading indicator size and adds placeholder text for alignment
Theme.kt Adds inspection mode support to prevent initialization issues in previews

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +324 to +356
suspend fun calcFeeWithTipGas(
token: Web3TokenItem,
transaction: JsSignMessage,
fromAddress: String,
): Pair<BigDecimal?, TipGas?> {
val chain = token.getChainFromName()
if (chain == Chain.Solana) {
val tx = VersionedTransactionCompat.from(transaction.data ?: "")
val fee = tx.calcFee(fromAddress)
return Pair(fee, null)
} else {
val r = withContext(Dispatchers.IO) {
runCatching {
web3Repository.estimateFee(
EstimateFeeRequest(
token.chainId,
null,
transaction.data ?: transaction.wcEthereumTransaction?.data,
fromAddress,
transaction.wcEthereumTransaction?.to,
transaction.wcEthereumTransaction?.value,
)
)
}.getOrNull()
}
if (r?.isSuccess != true) return Pair(BigDecimal.ZERO, null)
return withContext(Dispatchers.IO) {
val tipGas = buildTipGas(chain.chainId, r.data!!)
val fee = tipGas.displayValue(transaction.wcEthereumTransaction?.maxFeePerGas) ?: BigDecimal.ZERO
Pair(fee, tipGas)
}
}
}
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The calcFeeWithTipGas method duplicates most of the logic from the existing calcFee method (lines 291-322). Consider refactoring calcFee to use calcFeeWithTipGas internally and return only the first element of the pair, or extract the common logic to avoid duplication.

Copilot uses AI. Check for mistakes.
Comment on lines 563 to 575
Text(
text = " ", //holder
color = MixinAppTheme.colors.textAssist,
maxLines = 1,
fontSize = 12.sp,
)
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'holder' in comment to 'placeholder'.

Copilot uses AI. Check for mistakes.
@SeniorZhai SeniorZhai force-pushed the feature/prevent-gas-refresh-once-calculated branch from 486fcf4 to 8babd62 Compare November 27, 2025 09:21
@SeniorZhai SeniorZhai added the testing Now testing, but you can review label Nov 27, 2025
@SeniorZhai SeniorZhai force-pushed the feature/prevent-gas-refresh-once-calculated branch from 8babd62 to f109aea Compare November 27, 2025 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Now testing, but you can review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants