diff --git a/app/src/main/java/com/tangem/tap/di/domain/TokensDomainModule.kt b/app/src/main/java/com/tangem/tap/di/domain/TokensDomainModule.kt index 65df536429..62da11c64c 100644 --- a/app/src/main/java/com/tangem/tap/di/domain/TokensDomainModule.kt +++ b/app/src/main/java/com/tangem/tap/di/domain/TokensDomainModule.kt @@ -53,26 +53,6 @@ internal object TokensDomainModule { return DefaultTokensFeatureToggles(featureTogglesManager = featureTogglesManager) } - @Provides - @Singleton - fun provideGetCurrencyWarningsUseCase( - walletManagersFacade: WalletManagersFacade, - currenciesRepository: CurrenciesRepository, - currencyChecksRepository: CurrencyChecksRepository, - dispatchers: CoroutineDispatcherProvider, - baseCurrencyStatusOperations: BaseCurrencyStatusOperations, - multiWalletCryptoCurrenciesSupplier: MultiWalletCryptoCurrenciesSupplier, - ): GetCurrencyWarningsUseCase { - return GetCurrencyWarningsUseCase( - walletManagersFacade = walletManagersFacade, - currenciesRepository = currenciesRepository, - dispatchers = dispatchers, - currencyChecksRepository = currencyChecksRepository, - currencyStatusOperations = baseCurrencyStatusOperations, - multiWalletCryptoCurrenciesSupplier = multiWalletCryptoCurrenciesSupplier, - ) - } - @Provides @Singleton fun provideFetchCurrencyStatusUseCase( diff --git a/domain/account/status/src/main/java/com/tangem/domain/account/status/utils/AccountCryptoCurrencyStatusFinder.kt b/domain/account/status/src/main/java/com/tangem/domain/account/status/utils/AccountCryptoCurrencyStatusFinder.kt index 22033e6c37..abe7c314d1 100644 --- a/domain/account/status/src/main/java/com/tangem/domain/account/status/utils/AccountCryptoCurrencyStatusFinder.kt +++ b/domain/account/status/src/main/java/com/tangem/domain/account/status/utils/AccountCryptoCurrencyStatusFinder.kt @@ -218,7 +218,27 @@ internal object AccountCryptoCurrencyStatusFinder { return AccountCryptoCurrencyStatus(account = accountCurrency.account, status = currencyStatus) } - private fun AccountStatusList.getExpectedAccountStatuses(networks: List): List { + internal fun AccountStatusList.getExpectedAccountStatuses(networkId: Network.ID): List { + val possibleAccountIndex = getAccountIndexOrNull( + rawNetworkId = networkId.rawId.value, + derivationPath = networkId.derivationPath, + ) + + return when (possibleAccountIndex) { + null -> accountStatuses + DerivationIndex.Main.value -> listOf(mainAccount) + // currency only in the account with specific derivation index or in the main account + else -> { + val account = accountStatuses.firstOrNull { account -> + val cryptoPortfolio = account as? AccountStatus.CryptoPortfolio ?: return@firstOrNull false + cryptoPortfolio.account.derivationIndex.value == possibleAccountIndex + } + listOfNotNull(account, mainAccount) + } + } + } + + internal fun AccountStatusList.getExpectedAccountStatuses(networks: List): List { val possibleAccountIndexes = networks.mapNotNull { getAccountIndexOrNull(it.rawId, it.derivationPath) } if (possibleAccountIndexes.isEmpty()) return accountStatuses diff --git a/domain/account/status/src/main/java/com/tangem/domain/account/status/utils/CryptoCurrencyStatusOperations.kt b/domain/account/status/src/main/java/com/tangem/domain/account/status/utils/CryptoCurrencyStatusOperations.kt index b9e72590a1..d5381ae00d 100644 --- a/domain/account/status/src/main/java/com/tangem/domain/account/status/utils/CryptoCurrencyStatusOperations.kt +++ b/domain/account/status/src/main/java/com/tangem/domain/account/status/utils/CryptoCurrencyStatusOperations.kt @@ -4,6 +4,7 @@ import arrow.core.Option import arrow.core.toOption import com.tangem.domain.account.models.AccountStatusList import com.tangem.domain.account.status.model.AccountCryptoCurrencyStatus +import com.tangem.domain.account.status.utils.AccountCryptoCurrencyStatusFinder.getExpectedAccountStatuses import com.tangem.domain.account.status.utils.AccountCryptoCurrencyStatusOperations.getAccountCryptoCurrencyStatus import com.tangem.domain.models.account.AccountStatus import com.tangem.domain.models.currency.CryptoCurrency @@ -68,6 +69,25 @@ object CryptoCurrencyStatusOperations { return getAccountCryptoCurrencyStatus(currencyId = currencyId, network = network) .map(AccountCryptoCurrencyStatus::status) } + + fun AccountStatusList.getCoinStatus(currency: CryptoCurrency): Option { + return getCoinStatus(network = currency.network) + } + + fun AccountStatusList.getCoinStatus(network: Network): Option { + return getCoinStatus(networkId = network.id) + } + + fun AccountStatusList.getCoinStatus(networkId: Network.ID): Option { + return getExpectedAccountStatuses(networkId) + .flatMap { accountStatus -> + (accountStatus as? AccountStatus.CryptoPortfolio) + ?.flattenCurrencies().orEmpty() + .filter { it.currency is CryptoCurrency.Coin } + } + .firstOrNull { status -> status.currency.network.id == networkId } + .toOption() + } // endregion // region AccountStatus.CryptoPortfolio diff --git a/domain/account/status/src/test/kotlin/com/tangem/domain/account/status/utils/CryptoCurrencyStatusOperationsTest.kt b/domain/account/status/src/test/kotlin/com/tangem/domain/account/status/utils/CryptoCurrencyStatusOperationsTest.kt index e79ed8bfbb..554a63f4ca 100644 --- a/domain/account/status/src/test/kotlin/com/tangem/domain/account/status/utils/CryptoCurrencyStatusOperationsTest.kt +++ b/domain/account/status/src/test/kotlin/com/tangem/domain/account/status/utils/CryptoCurrencyStatusOperationsTest.kt @@ -1,7 +1,9 @@ package com.tangem.domain.account.status.utils +import com.tangem.blockchain.common.Blockchain import com.tangem.common.test.domain.token.MockCryptoCurrencyFactory import com.tangem.domain.account.models.AccountStatusList +import com.tangem.domain.account.status.utils.CryptoCurrencyStatusOperations.getCoinStatus import com.tangem.domain.account.status.utils.CryptoCurrencyStatusOperations.getCryptoCurrencyStatus import com.tangem.domain.core.utils.lceLoading import com.tangem.domain.models.TokensGroupType @@ -11,6 +13,7 @@ import com.tangem.domain.models.account.Account import com.tangem.domain.models.account.AccountStatus import com.tangem.domain.models.currency.CryptoCurrency import com.tangem.domain.models.currency.CryptoCurrencyStatus +import com.tangem.domain.models.network.Network import com.tangem.domain.models.tokenlist.TokenList import com.tangem.domain.models.wallet.UserWalletId import com.tangem.test.core.assertNone @@ -286,6 +289,227 @@ class CryptoCurrencyStatusOperationsTest { } } + @Nested + @TestInstance(TestInstance.Lifecycle.PER_CLASS) + inner class GetCoinStatusByCurrency { + + @Test + fun `returns None when no coin exists for the currency network`() { + // Arrange + val token = cryptoCurrencyFactory.createToken(Blockchain.Ethereum) + val tokenStatus = CryptoCurrencyStatus( + currency = token, + value = CryptoCurrencyStatus.Loading, + ) + val accountStatusList = createAccountStatusList( + currencies = listOf(token), + currencyStatuses = listOf(tokenStatus), + ) + // Act + val result = accountStatusList.getCoinStatus(token) + // Assert + assertNone(result) + } + + @Test + fun `returns Some when coin exists for the currency network`() { + // Arrange + val coinStatus = CryptoCurrencyStatus( + currency = currency, + value = CryptoCurrencyStatus.Loading, + ) + val accountStatusList = createAccountStatusList( + currencies = listOf(currency), + currencyStatuses = listOf(coinStatus), + ) + // Act + val result = accountStatusList.getCoinStatus(currency) + // Assert + assertSome(result, coinStatus) + } + } + + @Nested + @TestInstance(TestInstance.Lifecycle.PER_CLASS) + inner class GetCoinStatusByNetwork { + + @Test + fun `returns None when AccountStatusList has empty token list`() { + // Arrange + val accountStatusList = createAccountStatusList(currencies = emptyList()) + // Act + val result = accountStatusList.getCoinStatus(currency.network) + // Assert + assertNone(result) + } + + @Test + fun `returns None when only tokens exist for network`() { + // Arrange + val token = cryptoCurrencyFactory.createToken(Blockchain.Ethereum) + val tokenStatus = CryptoCurrencyStatus( + currency = token, + value = CryptoCurrencyStatus.Loading, + ) + val accountStatusList = createAccountStatusList( + currencies = listOf(token), + currencyStatuses = listOf(tokenStatus), + ) + // Act + val result = accountStatusList.getCoinStatus(currency.network) + // Assert + assertNone(result) + } + + @Test + fun `returns Some when coin exists for network`() { + // Arrange + val coinStatus = CryptoCurrencyStatus( + currency = currency, + value = CryptoCurrencyStatus.Loading, + ) + val accountStatusList = createAccountStatusList( + currencies = listOf(currency), + currencyStatuses = listOf(coinStatus), + ) + // Act + val result = accountStatusList.getCoinStatus(currency.network) + // Assert + assertSome(result, coinStatus) + } + + @Test + fun `returns coin status when both coin and token exist for same network`() { + // Arrange + val token = cryptoCurrencyFactory.createToken(Blockchain.Ethereum) + val coinStatus = CryptoCurrencyStatus( + currency = currency, + value = CryptoCurrencyStatus.Loading, + ) + val tokenStatus = CryptoCurrencyStatus( + currency = token, + value = CryptoCurrencyStatus.Loading, + ) + val accountStatusList = createAccountStatusList( + currencies = listOf(currency, token), + currencyStatuses = listOf(coinStatus, tokenStatus), + ) + // Act + val result = accountStatusList.getCoinStatus(currency.network) + // Assert + assertSome(result, coinStatus) + } + } + + @Nested + @TestInstance(TestInstance.Lifecycle.PER_CLASS) + inner class GetCoinStatusByNetworkId { + + @Test + fun `returns None when AccountStatusList has empty token list`() { + // Arrange + val accountStatusList = createAccountStatusList(currencies = emptyList()) + // Act + val result = accountStatusList.getCoinStatus(currency.network.id) + // Assert + assertNone(result) + } + + @Test + fun `returns None when network id does not match any currency`() { + // Arrange + val coinStatus = CryptoCurrencyStatus( + currency = currency, + value = CryptoCurrencyStatus.Loading, + ) + val accountStatusList = createAccountStatusList( + currencies = listOf(currency), + currencyStatuses = listOf(coinStatus), + ) + val otherNetworkId = Network.ID(value = "bitcoin", derivationPath = Network.DerivationPath.None) + // Act + val result = accountStatusList.getCoinStatus(otherNetworkId) + // Assert + assertNone(result) + } + + @Test + fun `returns None when only tokens exist for network id`() { + // Arrange + val token = cryptoCurrencyFactory.createToken(Blockchain.Ethereum) + val tokenStatus = CryptoCurrencyStatus( + currency = token, + value = CryptoCurrencyStatus.Loading, + ) + val accountStatusList = createAccountStatusList( + currencies = listOf(token), + currencyStatuses = listOf(tokenStatus), + ) + // Act + val result = accountStatusList.getCoinStatus(token.network.id) + // Assert + assertNone(result) + } + + @Test + fun `returns Some when coin exists for network id`() { + // Arrange + val coinStatus = CryptoCurrencyStatus( + currency = currency, + value = CryptoCurrencyStatus.Loading, + ) + val accountStatusList = createAccountStatusList( + currencies = listOf(currency), + currencyStatuses = listOf(coinStatus), + ) + // Act + val result = accountStatusList.getCoinStatus(currency.network.id) + // Assert + assertSome(result, coinStatus) + } + + @Test + fun `returns coin status when both coin and token exist for same network id`() { + // Arrange + val token = cryptoCurrencyFactory.createToken(Blockchain.Ethereum) + val coinStatus = CryptoCurrencyStatus( + currency = currency, + value = CryptoCurrencyStatus.Loading, + ) + val tokenStatus = CryptoCurrencyStatus( + currency = token, + value = CryptoCurrencyStatus.Loading, + ) + val accountStatusList = createAccountStatusList( + currencies = listOf(currency, token), + currencyStatuses = listOf(coinStatus, tokenStatus), + ) + // Act + val result = accountStatusList.getCoinStatus(currency.network.id) + // Assert + assertSome(result, coinStatus) + } + + @Test + fun `returns correct coin when multiple networks exist`() { + // Arrange + val currencies = cryptoCurrencyFactory.ethereumAndStellar + val currencyStatuses = currencies.map { + CryptoCurrencyStatus(currency = it, value = CryptoCurrencyStatus.Loading) + } + val accountStatusList = createAccountStatusList( + currencies = currencies, + currencyStatuses = currencyStatuses, + ) + val targetCurrency = currencies.last() + val expectedStatus = currencyStatuses.last() + // Act + val result = accountStatusList.getCoinStatus(targetCurrency.network.id) + // Assert + assertSome(result, expectedStatus) + } + } + private fun createAccountStatusList( currencies: List, currencyStatuses: List = emptyList(), diff --git a/domain/tokens/detekt-baseline-debug.xml b/domain/tokens/detekt-baseline-debug.xml index 352d25c614..3c148b5f78 100644 --- a/domain/tokens/detekt-baseline-debug.xml +++ b/domain/tokens/detekt-baseline-debug.xml @@ -11,8 +11,6 @@ MultilineLambdaItParameter:FetchCurrencyStatusUseCase.kt$FetchCurrencyStatusUseCase${ when (it) { is StakingIdFactory.Error.UnableToGetAddress -> raise(IllegalStateException("$it")) StakingIdFactory.Error.UnsupportedCurrency -> Unit.right() } return@either } MultilineLambdaItParameter:GetBalanceNotEnoughForFeeWarningUseCase.kt$GetBalanceNotEnoughForFeeWarningUseCase${ it is CryptoCurrency.Token && it.contractAddress.equals(feePaidToken.contractAddress, ignoreCase = true) && it.network.derivationPath == tokenStatus.currency.network.derivationPath } MultilineLambdaItParameter:GetCryptoCurrencyActionsUseCase.kt$GetCryptoCurrencyActionsUseCase${ TokenActionsState( walletId = userWallet.walletId, cryptoCurrencyStatus = cryptoCurrencyStatus, states = it.toList(), ) } - MultilineLambdaItParameter:GetCurrencyWarningsUseCase.kt$GetCurrencyWarningsUseCase${ if (isNeedToCreateAccountWithoutReserve(networkId = currencyStatus.currency.network.rawId)) { CryptoCurrencyWarning.TopUpWithoutReserve } else { CryptoCurrencyWarning.SomeNetworksNoAccount( amountToCreateAccount = it.amountToCreateAccount, amountCurrency = currencyStatus.currency, ) } } - MultilineLambdaItParameter:GetCurrencyWarningsUseCase.kt$GetCurrencyWarningsUseCase${ it is CryptoCurrency.Token && it.contractAddress.equals(feePaidToken.contractAddress, ignoreCase = true) && it.network.derivationPath == tokenStatus.currency.network.derivationPath } MultilineLambdaItParameter:GetWalletTotalBalanceUseCase.kt$GetWalletTotalBalanceUseCase${ Timber.e("failed to load balances with error: $it") TotalFiatBalance.Failed } MultilineLambdaItParameter:PriceChangeCalculator.kt$PriceChangeCalculator${ val weight = it.value.fiatAmount.orZero().divide(balance, 2, RoundingMode.HALF_UP) val priceChange = it.value.priceChange.orZero() weight * priceChange } MultilineLambdaItParameter:WalletBalanceFetcher.kt$WalletBalanceFetcher${ val stakingId = stakingIdFactory.create(userWalletId = userWalletId, cryptoCurrency = it) if (stakingId.isLeft { it is StakingIdFactory.Error.UnableToGetAddress }) { Timber.e("Unable to get staking ID for user wallet $userWalletId and currency ${it.id}") } stakingId } @@ -20,7 +18,6 @@ NoNameShadowing:WalletBalanceFetcher.kt$WalletBalanceFetcher${ it is StakingIdFactory.Error.UnableToGetAddress } NullableBooleanCheck:GetCurrencyCheckUseCase.kt$GetCurrencyCheckUseCase$recipientAddress?.let { currencyChecksRepository.checkIfAccountFunded( userWalletId, network, recipientAddress, ) } ?: false SuspendFunWithFlowReturnType:BaseCurrencyStatusOperations.kt$BaseCurrencyStatusOperations$suspend - SuspendFunWithFlowReturnType:GetCurrencyWarningsUseCase.kt$GetCurrencyWarningsUseCase$suspend SuspendFunWithFlowReturnType:GetNetworkCoinStatusUseCase.kt$GetNetworkCoinStatusUseCase$suspend SuspendFunWithFlowReturnType:GetSingleCryptoCurrencyStatusUseCase.kt$GetSingleCryptoCurrencyStatusUseCase$suspend UnnecessaryAbstractClass:MultiWalletCryptoCurrenciesSupplier.kt$MultiWalletCryptoCurrenciesSupplier$MultiWalletCryptoCurrenciesSupplier diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/BaseCurrenciesStatusesOperations.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/BaseCurrenciesStatusesOperations.kt deleted file mode 100644 index d3842665be..0000000000 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/BaseCurrenciesStatusesOperations.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.tangem.domain.tokens.operations - -import com.tangem.domain.core.lce.LceFlow -import com.tangem.domain.models.currency.CryptoCurrencyStatus -import com.tangem.domain.models.wallet.UserWalletId -import com.tangem.domain.tokens.error.TokenListError - -/** - * Base operations for working with currencies statuses - * -[REDACTED_AUTHOR] - */ -interface BaseCurrenciesStatusesOperations { - - /** Get [LceFlow] of currencies statuses by [userWalletId] */ - fun getCurrenciesStatuses(userWalletId: UserWalletId): LceFlow> -} \ No newline at end of file diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/domain/GetCurrencyWarningsUseCase.kt similarity index 83% rename from domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt rename to features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/domain/GetCurrencyWarningsUseCase.kt index 15315030c7..1c8370811a 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/domain/GetCurrencyWarningsUseCase.kt @@ -1,17 +1,21 @@ -package com.tangem.domain.tokens +package com.tangem.feature.tokendetails.domain import com.tangem.blockchainsdk.utils.isNeedToCreateAccountWithoutReserve +import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier +import com.tangem.domain.account.status.utils.CryptoCurrencyStatusOperations.getCoinStatus +import com.tangem.domain.account.status.utils.CryptoCurrencyStatusOperations.getCryptoCurrencyStatus import com.tangem.domain.models.StatusSource import com.tangem.domain.models.currency.CryptoCurrency import com.tangem.domain.models.currency.CryptoCurrencyStatus import com.tangem.domain.models.network.Network import com.tangem.domain.models.wallet.UserWalletId +import com.tangem.domain.tokens.MultiWalletCryptoCurrenciesProducer +import com.tangem.domain.tokens.MultiWalletCryptoCurrenciesSupplier import com.tangem.domain.tokens.model.CurrencyAmount import com.tangem.domain.tokens.model.FeePaidCurrency import com.tangem.domain.tokens.model.warnings.CryptoCurrencyWarning import com.tangem.domain.tokens.model.warnings.HederaWarnings import com.tangem.domain.tokens.model.warnings.KaspaWarnings -import com.tangem.domain.tokens.operations.BaseCurrencyStatusOperations import com.tangem.domain.tokens.repository.CurrenciesRepository import com.tangem.domain.tokens.repository.CurrencyChecksRepository import com.tangem.domain.transaction.models.AssetRequirementsCondition @@ -20,23 +24,22 @@ import com.tangem.lib.crypto.BlockchainUtils import com.tangem.utils.coroutines.CoroutineDispatcherProvider import kotlinx.coroutines.flow.* import java.math.BigDecimal +import javax.inject.Inject -@Suppress("LongParameterList") -class GetCurrencyWarningsUseCase( +@Suppress("LongParameterList", "SuspendFunWithFlowReturnType") +internal class GetCurrencyWarningsUseCase @Inject constructor( private val walletManagersFacade: WalletManagersFacade, private val currenciesRepository: CurrenciesRepository, private val dispatchers: CoroutineDispatcherProvider, private val currencyChecksRepository: CurrencyChecksRepository, - private val currencyStatusOperations: BaseCurrencyStatusOperations, private val multiWalletCryptoCurrenciesSupplier: MultiWalletCryptoCurrenciesSupplier, - + private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier, ) { suspend operator fun invoke( userWalletId: UserWalletId, currencyStatus: CryptoCurrencyStatus, derivationPath: Network.DerivationPath, - isSingleWalletWithTokens: Boolean, ): Flow> { val currency = currencyStatus.currency @@ -44,10 +47,7 @@ class GetCurrencyWarningsUseCase( return combine( flow = getCoinRelatedWarnings( userWalletId = userWalletId, - networkId = currency.network.id, - currencyId = currency.id, - derivationPath = derivationPath, - isSingleWalletWithTokens = isSingleWalletWithTokens, + currency = currency, ), flow2 = flowOf(currencyChecksRepository.getRentInfoWarning(userWalletId, currencyStatus)), flow3 = flowOf(currencyChecksRepository.getExistentialDeposit(userWalletId, currency.network)), @@ -68,44 +68,34 @@ class GetCurrencyWarningsUseCase( }.flowOn(dispatchers.io) } - @Suppress("LongParameterList") private suspend fun getCoinRelatedWarnings( userWalletId: UserWalletId, - networkId: Network.ID, - currencyId: CryptoCurrency.ID, - derivationPath: Network.DerivationPath, - isSingleWalletWithTokens: Boolean, + currency: CryptoCurrency, ): Flow> { - val currencyFlow = currencyStatusOperations.getCurrencyStatusFlow( - userWalletId = userWalletId, - currencyId = currencyId, - isSingleWalletWithTokens = isSingleWalletWithTokens, - ) + return singleAccountStatusListSupplier(userWalletId) + .map { accountStatusList -> + val coin = accountStatusList.getCoinStatus(currency).getOrNull() + val token = accountStatusList.getCryptoCurrencyStatus(currency).getOrNull() - val networkFlow = if (isSingleWalletWithTokens) { - currencyStatusOperations.getNetworkCoinForSingleWalletWithTokenFlow(userWalletId, networkId) - } else { - currencyStatusOperations.getNetworkCoinFlow(userWalletId, networkId, derivationPath) - } + coin to token + } + .distinctUntilChanged() + .map { pair -> + val (coinStatus, tokenStatus) = pair - return combine( - currencyFlow.map { it.getOrNull() }, - networkFlow.map { it.getOrNull() }, - ) { tokenStatus, coinStatus -> - when { - tokenStatus != null && coinStatus != null -> { - buildList { - getUsedOutdatedDataWarning(tokenStatus)?.let(::add) + if (tokenStatus != null && coinStatus != null) { + listOfNotNull( + getUsedOutdatedDataWarning(tokenStatus), getFeeWarning( userWalletId = userWalletId, coinStatus = coinStatus, tokenStatus = tokenStatus, - )?.let(::add) - } + ), + ) + } else { + listOf(CryptoCurrencyWarning.SomeNetworksUnreachable) } - else -> listOf(CryptoCurrencyWarning.SomeNetworksUnreachable) } - } } private suspend fun getFeeWarning( @@ -161,10 +151,10 @@ class GetCurrencyWarningsUseCase( ) .orEmpty() - val token = tokens.find { - it is CryptoCurrency.Token && - it.contractAddress.equals(feePaidToken.contractAddress, ignoreCase = true) && - it.network.derivationPath == tokenStatus.currency.network.derivationPath + val token = tokens.find { currency -> + currency is CryptoCurrency.Token && + currency.contractAddress.equals(feePaidToken.contractAddress, ignoreCase = true) && + currency.network.derivationPath == tokenStatus.currency.network.derivationPath } return if (token != null) { @@ -193,12 +183,12 @@ class GetCurrencyWarningsUseCase( } private fun getNetworkNoAccountWarning(currencyStatus: CryptoCurrencyStatus): CryptoCurrencyWarning? { - return (currencyStatus.value as? CryptoCurrencyStatus.NoAccount)?.let { + return (currencyStatus.value as? CryptoCurrencyStatus.NoAccount)?.let { noAccountStatus -> if (isNeedToCreateAccountWithoutReserve(networkId = currencyStatus.currency.network.rawId)) { CryptoCurrencyWarning.TopUpWithoutReserve } else { CryptoCurrencyWarning.SomeNetworksNoAccount( - amountToCreateAccount = it.amountToCreateAccount, + amountToCreateAccount = noAccountStatus.amountToCreateAccount, amountCurrency = currencyStatus.currency, ) } diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/model/TokenDetailsModel.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/model/TokenDetailsModel.kt index 2f8b9f76ed..d897836afb 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/model/TokenDetailsModel.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/model/TokenDetailsModel.kt @@ -38,7 +38,6 @@ import com.tangem.domain.account.status.usecase.ManageCryptoCurrenciesUseCase import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.balancehiding.GetBalanceHidingSettingsUseCase -import com.tangem.domain.card.common.util.cardTypesResolver import com.tangem.domain.demo.IsDemoCardUseCase import com.tangem.domain.models.StatusSource import com.tangem.domain.models.TokenReceiveNotification @@ -79,6 +78,7 @@ import com.tangem.domain.wallets.usecase.NetworkHasDerivationUseCase import com.tangem.domain.yield.supply.models.YieldSupplyRewardBalance import com.tangem.domain.yield.supply.usecase.YieldSupplyGetRewardsBalanceUseCase import com.tangem.feature.tokendetails.deeplink.TokenDetailsDeepLinkActionListener +import com.tangem.feature.tokendetails.domain.GetCurrencyWarningsUseCase import com.tangem.feature.tokendetails.presentation.router.InnerTokenDetailsRouter import com.tangem.feature.tokendetails.presentation.tokendetails.analytics.TokenDetailsCurrencyStatusAnalyticsSender import com.tangem.feature.tokendetails.presentation.tokendetails.analytics.TokenDetailsNotificationsAnalyticsSender @@ -326,12 +326,10 @@ internal class TokenDetailsModel @Inject constructor( private fun updateWarnings(cryptoCurrencyStatus: CryptoCurrencyStatus) { modelScope.launch(dispatchers.main) { - getCurrencyWarningsUseCase.invoke( + getCurrencyWarningsUseCase( userWalletId = userWalletId, currencyStatus = cryptoCurrencyStatus, derivationPath = cryptoCurrency.network.derivationPath, - isSingleWalletWithTokens = userWallet is UserWallet.Cold && - userWallet.scanResponse.cardTypesResolver.isSingleWalletWithToken(), ) .distinctUntilChanged() .onEach { warnings ->