Updated on 2026-08-14
This commit is contained in:
parent
c7fddb24a0
commit
504d0276f9
3 changed files with 11 additions and 11 deletions
|
|
@ -1,5 +1,6 @@
|
|||
package com.tangem.domain.tokens
|
||||
|
||||
import com.tangem.domain.common.util.cardTypesResolver
|
||||
import com.tangem.domain.exchange.RampStateManager
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
||||
|
|
@ -9,6 +10,7 @@ import com.tangem.domain.tokens.repository.CurrenciesRepository
|
|||
import com.tangem.domain.tokens.repository.MarketCryptoCurrencyRepository
|
||||
import com.tangem.domain.tokens.repository.NetworksRepository
|
||||
import com.tangem.domain.tokens.repository.QuotesRepository
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import com.tangem.utils.isNullOrZero
|
||||
|
|
@ -31,25 +33,26 @@ class GetCryptoCurrencyActionsUseCase(
|
|||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
suspend operator fun invoke(
|
||||
userWalletId: UserWalletId,
|
||||
userWallet: UserWallet,
|
||||
cryptoCurrencyStatus: CryptoCurrencyStatus,
|
||||
isSingleWalletWithTokens: Boolean,
|
||||
): Flow<TokenActionsState> {
|
||||
val operations = CurrenciesStatusesOperations(
|
||||
currenciesRepository = currenciesRepository,
|
||||
quotesRepository = quotesRepository,
|
||||
networksRepository = networksRepository,
|
||||
userWalletId = userWalletId,
|
||||
userWalletId = userWallet.walletId,
|
||||
)
|
||||
val networkId = cryptoCurrencyStatus.currency.network.id
|
||||
val networkFlow = if (isSingleWalletWithTokens) {
|
||||
val networkFlow = if (userWallet.scanResponse.cardTypesResolver.isSingleWalletWithToken()) {
|
||||
operations.getNetworkCoinForSingleWalletWithTokenFlow(networkId)
|
||||
} else if (!userWallet.isMultiCurrency) {
|
||||
operations.getPrimaryCurrencyStatusFlow()
|
||||
} else {
|
||||
operations.getNetworkCoinFlow(networkId, cryptoCurrencyStatus.currency.network.derivationPath)
|
||||
}
|
||||
return networkFlow.mapLatest { maybeCoinStatus ->
|
||||
createTokenActionsState(
|
||||
userWalletId = userWalletId,
|
||||
userWalletId = userWallet.walletId,
|
||||
coinStatus = maybeCoinStatus.getOrNull(),
|
||||
cryptoCurrencyStatus = cryptoCurrencyStatus,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -135,9 +135,8 @@ internal class TokenDetailsViewModel @Inject constructor(
|
|||
private suspend fun updateButtons(userWalletId: UserWalletId, currencyStatus: CryptoCurrencyStatus) {
|
||||
val userWallet = getUserWalletUseCase(userWalletId).getOrElse { return }
|
||||
getCryptoCurrencyActionsUseCase(
|
||||
userWalletId = userWallet.walletId,
|
||||
userWallet = userWallet,
|
||||
cryptoCurrencyStatus = currencyStatus,
|
||||
isSingleWalletWithTokens = userWallet.scanResponse.cardTypesResolver.isSingleWalletWithToken(),
|
||||
)
|
||||
.conflate()
|
||||
.distinctUntilChanged()
|
||||
|
|
|
|||
|
|
@ -920,9 +920,8 @@ internal class WalletViewModel @Inject constructor(
|
|||
val userWallet = getSelectedWallet()
|
||||
viewModelScope.launch(dispatchers.io) {
|
||||
getCryptoCurrencyActionsUseCase(
|
||||
userWalletId = userWallet.walletId,
|
||||
userWallet = userWallet,
|
||||
cryptoCurrencyStatus = cryptoCurrencyStatus,
|
||||
isSingleWalletWithTokens = userWallet.scanResponse.cardTypesResolver.isSingleWalletWithToken(),
|
||||
)
|
||||
.take(count = 1)
|
||||
.collectLatest {
|
||||
|
|
@ -1302,9 +1301,8 @@ internal class WalletViewModel @Inject constructor(
|
|||
|
||||
private suspend fun updateButtons(userWallet: UserWallet, currencyStatus: CryptoCurrencyStatus) {
|
||||
getCryptoCurrencyActionsUseCase(
|
||||
userWalletId = userWallet.walletId,
|
||||
userWallet = userWallet,
|
||||
cryptoCurrencyStatus = currencyStatus,
|
||||
isSingleWalletWithTokens = userWallet.scanResponse.cardTypesResolver.isSingleWalletWithToken(),
|
||||
)
|
||||
.conflate()
|
||||
.distinctUntilChanged()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue