Updated on 2026-08-14

This commit is contained in:
Tangem 2026-05-14 12:37:27 +03:00
parent ce948a71ae
commit ad9def0d21
27 changed files with 6 additions and 291 deletions

View file

@ -29,9 +29,7 @@ import com.tangem.datasource.local.onramp.currencies.OnrampCurrenciesStore
import com.tangem.datasource.local.onramp.pairs.OnrampPairsStore
import com.tangem.datasource.local.onramp.paymentmethods.OnrampPaymentMethodsStore
import com.tangem.datasource.local.onramp.quotes.OnrampQuotesStore
import com.tangem.datasource.local.onramp.sepa.OnrampCurrentCountryByIPStore
import com.tangem.datasource.local.onramp.sepa.OnrampSepaAvailabilityStore
import com.tangem.datasource.local.onramp.sepa.OnrampSepaAvailabilityStoreKey
import com.tangem.datasource.local.onramp.country.OnrampCurrentCountryByIPStore
import com.tangem.datasource.local.preferences.AppPreferencesStore
import com.tangem.datasource.local.preferences.PreferencesKeys
import com.tangem.datasource.local.preferences.utils.getObject
@ -67,7 +65,6 @@ internal class DefaultOnrampRepository(
private val dispatchers: CoroutineDispatcherProvider,
private val appPreferencesStore: AppPreferencesStore,
private val paymentMethodsStore: OnrampPaymentMethodsStore,
private val onrampSepaAvailabilityStore: OnrampSepaAvailabilityStore,
private val onrampCurrentCountryByIPStore: OnrampCurrentCountryByIPStore,
private val pairsStore: OnrampPairsStore,
private val quotesStore: OnrampQuotesStore,
@ -281,62 +278,6 @@ internal class DefaultOnrampRepository(
storeOnrampPairs(pairs = onrampPairs.await(), providers = providers.await())
}
override suspend fun hasSepaMethod(
userWallet: UserWallet,
country: OnrampCountry,
cryptoCurrency: CryptoCurrency,
): Boolean {
return withContext(dispatchers.io) {
val key = OnrampSepaAvailabilityStoreKey(
userWallet = userWallet,
country = country,
cryptoCurrency = cryptoCurrency,
)
val isCachedValue = onrampSepaAvailabilityStore.getSyncOrNull(key)
if (isCachedValue != null) {
return@withContext isCachedValue
}
val onrampPairs =
safeApiCall(
call = {
onrampApi.getPairs(
userWalletId = userWallet.walletId.stringValue,
refCode = ExpressUtils.getRefCode(
userWallet = userWallet,
appPreferencesStore = appPreferencesStore,
),
body = OnrampPairsRequest(
fromCurrencyCode = EUR_CURRENCY_CODE,
countryCode = country.code,
to = listOf(
OnrampDestinationDTO(
contractAddress = cryptoCurrency.getContractAddress(),
network = cryptoCurrency.network.rawId,
),
),
),
).bind()
},
onError = { error ->
TangemLogger.w("Unable to fetch onramp pairs", error)
throw error
},
)
val hasSepaMethod = onrampPairs
.flatMap { it.providers }
.flatMap { it.paymentMethods }
.any { it == SEPA_METHOD_ID }
onrampSepaAvailabilityStore.store(key, hasSepaMethod)
hasSepaMethod
}
}
override suspend fun fetchQuotes(userWallet: UserWallet, cryptoCurrency: CryptoCurrency, amount: Amount) =
withContext(dispatchers.io) {
val pairs = requireNotNull(pairsStore.getSyncOrNull(PAIRS_KEY)) {
@ -632,8 +573,5 @@ internal class DefaultOnrampRepository(
const val PROVIDER_THEME_LIGHT = "light"
const val REDIRECT_URL = "https://tangem.com/onramp"
const val SEPA_METHOD_ID = "sepa"
const val EUR_CURRENCY_CODE = "EUR"
}
}

View file

@ -24,8 +24,7 @@ import com.tangem.datasource.local.onramp.currencies.OnrampCurrenciesStore
import com.tangem.datasource.local.onramp.pairs.OnrampPairsStore
import com.tangem.datasource.local.onramp.paymentmethods.OnrampPaymentMethodsStore
import com.tangem.datasource.local.onramp.quotes.OnrampQuotesStore
import com.tangem.datasource.local.onramp.sepa.OnrampCurrentCountryByIPStore
import com.tangem.datasource.local.onramp.sepa.OnrampSepaAvailabilityStore
import com.tangem.datasource.local.onramp.country.OnrampCurrentCountryByIPStore
import com.tangem.datasource.local.preferences.AppPreferencesStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.utils.coroutines.AppCoroutineScope
@ -56,7 +55,6 @@ internal object OnrampDataModule {
currenciesStore: OnrampCurrenciesStore,
walletManagersFacade: WalletManagersFacade,
dataSignatureVerifier: DataSignatureVerifier,
onrampSepaAvailabilityStore: OnrampSepaAvailabilityStore,
onrampCurrentCountryByIPStore: OnrampCurrentCountryByIPStore,
@NetworkMoshi moshi: Moshi,
): OnrampRepository {
@ -66,7 +64,6 @@ internal object OnrampDataModule {
dispatchers = dispatchers,
appPreferencesStore = appPreferencesStore,
paymentMethodsStore = paymentMethodsStore,
onrampSepaAvailabilityStore = onrampSepaAvailabilityStore,
onrampCurrentCountryByIPStore = onrampCurrentCountryByIPStore,
pairsStore = pairsStore,
quotesStore = quotesStore,