Skip to content

Commit

Permalink
Fix gas setting impact
Browse files Browse the repository at this point in the history
  • Loading branch information
aminsato committed Nov 30, 2024
1 parent 31d7d0b commit d3d3571
Showing 1 changed file with 22 additions and 6 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 = updatedGasFee(gasFee,gasSettings,specific)

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

Expand Down Expand Up @@ -804,6 +808,17 @@ internal class SendFormViewModel @Inject constructor(
}
}

private fun updatedGasFee(
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 +1010,8 @@ internal class SendFormViewModel @Inject constructor(
srcAddress.address
)

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


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

0 comments on commit d3d3571

Please sign in to comment.