Updated on 2026-08-14
This commit is contained in:
parent
bc8a0ba20d
commit
a733dd0e52
13 changed files with 158 additions and 25 deletions
|
|
@ -30,6 +30,9 @@ 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.preferences.AppPreferencesStore
|
||||
import com.tangem.datasource.local.preferences.PreferencesKeys
|
||||
import com.tangem.datasource.local.preferences.utils.getObject
|
||||
|
|
@ -64,6 +67,8 @@ 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,
|
||||
private val countriesStore: OnrampCountriesStore,
|
||||
|
|
@ -123,17 +128,30 @@ internal class DefaultOnrampRepository(
|
|||
result
|
||||
}
|
||||
|
||||
override suspend fun getCountryByIp(userWallet: UserWallet): OnrampCountry = withContext(dispatchers.io) {
|
||||
onrampApi.getCountryByIp(
|
||||
userWalletId = userWallet.walletId.stringValue,
|
||||
refCode = ExpressUtils.getRefCode(
|
||||
userWallet = userWallet,
|
||||
appPreferencesStore = appPreferencesStore,
|
||||
),
|
||||
)
|
||||
.getOrThrow()
|
||||
.let(countryConverter::convert)
|
||||
}
|
||||
override suspend fun getCountryByIp(userWallet: UserWallet, fromCache: Boolean): OnrampCountry =
|
||||
withContext(dispatchers.io) {
|
||||
if (fromCache) {
|
||||
val country = onrampCurrentCountryByIPStore.getSyncOrNull()
|
||||
|
||||
if (country != null) {
|
||||
return@withContext country
|
||||
}
|
||||
}
|
||||
|
||||
val country = onrampApi.getCountryByIp(
|
||||
userWalletId = userWallet.walletId.stringValue,
|
||||
refCode = ExpressUtils.getRefCode(
|
||||
userWallet = userWallet,
|
||||
appPreferencesStore = appPreferencesStore,
|
||||
),
|
||||
)
|
||||
.getOrThrow()
|
||||
.let(countryConverter::convert)
|
||||
|
||||
onrampCurrentCountryByIPStore.store(country)
|
||||
|
||||
country
|
||||
}
|
||||
|
||||
override suspend fun getStatus(userWallet: UserWallet, txId: String): OnrampStatus = withContext(dispatchers.io) {
|
||||
onrampApi.getStatus(
|
||||
|
|
@ -263,11 +281,22 @@ internal class DefaultOnrampRepository(
|
|||
|
||||
override suspend fun hasSepaMethod(
|
||||
userWallet: UserWallet,
|
||||
currency: OnrampCurrency,
|
||||
country: OnrampCountry,
|
||||
cryptoCurrency: CryptoCurrency,
|
||||
): Boolean {
|
||||
return withContext(dispatchers.io) {
|
||||
val key = OnrampSepaAvailabilityStoreKey(
|
||||
userWallet = userWallet,
|
||||
country = country,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
)
|
||||
|
||||
val cachedValue = onrampSepaAvailabilityStore.getSyncOrNull(key)
|
||||
|
||||
if (cachedValue != null) {
|
||||
return@withContext cachedValue
|
||||
}
|
||||
|
||||
val onrampPairs =
|
||||
safeApiCall(
|
||||
call = {
|
||||
|
|
@ -300,6 +329,8 @@ internal class DefaultOnrampRepository(
|
|||
.flatMap { it.paymentMethods }
|
||||
.any { it == SEPA_METHOD_ID }
|
||||
|
||||
onrampSepaAvailabilityStore.store(key, hasSepaMethod)
|
||||
|
||||
hasSepaMethod
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ 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.preferences.AppPreferencesStore
|
||||
import com.tangem.datasource.local.token.UserTokensResponseStore
|
||||
import com.tangem.datasource.local.userwallet.UserWalletsStore
|
||||
|
|
@ -52,6 +54,8 @@ internal object OnrampDataModule {
|
|||
currenciesStore: OnrampCurrenciesStore,
|
||||
walletManagersFacade: WalletManagersFacade,
|
||||
dataSignatureVerifier: DataSignatureVerifier,
|
||||
onrampSepaAvailabilityStore: OnrampSepaAvailabilityStore,
|
||||
onrampCurrentCountryByIPStore: OnrampCurrentCountryByIPStore,
|
||||
@NetworkMoshi moshi: Moshi,
|
||||
): OnrampRepository {
|
||||
return DefaultOnrampRepository(
|
||||
|
|
@ -60,6 +64,8 @@ internal object OnrampDataModule {
|
|||
dispatchers = dispatchers,
|
||||
appPreferencesStore = appPreferencesStore,
|
||||
paymentMethodsStore = paymentMethodsStore,
|
||||
onrampSepaAvailabilityStore = onrampSepaAvailabilityStore,
|
||||
onrampCurrentCountryByIPStore = onrampCurrentCountryByIPStore,
|
||||
pairsStore = pairsStore,
|
||||
quotesStore = quotesStore,
|
||||
currenciesStore = currenciesStore,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue