Updated on 2026-08-14
This commit is contained in:
parent
519e59d96b
commit
fdee74fbf0
8 changed files with 301 additions and 89 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -218,7 +218,27 @@ internal object AccountCryptoCurrencyStatusFinder {
|
|||
return AccountCryptoCurrencyStatus(account = accountCurrency.account, status = currencyStatus)
|
||||
}
|
||||
|
||||
private fun AccountStatusList.getExpectedAccountStatuses(networks: List<Network>): List<AccountStatus> {
|
||||
internal fun AccountStatusList.getExpectedAccountStatuses(networkId: Network.ID): List<AccountStatus> {
|
||||
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<Network>): List<AccountStatus> {
|
||||
val possibleAccountIndexes = networks.mapNotNull { getAccountIndexOrNull(it.rawId, it.derivationPath) }
|
||||
|
||||
if (possibleAccountIndexes.isEmpty()) return accountStatuses
|
||||
|
|
|
|||
|
|
@ -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<CryptoCurrencyStatus> {
|
||||
return getCoinStatus(network = currency.network)
|
||||
}
|
||||
|
||||
fun AccountStatusList.getCoinStatus(network: Network): Option<CryptoCurrencyStatus> {
|
||||
return getCoinStatus(networkId = network.id)
|
||||
}
|
||||
|
||||
fun AccountStatusList.getCoinStatus(networkId: Network.ID): Option<CryptoCurrencyStatus> {
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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<CryptoCurrency>,
|
||||
currencyStatuses: List<CryptoCurrencyStatus> = emptyList(),
|
||||
|
|
|
|||
|
|
@ -11,8 +11,6 @@
|
|||
<ID>MultilineLambdaItParameter:FetchCurrencyStatusUseCase.kt$FetchCurrencyStatusUseCase${ when (it) { is StakingIdFactory.Error.UnableToGetAddress -> raise(IllegalStateException("$it")) StakingIdFactory.Error.UnsupportedCurrency -> Unit.right() } return@either }</ID>
|
||||
<ID>MultilineLambdaItParameter:GetBalanceNotEnoughForFeeWarningUseCase.kt$GetBalanceNotEnoughForFeeWarningUseCase${ it is CryptoCurrency.Token && it.contractAddress.equals(feePaidToken.contractAddress, ignoreCase = true) && it.network.derivationPath == tokenStatus.currency.network.derivationPath }</ID>
|
||||
<ID>MultilineLambdaItParameter:GetCryptoCurrencyActionsUseCase.kt$GetCryptoCurrencyActionsUseCase${ TokenActionsState( walletId = userWallet.walletId, cryptoCurrencyStatus = cryptoCurrencyStatus, states = it.toList(), ) }</ID>
|
||||
<ID>MultilineLambdaItParameter:GetCurrencyWarningsUseCase.kt$GetCurrencyWarningsUseCase${ if (isNeedToCreateAccountWithoutReserve(networkId = currencyStatus.currency.network.rawId)) { CryptoCurrencyWarning.TopUpWithoutReserve } else { CryptoCurrencyWarning.SomeNetworksNoAccount( amountToCreateAccount = it.amountToCreateAccount, amountCurrency = currencyStatus.currency, ) } }</ID>
|
||||
<ID>MultilineLambdaItParameter:GetCurrencyWarningsUseCase.kt$GetCurrencyWarningsUseCase${ it is CryptoCurrency.Token && it.contractAddress.equals(feePaidToken.contractAddress, ignoreCase = true) && it.network.derivationPath == tokenStatus.currency.network.derivationPath }</ID>
|
||||
<ID>MultilineLambdaItParameter:GetWalletTotalBalanceUseCase.kt$GetWalletTotalBalanceUseCase${ Timber.e("failed to load balances with error: $it") TotalFiatBalance.Failed }</ID>
|
||||
<ID>MultilineLambdaItParameter:PriceChangeCalculator.kt$PriceChangeCalculator${ val weight = it.value.fiatAmount.orZero().divide(balance, 2, RoundingMode.HALF_UP) val priceChange = it.value.priceChange.orZero() weight * priceChange }</ID>
|
||||
<ID>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 }</ID>
|
||||
|
|
@ -20,7 +18,6 @@
|
|||
<ID>NoNameShadowing:WalletBalanceFetcher.kt$WalletBalanceFetcher${ it is StakingIdFactory.Error.UnableToGetAddress }</ID>
|
||||
<ID>NullableBooleanCheck:GetCurrencyCheckUseCase.kt$GetCurrencyCheckUseCase$recipientAddress?.let { currencyChecksRepository.checkIfAccountFunded( userWalletId, network, recipientAddress, ) } ?: false</ID>
|
||||
<ID>SuspendFunWithFlowReturnType:BaseCurrencyStatusOperations.kt$BaseCurrencyStatusOperations$suspend</ID>
|
||||
<ID>SuspendFunWithFlowReturnType:GetCurrencyWarningsUseCase.kt$GetCurrencyWarningsUseCase$suspend</ID>
|
||||
<ID>SuspendFunWithFlowReturnType:GetNetworkCoinStatusUseCase.kt$GetNetworkCoinStatusUseCase$suspend</ID>
|
||||
<ID>SuspendFunWithFlowReturnType:GetSingleCryptoCurrencyStatusUseCase.kt$GetSingleCryptoCurrencyStatusUseCase$suspend</ID>
|
||||
<ID>UnnecessaryAbstractClass:MultiWalletCryptoCurrenciesSupplier.kt$MultiWalletCryptoCurrenciesSupplier$MultiWalletCryptoCurrenciesSupplier</ID>
|
||||
|
|
|
|||
|
|
@ -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<TokenListError, List<CryptoCurrencyStatus>>
|
||||
}
|
||||
|
|
@ -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<Set<CryptoCurrencyWarning>> {
|
||||
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<List<CryptoCurrencyWarning>> {
|
||||
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,
|
||||
)
|
||||
}
|
||||
|
|
@ -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 ->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue