diff --git a/domain/account/status/src/main/java/com/tangem/domain/account/status/usecase/GetCryptoCurrencyActionsUseCaseV2.kt b/domain/account/status/src/main/java/com/tangem/domain/account/status/usecase/GetCryptoCurrencyActionsUseCaseV2.kt index 9c7c078cd8..d9185beaf3 100644 --- a/domain/account/status/src/main/java/com/tangem/domain/account/status/usecase/GetCryptoCurrencyActionsUseCaseV2.kt +++ b/domain/account/status/src/main/java/com/tangem/domain/account/status/usecase/GetCryptoCurrencyActionsUseCaseV2.kt @@ -8,6 +8,7 @@ import com.tangem.domain.models.account.AccountId import com.tangem.domain.models.currency.CryptoCurrency import com.tangem.domain.tokens.GetCryptoCurrencyActionsUseCase import com.tangem.domain.tokens.model.TokenActionsState +import com.tangem.domain.yield.supply.models.YieldSupplyAvailability import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.emitAll @@ -29,7 +30,11 @@ class GetCryptoCurrencyActionsUseCaseV2( ) { @OptIn(ExperimentalCoroutinesApi::class) - operator fun invoke(accountId: AccountId, currency: CryptoCurrency): Flow { + operator fun invoke( + accountId: AccountId, + currency: CryptoCurrency, + yieldSupplyAvailability: YieldSupplyAvailability = YieldSupplyAvailability.Unavailable, + ): Flow { return singleAccountStatusListSupplier( params = SingleAccountStatusListProducer.Params(userWalletId = accountId.userWalletId), ) @@ -44,6 +49,7 @@ class GetCryptoCurrencyActionsUseCaseV2( val actionsFlow = getCryptoCurrencyActionsUseCase( userWallet = userWallet, cryptoCurrencyStatus = accountCurrencyStatus.status, + yieldSupplyAvailability = yieldSupplyAvailability, ) emitAll(actionsFlow) diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/NewMarketsPortfolioDelegate.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/NewMarketsPortfolioDelegate.kt index a01af9079d..15f9bd9da6 100644 --- a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/NewMarketsPortfolioDelegate.kt +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/NewMarketsPortfolioDelegate.kt @@ -1,5 +1,6 @@ package com.tangem.features.markets.portfolio.impl.model +import arrow.core.getOrElse import com.tangem.blockchainsdk.compatibility.getTokenIdIfL2Network import com.tangem.common.ui.account.AccountTitleUM import com.tangem.common.ui.account.toUM @@ -24,6 +25,8 @@ import com.tangem.domain.models.wallet.UserWalletId import com.tangem.domain.models.wallet.isMultiCurrency import com.tangem.domain.tokens.model.TokenActionsState import com.tangem.domain.wallets.usecase.GetUserWalletUseCase +import com.tangem.domain.yield.supply.models.YieldSupplyAvailability +import com.tangem.domain.yield.supply.usecase.YieldSupplyGetAvailabilityUseCase import com.tangem.features.markets.portfolio.impl.loader.PortfolioData import com.tangem.features.markets.portfolio.impl.ui.state.MyPortfolioUM import com.tangem.features.markets.portfolio.impl.ui.state.MyPortfolioUM.Tokens.AddButtonState @@ -48,6 +51,7 @@ internal class NewMarketsPortfolioDelegate @AssistedInject constructor( private val allAccountSupplier: MultiAccountStatusListSupplier, private val getCryptoCurrencyActionsUseCase: GetCryptoCurrencyActionsUseCaseV2, private val getUserWalletUseCase: GetUserWalletUseCase, + private val yieldSupplyGetAvailabilityUseCase: YieldSupplyGetAvailabilityUseCase, isAccountsModeEnabledUseCase: IsAccountsModeEnabledUseCase, @Assisted private val scope: CoroutineScope, @Assisted private val token: TokenMarketParams, @@ -113,10 +117,17 @@ internal class NewMarketsPortfolioDelegate @AssistedInject constructor( private fun contentFlow(portfolio: PortfoliosWithThisCurrency): Flow { fun Portfolio.actionsFoAccountCurrencies(): List>> = accountsWithAdded.map { account -> - fun CryptoCurrencyStatus.actionsFlow() = getCryptoCurrencyActionsUseCase( - accountId = account.accountStatus.account.accountId, - currency = this.currency, - ).map { actionsState -> actionsState.cryptoCurrencyStatus.currency to actionsState } + fun CryptoCurrencyStatus.actionsFlow(): Flow> = flow { + val yieldSupplyAvailability = yieldSupplyGetAvailabilityUseCase(this@actionsFlow.currency) + .getOrElse { YieldSupplyAvailability.Unavailable } + emitAll( + getCryptoCurrencyActionsUseCase( + accountId = account.accountStatus.account.accountId, + currency = this@actionsFlow.currency, + yieldSupplyAvailability = yieldSupplyAvailability, + ).map { actionsState -> actionsState.cryptoCurrencyStatus.currency to actionsState }, + ) + } account.addedCurrency.map { it.actionsFlow() } }.flatten()