Updated on 2026-08-14

This commit is contained in:
Tangem 2025-10-30 18:55:17 +01:00
parent 79ef677303
commit 8c5711166f
4 changed files with 45 additions and 12 deletions

View file

@ -1,6 +1,5 @@
package com.tangem.tap.di.domain
import com.tangem.domain.wallets.derivations.DerivationsRepository
import com.tangem.domain.managetokens.*
import com.tangem.domain.managetokens.repository.CustomTokensRepository
import com.tangem.domain.managetokens.repository.ManageTokensRepository
@ -10,11 +9,14 @@ import com.tangem.domain.staking.StakingIdFactory
import com.tangem.domain.staking.multi.MultiYieldBalanceFetcher
import com.tangem.domain.tokens.repository.CurrenciesRepository
import com.tangem.domain.walletmanager.WalletManagersFacade
import com.tangem.domain.wallets.derivations.DerivationsRepository
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import javax.inject.Singleton
@Module
@ -74,6 +76,7 @@ internal object ManageTokensDomainModule {
multiQuoteStatusFetcher: MultiQuoteStatusFetcher,
multiYieldBalanceFetcher: MultiYieldBalanceFetcher,
stakingIdFactory: StakingIdFactory,
dispatchers: CoroutineDispatcherProvider,
): SaveManagedTokensUseCase {
return SaveManagedTokensUseCase(
customTokensRepository = customTokensRepository,
@ -84,6 +87,7 @@ internal object ManageTokensDomainModule {
multiQuoteStatusFetcher = multiQuoteStatusFetcher,
multiYieldBalanceFetcher = multiYieldBalanceFetcher,
stakingIdFactory = stakingIdFactory,
parallelUpdatingScope = CoroutineScope(SupervisorJob() + dispatchers.default),
)
}

View file

@ -15,10 +15,13 @@ import com.tangem.domain.tokens.repository.CurrenciesRepository
import com.tangem.domain.wallets.derivations.DerivationsRepository
import com.tangem.domain.wallets.legacy.UserWalletsListManager
import com.tangem.features.hotwallet.HotWalletFeatureToggles
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import javax.inject.Singleton
@Module
@ -67,6 +70,7 @@ object MarketsDomainModule {
multiQuoteStatusFetcher: MultiQuoteStatusFetcher,
multiYieldBalanceFetcher: MultiYieldBalanceFetcher,
stakingIdFactory: StakingIdFactory,
dispatchers: CoroutineDispatcherProvider,
): SaveMarketTokensUseCase {
return SaveMarketTokensUseCase(
derivationsRepository = derivationsRepository,
@ -76,6 +80,7 @@ object MarketsDomainModule {
multiQuoteStatusFetcher = multiQuoteStatusFetcher,
multiYieldBalanceFetcher = multiYieldBalanceFetcher,
stakingIdFactory = stakingIdFactory,
parallelUpdatingScope = CoroutineScope(SupervisorJob() + dispatchers.default),
)
}

View file

@ -14,6 +14,10 @@ import com.tangem.domain.staking.multi.MultiYieldBalanceFetcher
import com.tangem.domain.tokens.repository.CurrenciesRepository
import com.tangem.domain.walletmanager.WalletManagersFacade
import com.tangem.domain.wallets.derivations.DerivationsRepository
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@Suppress("LongParameterList")
class SaveManagedTokensUseCase(
@ -25,6 +29,7 @@ class SaveManagedTokensUseCase(
private val multiQuoteStatusFetcher: MultiQuoteStatusFetcher,
private val multiYieldBalanceFetcher: MultiYieldBalanceFetcher,
private val stakingIdFactory: StakingIdFactory,
private val parallelUpdatingScope: CoroutineScope,
) {
suspend operator fun invoke(
@ -53,11 +58,23 @@ class SaveManagedTokensUseCase(
currencies = addingCurrencies,
)
refreshUpdatedNetworks(userWalletId = userWalletId, addedCurrencies = savedCurrencies)
refreshUpdatedYieldBalances(userWalletId = userWalletId, addedCurrencies = savedCurrencies)
refreshUpdatedQuotes(addedCurrencies = savedCurrencies)
parallelUpdatingScope.launch {
withContext(NonCancellable) {
launch {
refreshUpdatedNetworks(
userWalletId = userWalletId,
addedCurrencies = savedCurrencies,
)
}
launch {
refreshUpdatedYieldBalances(
userWalletId = userWalletId,
addedCurrencies = savedCurrencies,
)
}
launch { refreshUpdatedQuotes(addedCurrencies = savedCurrencies) }
}
}
}
}

View file

@ -1,7 +1,6 @@
package com.tangem.domain.markets
import arrow.core.Either
import com.tangem.domain.wallets.derivations.DerivationsRepository
import com.tangem.domain.markets.repositories.MarketsTokenRepository
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.network.Network
@ -11,6 +10,11 @@ import com.tangem.domain.quotes.multi.MultiQuoteStatusFetcher
import com.tangem.domain.staking.StakingIdFactory
import com.tangem.domain.staking.multi.MultiYieldBalanceFetcher
import com.tangem.domain.tokens.repository.CurrenciesRepository
import com.tangem.domain.wallets.derivations.DerivationsRepository
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
/**
* Use case for saving tokens from Markets
@ -30,6 +34,7 @@ class SaveMarketTokensUseCase(
private val multiQuoteStatusFetcher: MultiQuoteStatusFetcher,
private val multiYieldBalanceFetcher: MultiYieldBalanceFetcher,
private val stakingIdFactory: StakingIdFactory,
private val parallelUpdatingScope: CoroutineScope,
) {
suspend operator fun invoke(
@ -69,11 +74,13 @@ class SaveMarketTokensUseCase(
currencies = addedCurrencies,
)
refreshUpdatedNetworks(userWalletId, savedCurrencies)
refreshUpdatedYieldBalances(userWalletId, savedCurrencies)
refreshUpdatedQuotes(savedCurrencies)
parallelUpdatingScope.launch {
withContext(NonCancellable) {
launch { refreshUpdatedNetworks(userWalletId, savedCurrencies) }
launch { refreshUpdatedYieldBalances(userWalletId, savedCurrencies) }
launch { refreshUpdatedQuotes(savedCurrencies) }
}
}
}
}