Updated on 2026-08-14

This commit is contained in:
Tangem 2025-03-18 15:44:13 +03:00
parent 91e0956576
commit 3eb843a05f
3 changed files with 21 additions and 54 deletions

View file

@ -36,36 +36,6 @@ class GetCryptoCurrencyUseCase(
}
}
/**
* Returns specific cryptocurrency for a given user wallet.
*
* @param userWalletId The ID of the user's wallet.
* @param id The ID of the cryptocurrency.
* @return An [Either] representing success (Right) or an error (Left) in fetching the status.
*/
suspend operator fun invoke(
userWalletId: UserWalletId,
id: CryptoCurrency.ID,
): Either<CurrencyStatusError, CryptoCurrency> {
return either { getCurrency(userWalletId, id) }
}
/**
* Returns specific cryptocurrency for a given user wallet.
*
* !!! Important Use only [CryptoCurrency.ID.value] as cryptoCurrencyId
*
* @param userWalletId The ID of the user's wallet.
* @param cryptoCurrencyId String representation of the [CryptoCurrency.ID.value] of the cryptocurrency.
* @return An [Either] representing success (Right) or an error (Left) in fetching the status.
*/
suspend operator fun invoke(
userWalletId: UserWalletId,
cryptoCurrencyId: String,
): Either<CurrencyStatusError, CryptoCurrency> {
return either { getCurrency(userWalletId, cryptoCurrencyId) }
}
/**
* Returns the primary cryptocurrency for a given user wallet.
*
@ -76,18 +46,6 @@ class GetCryptoCurrencyUseCase(
return either { getPrimaryCurrency(userWalletId) }
}
private suspend fun Raise<CurrencyStatusError>.getCurrency(
userWalletId: UserWalletId,
id: CryptoCurrency.ID,
): CryptoCurrency {
return catch(
block = {
currenciesRepository.getMultiCurrencyWalletCurrency(userWalletId, id)
},
catch = { raise(CurrencyStatusError.DataError(it)) },
)
}
private suspend fun Raise<CurrencyStatusError>.getCurrency(
userWalletId: UserWalletId,
id: String,

View file

@ -19,6 +19,7 @@ import com.tangem.domain.onramp.model.cache.OnrampTransaction
import com.tangem.domain.onramp.model.error.OnrampError
import com.tangem.domain.tokens.GetCryptoCurrencyUseCase
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.wallets.usecase.GetUserWalletUseCase
import com.tangem.features.onramp.component.OnrampSuccessComponent
import com.tangem.features.onramp.impl.R
import com.tangem.features.onramp.success.entity.OnrampSuccessClickIntents
@ -42,6 +43,7 @@ internal class OnrampSuccessComponentModel @Inject constructor(
private val getOnrampStatusUseCase: GetOnrampStatusUseCase,
private val getCryptoCurrencyUseCase: GetCryptoCurrencyUseCase,
private val onrampRemoveTransactionUseCase: OnrampRemoveTransactionUseCase,
private val getUserWalletUseCase: GetUserWalletUseCase,
private val analyticsEventHandler: AnalyticsEventHandler,
private val messageSender: UiMessageSender,
private val router: Router,
@ -79,17 +81,21 @@ internal class OnrampSuccessComponentModel @Inject constructor(
}
private suspend fun loadTransactionStatus(transaction: OnrampTransaction) {
val multiCryptoCurrency = getCryptoCurrencyUseCase(
transaction.userWalletId,
transaction.toCurrencyId,
).getOrNull()
val cryptoCurrency = multiCryptoCurrency
?: getCryptoCurrencyUseCase.invoke(transaction.userWalletId).getOrElse {
Timber.e("Crypto currency not found")
showErrorAlert(OnrampError.DomainError(null))
return
}
val userWallet = getUserWalletUseCase(transaction.userWalletId).getOrNull()
if (userWallet == null) {
Timber.e("UserWallet found")
// this case should never happened
showErrorAlert(OnrampError.DomainError("UserWallet not found"))
return
}
val cryptoCurrency = getCryptoCurrencyUseCase(
userWallet = userWallet,
cryptoCurrencyId = transaction.toCurrencyId,
).getOrElse {
Timber.e("Crypto currency not found")
showErrorAlert(OnrampError.DomainError(null))
return
}
getOnrampStatusUseCase(txId = transaction.txId)
.fold(

View file

@ -419,7 +419,10 @@ internal class SendModel @Inject constructor(
return filterNot { it.isLocked }
.mapNotNull { wallet ->
val addresses = if (!wallet.isMultiCurrency) {
getCryptoCurrencyUseCase(wallet.walletId).getOrNull()?.let {
getCryptoCurrencyUseCase(
userWallet = wallet,
cryptoCurrencyId = cryptoCurrency.id.value,
).getOrNull()?.let {
if (it.network.id == cryptoCurrency.network.id) {
getNetworkAddressesUseCase.invokeSync(wallet.walletId, it.network)
} else {