Updated on 2026-08-14

This commit is contained in:
Tangem 2024-11-20 14:34:19 +05:00
parent 851d9ffea9
commit 9f65e1b80c
18 changed files with 347 additions and 2 deletions

View file

@ -0,0 +1,10 @@
package com.tangem.domain.onramp.model
import kotlinx.serialization.Serializable
@Serializable
data class OnrampPaymentMethod(
val id: String,
val name: String,
val imageUrl: String,
)

View file

@ -8,6 +8,7 @@ class CheckOnrampAvailabilityUseCase(private val repository: OnrampRepository) {
suspend operator fun invoke(): Either<Throwable, OnrampAvailability> {
return Either.catch {
repository.fetchPaymentMethodsIfAbsent()
repository.getDefaultCountrySync()?.let { savedCountry ->
return@catch if (savedCountry.onrampAvailable) {
val currency = repository.getDefaultCurrencySync() ?: run {

View file

@ -0,0 +1,12 @@
package com.tangem.domain.onramp
import arrow.core.Either
import com.tangem.domain.onramp.model.OnrampPaymentMethod
import com.tangem.domain.onramp.repositories.OnrampRepository
class GetOnrampPaymentMethodsUseCase(private val repository: OnrampRepository) {
suspend operator fun invoke(): Either<Throwable, List<OnrampPaymentMethod>> {
return Either.catch { repository.getPaymentMethods() }
}
}

View file

@ -3,6 +3,7 @@ package com.tangem.domain.onramp.repositories
import com.tangem.domain.onramp.model.OnrampCountry
import com.tangem.domain.onramp.model.OnrampCurrency
import com.tangem.domain.onramp.model.OnrampStatus
import com.tangem.domain.onramp.model.OnrampPaymentMethod
import kotlinx.coroutines.flow.Flow
interface OnrampRepository {
@ -11,6 +12,7 @@ interface OnrampRepository {
suspend fun getCountries(): List<OnrampCountry>
suspend fun getCountryByIp(): OnrampCountry
suspend fun getStatus(txId: String): OnrampStatus
suspend fun fetchPaymentMethodsIfAbsent()
// cache
suspend fun saveDefaultCurrency(currency: OnrampCurrency)
@ -19,4 +21,5 @@ interface OnrampRepository {
suspend fun saveDefaultCountry(country: OnrampCountry)
suspend fun getDefaultCountrySync(): OnrampCountry?
fun getDefaultCountry(): Flow<OnrampCountry?>
suspend fun getPaymentMethods(): List<OnrampPaymentMethod>
}