Updated on 2026-08-14

This commit is contained in:
Tangem 2024-12-12 20:09:16 +05:00
parent b946eb5435
commit 029ba6e96c
5 changed files with 10 additions and 24 deletions

View file

@ -100,14 +100,16 @@ internal class DefaultOnrampRepository(
return countriesStore.getSyncOrNull(COUNTRIES_KEY)
}
override suspend fun fetchCountries() = withContext(dispatchers.io) {
if (!countriesStore.getSyncOrNull(COUNTRIES_KEY).isNullOrEmpty()) return@withContext
override suspend fun fetchCountries(): List<OnrampCountry> = withContext(dispatchers.io) {
if (!countriesStore.getSyncOrNull(COUNTRIES_KEY).isNullOrEmpty()) return@withContext emptyList()
val result = onrampApi.getCountries()
.getOrThrow()
.map(countryConverter::convert)
countriesStore.store(COUNTRIES_KEY, result)
result
}
override suspend fun getCountryByIp(): OnrampCountry = withContext(dispatchers.io) {

View file

@ -26,16 +26,16 @@ class CheckOnrampAvailabilityUseCase(
}
private suspend fun proceedWithSavedCountry(savedCountry: OnrampCountry): OnrampAvailability {
val countries = repository.getCountriesSync().orEmpty()
val onrampAvailable = countries.find { it == savedCountry }?.onrampAvailable ?: false
return if (onrampAvailable) {
val countries = repository.fetchCountries()
val updatedCountry = countries.find { it.id == savedCountry.id } ?: savedCountry
return if (updatedCountry.onrampAvailable) {
val currency = repository.getDefaultCurrencySync() ?: run {
repository.saveDefaultCurrency(savedCountry.defaultCurrency)
savedCountry.defaultCurrency
}
OnrampAvailability.Available(country = savedCountry, currency = currency)
} else {
OnrampAvailability.NotSupported(savedCountry)
OnrampAvailability.NotSupported(updatedCountry)
}
}
}

View file

@ -11,6 +11,6 @@ class FetchOnrampCountriesUseCase(
) {
suspend operator fun invoke(): Either<OnrampError, Unit> {
return Either.catch { repository.fetchCountries() }.mapLeft(errorResolver::resolve)
return Either.catch<Unit> { repository.fetchCountries() }.mapLeft(errorResolver::resolve)
}
}

View file

@ -16,7 +16,7 @@ interface OnrampRepository {
suspend fun getCountryByIp(): OnrampCountry
suspend fun getStatus(txId: String): OnrampStatus
suspend fun fetchCurrencies()
suspend fun fetchCountries()
suspend fun fetchCountries(): List<OnrampCountry>
suspend fun fetchPaymentMethodsIfAbsent()
suspend fun fetchPairs(currency: OnrampCurrency, country: OnrampCountry, cryptoCurrency: CryptoCurrency)
suspend fun fetchQuotes(cryptoCurrency: CryptoCurrency, amount: Amount)

View file

@ -8,18 +8,14 @@ import com.tangem.core.decompose.model.Model
import com.tangem.core.decompose.model.ParamsContainer
import com.tangem.core.decompose.navigation.Router
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.domain.onramp.GetOnrampCountryUseCase
import com.tangem.domain.onramp.OnrampSaveDefaultCountryUseCase
import com.tangem.domain.onramp.analytics.OnrampAnalyticsEvent
import com.tangem.features.onramp.confirmresidency.ConfirmResidencyComponent
import com.tangem.features.onramp.confirmresidency.entity.ConfirmResidencyBottomSheetConfig
import com.tangem.features.onramp.confirmresidency.entity.ConfirmResidencyUM
import com.tangem.features.onramp.impl.R
import com.tangem.features.onramp.utils.sendOnrampErrorEvent
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import javax.inject.Inject
@ -29,7 +25,6 @@ internal class ConfirmResidencyModel @Inject constructor(
private val analyticsEventHandler: AnalyticsEventHandler,
private val router: Router,
private val saveDefaultCountryUseCase: OnrampSaveDefaultCountryUseCase,
getOnrampCountryUseCase: GetOnrampCountryUseCase,
paramsContainer: ParamsContainer,
) : Model() {
@ -50,17 +45,6 @@ internal class ConfirmResidencyModel @Inject constructor(
init {
analyticsEventHandler.send(OnrampAnalyticsEvent.ResidenceConfirmScreenOpened(params.country.name))
getOnrampCountryUseCase.invoke()
.onEach { maybeCountry ->
maybeCountry.onLeft {
analyticsEventHandler.sendOnrampErrorEvent(it, params.cryptoCurrency.symbol)
}
val country = maybeCountry.getOrNull()
if (country != null) {
params.onDismiss(country)
}
}
.launchIn(modelScope)
}
private fun getPrimaryButtonConfig() = if (params.country.onrampAvailable) {