Updated on 2026-08-14
This commit is contained in:
parent
42a9b57ee9
commit
2a85a3ce32
3 changed files with 27 additions and 15 deletions
|
|
@ -1,8 +1,10 @@
|
|||
package com.tangem.features.onramp.main.entity
|
||||
|
||||
import com.tangem.domain.onramp.model.OnrampAmount
|
||||
import com.tangem.domain.onramp.model.OnrampPaymentMethod
|
||||
|
||||
data class OnrampLastUpdate(
|
||||
val lastAmount: OnrampAmount,
|
||||
val lastCountryString: String,
|
||||
val fromAmount: OnrampAmount,
|
||||
val countryCode: String,
|
||||
val paymentMethod: OnrampPaymentMethod,
|
||||
)
|
||||
|
|
@ -69,7 +69,7 @@ internal class OnrampMainComponentModel @Inject constructor(
|
|||
|
||||
private val params: OnrampMainComponent.Params = paramsContainer.require()
|
||||
|
||||
private var isSepaLaunched = false
|
||||
private var shouldForceChooseSepa = params.launchSepa
|
||||
private var currencyToRestore: OnrampCurrency? = null
|
||||
|
||||
val userWallet = getWalletsUseCase.invokeSync().first { it.walletId == params.userWalletId }
|
||||
|
|
@ -133,6 +133,10 @@ internal class OnrampMainComponentModel @Inject constructor(
|
|||
|
||||
fun onProviderSelected(result: SelectProviderResult, isBestRate: Boolean) {
|
||||
_state.update { amountStateFactory.getAmountSecondaryUpdatedState(result, isBestRate) }
|
||||
|
||||
if (result.paymentMethod.id != SEPA_METHOD_ID) {
|
||||
shouldForceChooseSepa = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkResidenceCountry() {
|
||||
|
|
@ -342,9 +346,7 @@ internal class OnrampMainComponentModel @Inject constructor(
|
|||
private fun selectOrUpdateQuote(quotes: List<OnrampQuote>): OnrampQuote? {
|
||||
val quoteToCheck = quotes.firstOrNull { it !is OnrampQuote.Error }
|
||||
|
||||
val sepaQuote = if (params.launchSepa && !isSepaLaunched) {
|
||||
isSepaLaunched = true
|
||||
|
||||
val bestSepaQuote = if (params.launchSepa && shouldForceChooseSepa) {
|
||||
quotes.filterIsInstance<OnrampQuote.Data>()
|
||||
.filter { it.paymentMethod.id == SEPA_METHOD_ID }
|
||||
.maxByOrNull { it.toAmount.value }
|
||||
|
|
@ -353,7 +355,7 @@ internal class OnrampMainComponentModel @Inject constructor(
|
|||
}
|
||||
|
||||
// Check if amount, country or currency has changed
|
||||
val newQuote = sepaQuote ?: if (checkLastInputState(quoteToCheck)) {
|
||||
val newQuote = bestSepaQuote ?: if (isAmountOrCountryChanged(quoteToCheck)) {
|
||||
quoteToCheck
|
||||
} else {
|
||||
val state = state.value as? OnrampMainComponentUM.Content
|
||||
|
|
@ -372,7 +374,9 @@ internal class OnrampMainComponentModel @Inject constructor(
|
|||
lastSelectedQuote
|
||||
}
|
||||
}
|
||||
newQuote?.let { updateProvider(newQuote, quotes) }
|
||||
if (newQuote != null) {
|
||||
updateProvider(newQuote, quotes)
|
||||
}
|
||||
|
||||
return newQuote
|
||||
}
|
||||
|
|
@ -381,8 +385,13 @@ internal class OnrampMainComponentModel @Inject constructor(
|
|||
lastUpdateState.value = OnrampLastUpdate(
|
||||
quote.fromAmount,
|
||||
quote.countryCode,
|
||||
quote.paymentMethod,
|
||||
)
|
||||
|
||||
if (quote.paymentMethod.id != SEPA_METHOD_ID) {
|
||||
shouldForceChooseSepa = false
|
||||
}
|
||||
|
||||
_state.update {
|
||||
amountStateFactory.getUpdatedProviderState(selectedQuote = quote, quotes = quotes)
|
||||
}
|
||||
|
|
@ -448,9 +457,9 @@ internal class OnrampMainComponentModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun checkLastInputState(quote: OnrampQuote?): Boolean {
|
||||
return lastUpdateState.value?.lastAmount != quote?.fromAmount ||
|
||||
lastUpdateState.value?.lastCountryString != quote?.countryCode
|
||||
private fun isAmountOrCountryChanged(quote: OnrampQuote?): Boolean {
|
||||
return lastUpdateState.value?.fromAmount != quote?.fromAmount ||
|
||||
lastUpdateState.value?.countryCode != quote?.countryCode
|
||||
}
|
||||
|
||||
private companion object {
|
||||
|
|
|
|||
|
|
@ -348,8 +348,9 @@ internal class OnrampV2MainComponentModel @Inject constructor(
|
|||
|
||||
private fun updateProvider(quote: OnrampQuote) {
|
||||
lastUpdateState.value = OnrampLastUpdate(
|
||||
quote.fromAmount,
|
||||
quote.countryCode,
|
||||
fromAmount = quote.fromAmount,
|
||||
countryCode = quote.countryCode,
|
||||
paymentMethod = quote.paymentMethod,
|
||||
)
|
||||
|
||||
_state.update {
|
||||
|
|
@ -378,8 +379,8 @@ internal class OnrampV2MainComponentModel @Inject constructor(
|
|||
}
|
||||
|
||||
private fun checkLastInputState(quote: OnrampQuote?): Boolean {
|
||||
return lastUpdateState.value?.lastAmount != quote?.fromAmount ||
|
||||
lastUpdateState.value?.lastCountryString != quote?.countryCode
|
||||
return lastUpdateState.value?.fromAmount != quote?.fromAmount ||
|
||||
lastUpdateState.value?.countryCode != quote?.countryCode
|
||||
}
|
||||
|
||||
private fun sendScreenOpenAnalytics() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue