diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyUseCase.kt index b24eb525ae..4363b74633 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyUseCase.kt @@ -7,12 +7,35 @@ import arrow.core.raise.either import com.tangem.domain.tokens.error.CurrencyStatusError import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.repository.CurrenciesRepository +import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.models.UserWalletId class GetCryptoCurrencyUseCase( private val currenciesRepository: CurrenciesRepository, ) { + /** + * Returns specific cryptocurrency for a given user wallet. + * + * !!! Important Use only [CryptoCurrency.ID.value] as cryptoCurrencyId + * + * @param userWallet The user's wallet. + * @param cryptoCurrencyId The ID of the cryptocurrency. + * @return An [Either] representing success (Right) or an error (Left) in fetching the status. + */ + suspend operator fun invoke( + userWallet: UserWallet, + cryptoCurrencyId: String, + ): Either { + return either { + if (userWallet.isMultiCurrency) { + getCurrency(userWallet.walletId, cryptoCurrencyId) + } else { + getPrimaryCurrency(userWallet.walletId) + } + } + } + /** * Returns specific cryptocurrency for a given user wallet. * diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/deeplink/WalletDeepLinksHandler.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/deeplink/WalletDeepLinksHandler.kt index d58c9a80ae..8f5e4a3732 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/deeplink/WalletDeepLinksHandler.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/deeplink/WalletDeepLinksHandler.kt @@ -68,7 +68,7 @@ internal class WalletDeepLinksHandler @Inject constructor( } private suspend fun onSellCurrencyDeepLink(userWallet: UserWallet, data: SellCurrencyDeepLink.Data) { - val cryptoCurrency = getCryptoCurrencyUseCase(userWallet.walletId, data.currencyId).getOrNull() + val cryptoCurrency = getCryptoCurrencyUseCase(userWallet, data.currencyId).getOrNull() if (cryptoCurrency == null) { Timber.e("onSellCurrencyDeepLink cryptoCurrency is null")