Updated on 2026-08-14

This commit is contained in:
Tangem 2025-11-05 10:16:43 +01:00
parent 6036c65b64
commit 80a13febdf
5 changed files with 33 additions and 33 deletions

View file

@ -44,6 +44,12 @@ internal class DefaultOnrampTransactionRepository(
}
}
override fun getAllTransactions(): Flow<List<OnrampTransaction>> {
return appPreferencesStore
.getObjectSet<OnrampTransactionDTO>(PreferencesKeys.ONRAMP_TRANSACTIONS_STATUSES_KEY)
.map { transactions -> transactions.map(transactionConverter::convert) }
}
override suspend fun getTransactionById(txId: String): OnrampTransaction? = withContext(dispatchers.io) {
val stored = appPreferencesStore.getObjectSetSync<OnrampTransactionDTO>(
PreferencesKeys.ONRAMP_TRANSACTIONS_STATUSES_KEY,

View file

@ -3,8 +3,6 @@ package com.tangem.domain.onramp
import arrow.core.left
import arrow.core.right
import com.tangem.domain.core.utils.EitherFlow
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.onramp.model.*
import com.tangem.domain.onramp.model.cache.OnrampTransaction
import com.tangem.domain.onramp.model.error.OnrampError
@ -25,13 +23,10 @@ class GetOnrampOffersUseCase(
private val settingsRepository: SettingsRepository,
) {
operator fun invoke(
userWalletId: UserWalletId,
cryptoCurrencyId: CryptoCurrency.ID,
): EitherFlow<OnrampError, List<OnrampOffersBlock>> {
operator fun invoke(): EitherFlow<OnrampError, List<OnrampOffersBlock>> {
return combine(
onrampRepository.getQuotes(),
onrampTransactionRepository.getTransactions(userWalletId, cryptoCurrencyId),
onrampTransactionRepository.getAllTransactions(),
) { quotes, transactions ->
processOffers(quotes, transactions)
}

View file

@ -12,6 +12,8 @@ interface OnrampTransactionRepository {
suspend fun getTransactionById(txId: String): OnrampTransaction?
fun getAllTransactions(): Flow<List<OnrampTransaction>>
fun getTransactions(userWalletId: UserWalletId, cryptoCurrencyId: CryptoCurrency.ID): Flow<List<OnrampTransaction>>
suspend fun updateTransactionStatus(

View file

@ -2,7 +2,6 @@ package com.tangem.domain.onramp
import com.google.common.truth.Truth
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.onramp.model.*
import com.tangem.domain.onramp.model.cache.OnrampTransaction
import com.tangem.domain.onramp.repositories.OnrampErrorResolver
@ -25,7 +24,6 @@ class GetOnrampOffersUseCaseTest {
private val errorResolver: OnrampErrorResolver = mockk(relaxUnitFun = true)
private val settingsRepository: SettingsRepository = mockk(relaxUnitFun = true)
private val cryptoCurrencyId: CryptoCurrency.ID = mockk(relaxUnitFun = true)
private val userWalletId: UserWalletId = mockk(relaxUnitFun = true)
private lateinit var useCase: GetOnrampOffersUseCase
@ -47,11 +45,11 @@ class GetOnrampOffersUseCaseTest {
coEvery { settingsRepository.isGooglePayAvailability() } returns false
coEvery { onrampRepository.getQuotes() } returns flowOf(emptyQuotes)
coEvery { onrampTransactionRepository.getTransactions(userWalletId, cryptoCurrencyId) } returns flowOf(
coEvery { onrampTransactionRepository.getAllTransactions() } returns flowOf(
emptyTransactions,
)
val result = useCase(userWalletId, cryptoCurrencyId)
val result = useCase()
result.collect { either ->
Truth.assertThat(either.isRight()).isTrue()
@ -62,7 +60,7 @@ class GetOnrampOffersUseCaseTest {
}
coVerify { onrampRepository.getQuotes() }
coVerify { onrampTransactionRepository.getTransactions(userWalletId, cryptoCurrencyId) }
coVerify { onrampTransactionRepository.getAllTransactions() }
}
@Test
@ -83,11 +81,11 @@ class GetOnrampOffersUseCaseTest {
coEvery { settingsRepository.isGooglePayAvailability() } returns false
coEvery { onrampRepository.getQuotes() } returns flowOf(quotes)
coEvery { onrampTransactionRepository.getTransactions(userWalletId, cryptoCurrencyId) } returns flowOf(
coEvery { onrampTransactionRepository.getAllTransactions() } returns flowOf(
transactions,
)
val result = useCase(userWalletId, cryptoCurrencyId)
val result = useCase()
result.collect { either ->
Truth.assertThat(either.isRight()).isTrue()
@ -128,11 +126,11 @@ class GetOnrampOffersUseCaseTest {
coEvery { settingsRepository.isGooglePayAvailability() } returns false
coEvery { onrampRepository.getQuotes() } returns flowOf(quotes)
coEvery { onrampTransactionRepository.getTransactions(userWalletId, cryptoCurrencyId) } returns flowOf(
coEvery { onrampTransactionRepository.getAllTransactions() } returns flowOf(
transactions,
)
val result = useCase(userWalletId, cryptoCurrencyId)
val result = useCase()
result.collect { either ->
Truth.assertThat(either.isRight()).isTrue()
@ -175,11 +173,11 @@ class GetOnrampOffersUseCaseTest {
coEvery { settingsRepository.isGooglePayAvailability() } returns false
coEvery { onrampRepository.getQuotes() } returns flowOf(quotes)
coEvery { onrampTransactionRepository.getTransactions(userWalletId, cryptoCurrencyId) } returns flowOf(
coEvery { onrampTransactionRepository.getAllTransactions() } returns flowOf(
transactions,
)
val result = useCase(userWalletId, cryptoCurrencyId)
val result = useCase()
result.collect { either ->
Truth.assertThat(either.isRight()).isTrue()
@ -229,11 +227,11 @@ class GetOnrampOffersUseCaseTest {
coEvery { settingsRepository.isGooglePayAvailability() } returns false
coEvery { onrampRepository.getQuotes() } returns flowOf(quotes)
coEvery { onrampTransactionRepository.getTransactions(userWalletId, cryptoCurrencyId) } returns flowOf(
coEvery { onrampTransactionRepository.getAllTransactions() } returns flowOf(
transactions,
)
val result = useCase(userWalletId, cryptoCurrencyId)
val result = useCase()
result.collect { either ->
Truth.assertThat(either.isRight()).isTrue()

View file

@ -226,19 +226,18 @@ internal class OnrampV2MainComponentModel @Inject constructor(
}
private fun subscribeOnOffers() = modelScope.launch {
getOnrampOffersUseCase.invoke(
userWalletId = userWallet.walletId,
cryptoCurrencyId = params.cryptoCurrency.id,
).collectLatest { maybeOffers ->
maybeOffers.fold(
ifLeft = ::handleOnrampError,
ifRight = { offers ->
if (offers.isNotEmpty()) {
_state.update { onrampOffersStateFactory.getOffersState(offers) }
}
},
)
}
getOnrampOffersUseCase
.invoke()
.collectLatest { maybeOffers ->
maybeOffers.fold(
ifLeft = ::handleOnrampError,
ifRight = { offers ->
if (offers.isNotEmpty()) {
_state.update { onrampOffersStateFactory.getOffersState(offers) }
}
},
)
}
}
private fun subscribeToAmountChanges() = modelScope.launch {