diff --git a/app/src/main/java/com/tangem/tap/di/domain/StakingDomainModule.kt b/app/src/main/java/com/tangem/tap/di/domain/StakingDomainModule.kt index 0807a628f1..6753cdf12a 100644 --- a/app/src/main/java/com/tangem/tap/di/domain/StakingDomainModule.kt +++ b/app/src/main/java/com/tangem/tap/di/domain/StakingDomainModule.kt @@ -152,8 +152,8 @@ internal object StakingDomainModule { fun provideGetPendingTransactionsUseCase( stakingPendingTransactionRepository: StakingPendingTransactionRepository, stakingErrorResolver: StakingErrorResolver, - ): GetPendingTransactionsUseCase { - return GetPendingTransactionsUseCase( + ): GetStakingPendingTransactionsUseCase { + return GetStakingPendingTransactionsUseCase( stakingPendingTransactionRepository = stakingPendingTransactionRepository, stakingErrorResolver = stakingErrorResolver, ) diff --git a/domain/staking/src/main/java/com/tangem/domain/staking/GetPendingTransactionsUseCase.kt b/domain/staking/src/main/java/com/tangem/domain/staking/GetStakingPendingTransactionsUseCase.kt similarity index 94% rename from domain/staking/src/main/java/com/tangem/domain/staking/GetPendingTransactionsUseCase.kt rename to domain/staking/src/main/java/com/tangem/domain/staking/GetStakingPendingTransactionsUseCase.kt index 1f4be9dea2..741456a4a8 100644 --- a/domain/staking/src/main/java/com/tangem/domain/staking/GetPendingTransactionsUseCase.kt +++ b/domain/staking/src/main/java/com/tangem/domain/staking/GetStakingPendingTransactionsUseCase.kt @@ -9,7 +9,7 @@ import com.tangem.domain.staking.repositories.StakingPendingTransactionRepositor /** * Use case for getting saved staking pending transactions. */ -class GetPendingTransactionsUseCase( +class GetStakingPendingTransactionsUseCase( private val stakingPendingTransactionRepository: StakingPendingTransactionRepository, private val stakingErrorResolver: StakingErrorResolver, ) { diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsLoadedBalanceConverter.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsLoadedBalanceConverter.kt index dafdd53e8c..b92a09ac94 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsLoadedBalanceConverter.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsLoadedBalanceConverter.kt @@ -13,6 +13,7 @@ import com.tangem.core.ui.extensions.wrappedList import com.tangem.core.ui.utils.BigDecimalFormatter import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.staking.model.StakingEntryInfo +import com.tangem.domain.staking.model.stakekit.BalanceItem import com.tangem.domain.staking.model.stakekit.RewardBlockType import com.tangem.domain.staking.model.stakekit.YieldBalance import com.tangem.domain.tokens.error.CurrencyStatusError @@ -37,6 +38,7 @@ internal class TokenDetailsLoadedBalanceConverter( private val currentStateProvider: Provider, private val appCurrencyProvider: Provider, private val stakingEntryInfoProvider: Provider, + private val pendingBalancesProvider: Provider>, private val symbol: String, private val decimals: Int, private val clickIntents: TokenDetailsClickIntents, @@ -143,16 +145,29 @@ internal class TokenDetailsLoadedBalanceConverter( val stakingEntryInfo = stakingEntryInfoProvider.invoke() val iconState = state.tokenInfoBlockState.iconState + val pendingBalances = pendingBalancesProvider.invoke() + val fiatRate = status.value.fiatRate return when { stakingCryptoAmount.isNullOrZero() && stakingEntryInfo != null -> { - getStakeAvailableState(stakingEntryInfo, iconState) + if (pendingBalances.isEmpty()) { + getStakeAvailableState(stakingEntryInfo, iconState) + } else { + val pendingBalancesCryptoAmount = pendingBalances.sumOf { it.amount } + + val stakingFiatAmount = fiatRate?.multiply(pendingBalancesCryptoAmount) + getStakedState( + status = status, + stakingCryptoAmount = pendingBalancesCryptoAmount, + stakingFiatAmount = stakingFiatAmount, + stakingRewardAmount = null, + ) + } } stakingCryptoAmount.isNullOrZero() && stakingEntryInfo == null -> { StakingBlockUM.Error(iconState = iconState) } else -> { - val fiatRate = status.value.fiatRate val stakingRewardAmount = yieldBalance?.getRewardStakingBalance()?.let { fiatRate?.multiply(it) } val stakingFiatAmount = stakingCryptoAmount?.let { fiatRate?.multiply(it) } diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsStateFactory.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsStateFactory.kt index 934b75a0d1..67a0d59d99 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsStateFactory.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsStateFactory.kt @@ -19,6 +19,7 @@ import com.tangem.domain.card.NetworkHasDerivationUseCase import com.tangem.domain.common.CardTypesResolver import com.tangem.domain.staking.model.StakingAvailability import com.tangem.domain.staking.model.StakingEntryInfo +import com.tangem.domain.staking.model.stakekit.BalanceItem import com.tangem.domain.staking.model.stakekit.StakingError import com.tangem.domain.tokens.error.CurrencyStatusError import com.tangem.domain.tokens.model.* @@ -52,6 +53,7 @@ internal class TokenDetailsStateFactory( private val appCurrencyProvider: Provider, private val stakingEntryInfoProvider: Provider, private val cryptoCurrencyStatusProvider: Provider, + private val pendingBalancesProvider: Provider>, private val clickIntents: TokenDetailsClickIntents, private val featureToggles: TokenDetailsFeatureToggles, private val networkHasDerivationUseCase: NetworkHasDerivationUseCase, @@ -81,6 +83,7 @@ internal class TokenDetailsStateFactory( currentStateProvider = currentStateProvider, appCurrencyProvider = appCurrencyProvider, stakingEntryInfoProvider = stakingEntryInfoProvider, + pendingBalancesProvider = pendingBalancesProvider, symbol = symbol, decimals = decimals, clickIntents = clickIntents, diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt index 5d65adaf1c..154f26312f 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt @@ -32,11 +32,13 @@ import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.demo.IsDemoCardUseCase import com.tangem.domain.redux.ReduxStateHolder import com.tangem.domain.settings.ShouldShowSwapPromoTokenUseCase +import com.tangem.domain.staking.GetStakingPendingTransactionsUseCase import com.tangem.domain.staking.GetStakingAvailabilityUseCase import com.tangem.domain.staking.GetStakingEntryInfoUseCase import com.tangem.domain.staking.GetYieldUseCase import com.tangem.domain.staking.model.StakingAvailability import com.tangem.domain.staking.model.StakingEntryInfo +import com.tangem.domain.staking.model.stakekit.BalanceItem import com.tangem.domain.tokens.* import com.tangem.domain.tokens.legacy.TradeCryptoAction import com.tangem.domain.tokens.legacy.TradeCryptoAction.TransactionInfo @@ -119,6 +121,7 @@ internal class TokenDetailsViewModel @Inject constructor( private val swapTransactionStatusStore: SwapTransactionStatusStore, private val isDemoCardUseCase: IsDemoCardUseCase, private val associateAssetUseCase: AssociateAssetUseCase, + private val getStakingPendingTransactionsUseCase: GetStakingPendingTransactionsUseCase, private val reduxStateHolder: ReduxStateHolder, private val analyticsEventsHandler: AnalyticsEventHandler, private val vibratorHapticManager: VibratorHapticManager, @@ -148,6 +151,8 @@ internal class TokenDetailsViewModel @Inject constructor( private val warningsJobHolder = JobHolder() private val swapTxJobHolder = JobHolder() private val selectedAppCurrencyFlow: StateFlow = createSelectedAppCurrencyFlow() + private val stakingPendingBalances: List + get() = getStakingPendingTransactionsUseCase().getOrElse { emptyList() } private var cryptoCurrencyStatus: CryptoCurrencyStatus? = null private var stakingEntryInfo: StakingEntryInfo? = null @@ -158,6 +163,7 @@ internal class TokenDetailsViewModel @Inject constructor( appCurrencyProvider = Provider(selectedAppCurrencyFlow::value), stakingEntryInfoProvider = Provider { stakingEntryInfo }, cryptoCurrencyStatusProvider = Provider { cryptoCurrencyStatus }, + pendingBalancesProvider = Provider { stakingPendingBalances }, clickIntents = this, symbol = cryptoCurrency.symbol, decimals = cryptoCurrency.decimals,