Updated on 2026-08-14
This commit is contained in:
parent
f532fe1ea1
commit
2c9b8eb80b
4 changed files with 49 additions and 24 deletions
|
|
@ -38,6 +38,7 @@ import com.tangem.utils.Provider
|
|||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import com.tangem.utils.coroutines.PeriodicTask
|
||||
import com.tangem.utils.coroutines.SingleTaskScheduler
|
||||
import com.tangem.utils.extensions.isSingleItem
|
||||
import com.tangem.utils.isNullOrZero
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.launch
|
||||
|
|
@ -196,8 +197,17 @@ internal class OnrampMainComponentModel @Inject constructor(
|
|||
quotes.filterIsInstance<OnrampQuote.Error>().forEach { errorState ->
|
||||
sendOnrampErrorAnalytic(errorState.error)
|
||||
}
|
||||
val isNoQuotes = quotes.none { it is OnrampQuote.Data }
|
||||
val quote = quotes.firstOrNull() ?: return@onEach
|
||||
|
||||
val bestProvider = quote as? OnrampQuote.Data
|
||||
val isMultipleQuotes = !quotes.isSingleItem()
|
||||
val isOtherQuotesHasData = quotes
|
||||
.filterNot { it == bestProvider }
|
||||
.any { it is OnrampQuote.Data }
|
||||
val hasBestProvider = isMultipleQuotes && isOtherQuotesHasData
|
||||
|
||||
val isBestProvider = quote == bestProvider && hasBestProvider
|
||||
|
||||
if (quote is OnrampQuote.Data && lastAmount.value != quote.fromAmount.value) {
|
||||
lastAmount.value = quote.fromAmount.value
|
||||
analyticsEventHandler.send(
|
||||
|
|
@ -208,7 +218,12 @@ internal class OnrampMainComponentModel @Inject constructor(
|
|||
),
|
||||
)
|
||||
}
|
||||
_state.update { amountStateFactory.getAmountSecondaryUpdatedState(quote, isNoQuotes) }
|
||||
_state.update {
|
||||
amountStateFactory.getAmountSecondaryUpdatedState(
|
||||
quote = quote,
|
||||
isBestRate = isBestProvider,
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ internal sealed interface ProviderListItemUM {
|
|||
val imageUrl: String,
|
||||
val rate: String,
|
||||
val isBestRate: Boolean,
|
||||
val diffRate: TextReference,
|
||||
val diffRate: TextReference?,
|
||||
val isSelected: Boolean,
|
||||
val onClick: () -> Unit,
|
||||
) : ProviderListItemUM
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import com.tangem.features.onramp.providers.entity.*
|
|||
import com.tangem.features.onramp.utils.sendOnrampErrorEvent
|
||||
import com.tangem.utils.StringsSigns.MINUS
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import com.tangem.utils.extensions.isSingleItem
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
|
@ -159,7 +160,11 @@ internal class SelectProviderModel @Inject constructor(
|
|||
val sorted = sortByRate()
|
||||
|
||||
val bestProvider = sorted.firstOrNull() as? OnrampProviderWithQuote.Data
|
||||
return sorted.mapIndexed { index, quote ->
|
||||
val isMultipleQuotes = !sorted.isSingleItem()
|
||||
val isOtherQuotesHasData = sorted.filterNot { it == bestProvider }.any { it is OnrampProviderWithQuote.Data }
|
||||
val hasBestProvider = isMultipleQuotes && isOtherQuotesHasData
|
||||
|
||||
return sorted.map { quote ->
|
||||
when (quote) {
|
||||
is OnrampProviderWithQuote.Data -> {
|
||||
val rate = quote.toAmount.value.format {
|
||||
|
|
@ -170,14 +175,16 @@ internal class SelectProviderModel @Inject constructor(
|
|||
}
|
||||
val isSelectedProvider = quote.provider.id == params.selectedProviderId
|
||||
val isSelectedPayment = quote.paymentMethod.id == params.selectedPaymentMethod.id
|
||||
val isBestProvider = quote == bestProvider && hasBestProvider
|
||||
ProviderListItemUM.Available(
|
||||
providerId = quote.provider.id,
|
||||
imageUrl = quote.provider.info.imageLarge,
|
||||
name = quote.provider.info.name,
|
||||
rate = rate,
|
||||
isSelected = isSelectedProvider && isSelectedPayment,
|
||||
isBestRate = quote == bestProvider,
|
||||
diffRate = stringReference("$MINUS${rateDiff.format { percent() }}"),
|
||||
isBestRate = isBestProvider,
|
||||
diffRate = stringReference("$MINUS${rateDiff.format { percent() }}")
|
||||
.takeIf { hasBestProvider },
|
||||
onClick = {
|
||||
onProviderSelected(
|
||||
result = SelectProviderResult.ProviderWithQuote(
|
||||
|
|
@ -186,7 +193,7 @@ internal class SelectProviderModel @Inject constructor(
|
|||
fromAmount = quote.fromAmount,
|
||||
toAmount = quote.toAmount,
|
||||
),
|
||||
isBestRate = bestProvider == quote,
|
||||
isBestRate = isBestProvider,
|
||||
)
|
||||
},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -184,23 +184,26 @@ private fun AvailableProviderItem(state: ProviderListItemUM.Available, modifier:
|
|||
style = TangemTheme.typography.body2,
|
||||
color = TangemTheme.colors.text.primary1,
|
||||
)
|
||||
if (state.isBestRate) {
|
||||
Text(
|
||||
text = stringResource(R.string.express_provider_best_rate),
|
||||
style = TangemTheme.typography.caption1,
|
||||
color = TangemTheme.colors.text.constantWhite,
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(4.dp))
|
||||
.background(TangemTheme.colors.icon.accent)
|
||||
.padding(vertical = 1.dp, horizontal = 6.dp),
|
||||
)
|
||||
} else {
|
||||
Text(
|
||||
text = state.diffRate.resolveReference(),
|
||||
style = TangemTheme.typography.caption2,
|
||||
color = TangemTheme.colors.text.warning,
|
||||
modifier = Modifier.padding(vertical = 1.dp),
|
||||
)
|
||||
when {
|
||||
state.isBestRate -> {
|
||||
Text(
|
||||
text = stringResource(R.string.express_provider_best_rate),
|
||||
style = TangemTheme.typography.caption1,
|
||||
color = TangemTheme.colors.text.constantWhite,
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(4.dp))
|
||||
.background(TangemTheme.colors.icon.accent)
|
||||
.padding(vertical = 1.dp, horizontal = 6.dp),
|
||||
)
|
||||
}
|
||||
state.diffRate != null -> {
|
||||
Text(
|
||||
text = state.diffRate.resolveReference(),
|
||||
style = TangemTheme.typography.caption2,
|
||||
color = TangemTheme.colors.text.warning,
|
||||
modifier = Modifier.padding(vertical = 1.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue