Updated on 2026-08-14
This commit is contained in:
parent
851d9ffea9
commit
9f65e1b80c
18 changed files with 347 additions and 2 deletions
|
|
@ -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,
|
||||
)
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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() }
|
||||
}
|
||||
}
|
||||
|
|
@ -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>
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue