Updated on 2026-08-14

This commit is contained in:
Tangem 2024-08-15 12:44:44 +04:00
parent 605f17c873
commit 517a9609ec
5 changed files with 44 additions and 0 deletions

View file

@ -413,4 +413,10 @@ internal object TokensDomainModule {
quotesRepository = quotesRepository,
)
}
@Provides
@Singleton
fun provideCheckHasLinkedTokensUseCase(currenciesRepository: CurrenciesRepository): CheckHasLinkedTokensUseCase {
return CheckHasLinkedTokensUseCase(currenciesRepository)
}
}

View file

@ -454,6 +454,21 @@ internal class DefaultCurrenciesRepository(
) ?: error("Unable to create token")
}
override suspend fun hasTokens(userWalletId: UserWalletId, network: Network): Boolean {
val userWallet = getUserWallet(userWalletId)
fetchTokensIfCacheExpired(userWallet, refresh = false)
val storedTokens = requireNotNull(userTokensStore.getSyncOrNull(userWallet.walletId)) {
"Unable to find tokens response for user wallet with provided ID: $userWalletId"
}
return storedTokens.tokens.any {
it.contractAddress != null &&
it.networkId == network.backendId &&
it.derivationPath == network.derivationPath.value
}
}
private fun getMultiCurrencyWalletCurrencies(userWallet: UserWallet): Flow<List<CryptoCurrency>> {
return userTokensStore.get(userWallet.walletId).map { storedTokens ->
responseCurrenciesFactory.createCurrencies(

View file

@ -0,0 +1,17 @@
package com.tangem.domain.tokens
import arrow.core.Either
import com.tangem.domain.tokens.model.Network
import com.tangem.domain.tokens.repository.CurrenciesRepository
import com.tangem.domain.wallets.models.UserWalletId
class CheckHasLinkedTokensUseCase(
private val currenciesRepository: CurrenciesRepository,
) {
suspend operator fun invoke(userWalletId: UserWalletId, network: Network): Either<Throwable, Boolean> {
return Either.catch {
currenciesRepository.hasTokens(userWalletId, network)
}
}
}

View file

@ -223,4 +223,6 @@ interface CurrenciesRepository {
contractAddress: String,
networkId: String,
): CryptoCurrency.Token
suspend fun hasTokens(userWalletId: UserWalletId, network: Network): Boolean
}

View file

@ -144,4 +144,8 @@ internal class MockCurrenciesRepository(
): CryptoCurrency.Token {
error("not implemented")
}
override suspend fun hasTokens(userWalletId: UserWalletId, network: Network): Boolean {
return false
}
}