Skip to content
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

Fix gas setting impact #1428

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ->
[email protected] = gasFee
},
gasSettings,
specific,
)
{ gasFee, gasSettings, specific ->
[email protected] = 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
)

[email protected] = gasFee
[email protected] =
adjustGasFee(gasFee, gasSettings.value, specific.value)


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