Skip to content

Commit

Permalink
Fix gas setting impact (#1428)
Browse files Browse the repository at this point in the history
  • Loading branch information
aminsato authored Dec 4, 2024
1 parent 7170640 commit 6267a52
Showing 1 changed file with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -728,22 +728,26 @@ internal class SendFormViewModel @Inject constructor(

private fun calculateGasFees() {
viewModelScope.launch {
selectedToken
combine(
selectedToken
.filterNotNull()
.map {
gasFeeRepository.getGasFee(it.chain, it.address)
}
.catch {
// TODO handle error when querying gas fee
Timber.e(it)
}
.collect { gasFee ->
this@SendFormViewModel.gasFee.value = gasFee
},
gasSettings,
specific,
)
{ gasFee, gasSettings, specific ->
this@SendFormViewModel.gasFee.value = adjustGasFee(gasFee,gasSettings,specific)

// uiState.update {
// it.copy(gasFee = mapGasFeeToString(gasFee))
// }
}
}.collect()
}
}

Expand All @@ -752,7 +756,8 @@ internal class SendFormViewModel @Inject constructor(
combine(
selectedToken.filterNotNull(),
gasFee.filterNotNull(),
) { token, gasFee ->
gasSettings,
) { token, gasFee, gasSettings ->
val chain = token.chain
val srcAddress = token.address
advanceGasUiRepository.updateTokenStandard(
Expand Down Expand Up @@ -781,7 +786,10 @@ internal class SendFormViewModel @Inject constructor(
val estimatedFee = gasFeeToEstimatedFee(
GasFeeParams(
gasLimit = if (chain.standard == TokenStandard.EVM) {
(specific.value?.blockChainSpecific as BlockChainSpecific.Ethereum).gasLimit
if (gasSettings is GasSettings.Eth)
gasSettings.gasLimit
else
(specific.value?.blockChainSpecific as BlockChainSpecific.Ethereum).gasLimit
} else {
BigInteger.valueOf(1)
},
Expand All @@ -804,6 +812,17 @@ internal class SendFormViewModel @Inject constructor(
}
}

private fun adjustGasFee(
gasFee: TokenValue,
gasSettings: GasSettings?,
spec: BlockChainSpecificAndUtxo?,
) = gasFee.copy(
value = if (gasSettings is GasSettings.UTXO && spec?.blockChainSpecific is BlockChainSpecific.UTXO) {
gasSettings.byteFee
} else
gasFee.value
)

private fun loadSelectedCurrency() {
viewModelScope.launch {
appCurrency.collect { appCurrency ->
Expand Down Expand Up @@ -995,7 +1014,8 @@ internal class SendFormViewModel @Inject constructor(
srcAddress.address
)

this@SendFormViewModel.gasFee.value = gasFee
this@SendFormViewModel.gasFee.value =
adjustGasFee(gasFee, gasSettings.value, specific.value)


// Rapid toggling of isRefreshing can cause the initial true value to be skipped,
Expand Down

0 comments on commit 6267a52

Please sign in to comment.