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 343d1e9a8e..0de9b7f3a1 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 @@ -319,12 +319,6 @@ internal object TokensDomainModule { return GetMissedAddressesCryptoCurrenciesUseCase(currenciesRepository = currenciesRepository) } - @Provides - @Singleton - fun provideGetGlobalTokenListUseCase(tokensListRepository: TokensListRepository): GetGlobalTokenListUseCase { - return GetGlobalTokenListUseCase(repository = tokensListRepository) - } - @Provides @Singleton fun provideCheckTokenCompatibilityUseCase( @@ -341,22 +335,6 @@ internal object TokensDomainModule { return RequiresHardenedDerivationOnlyUseCase(networksCompatibilityRepository) } - @Provides - @Singleton - fun provideFindTokenByContractAddressUseCase( - tokensListRepository: TokensListRepository, - ): FindTokenByContractAddressUseCase { - return FindTokenByContractAddressUseCase(repository = tokensListRepository) - } - - @Provides - @Singleton - fun provideValidateContractAddressUseCase( - tokensListRepository: TokensListRepository, - ): ValidateContractAddressUseCase { - return ValidateContractAddressUseCase(tokensListRepository = tokensListRepository) - } - @Provides @Singleton fun provideAreTokensSupportedByNetworkUseCase( diff --git a/data/tokens/src/main/kotlin/com/tangem/data/tokens/di/TokensDataModule.kt b/data/tokens/src/main/kotlin/com/tangem/data/tokens/di/TokensDataModule.kt index c37a3bc87f..d363d4b94a 100644 --- a/data/tokens/src/main/kotlin/com/tangem/data/tokens/di/TokensDataModule.kt +++ b/data/tokens/src/main/kotlin/com/tangem/data/tokens/di/TokensDataModule.kt @@ -93,20 +93,6 @@ internal object TokensDataModule { return DefaultMarketCryptoCurrencyRepository(expressAssetsStore, coroutineDispatcherProvider) } - @Provides - @Singleton - fun providesTokensListRepository( - tangemTechApi: TangemTechApi, - dispatchers: CoroutineDispatcherProvider, - quotesRepository: QuotesRepository, - ): TokensListRepository { - return DefaultTokensListRepository( - tangemTechApi = tangemTechApi, - dispatchers = dispatchers, - quotesRepository = quotesRepository, - ) - } - @Provides @Singleton fun provideCardNetworksRepository( diff --git a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultTokensListRepository.kt b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultTokensListRepository.kt deleted file mode 100644 index a10187713a..0000000000 --- a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultTokensListRepository.kt +++ /dev/null @@ -1,79 +0,0 @@ -package com.tangem.data.tokens.repository - -import androidx.paging.Pager -import androidx.paging.PagingConfig -import androidx.paging.PagingData -import com.tangem.blockchain.common.Blockchain -import com.tangem.blockchainsdk.utils.fromNetworkId -import com.tangem.data.tokens.paging.CoinsPagingSource -import com.tangem.data.tokens.utils.FoundTokenConverter -import com.tangem.datasource.api.common.response.getOrThrow -import com.tangem.datasource.api.tangemTech.TangemTechApi -import com.tangem.domain.tokens.model.FoundToken -import com.tangem.domain.tokens.model.Token -import com.tangem.domain.tokens.repository.QuotesRepository -import com.tangem.domain.tokens.repository.TokensListRepository -import com.tangem.utils.coroutines.CoroutineDispatcherProvider -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.withContext - -/** - * Default repository implementation for managing operations related to a complete set of tokens - * - * @property tangemTechApi Tangem Tech API - * @property dispatchers coroutine dispatchers provider - * @property quotesRepository responsible for providing cryptocurrency quotes data - * - */ -internal class DefaultTokensListRepository( - private val tangemTechApi: TangemTechApi, - private val dispatchers: CoroutineDispatcherProvider, - private val quotesRepository: QuotesRepository, -) : TokensListRepository { - - override fun getTokens(searchText: String?): Flow> { - return Pager( - config = PagingConfig( - pageSize = 100, - prefetchDistance = 70, - enablePlaceholders = false, - ), - pagingSourceFactory = { - CoinsPagingSource( - api = tangemTechApi, - dispatchers = dispatchers, - searchText = searchText, - quotesRepository = quotesRepository, - ) - }, - ).flow - } - - override suspend fun findToken(contractAddress: String, networkId: String): FoundToken? { - return withContext(dispatchers.io) { - val foundCoin = tangemTechApi.getCoins( - contractAddress = contractAddress, - networkIds = networkId, - ).getOrThrow().coins.firstNotNullOfOrNull { coin -> - val tokenNetwork = coin.networks.filter { network -> - network.contractAddress != null && network.decimalCount != null && - network.contractAddress?.equals(contractAddress, ignoreCase = true) == true && - networkId == network.networkId - } - if (tokenNetwork.isNotEmpty()) { - coin.copy(networks = tokenNetwork) - } else { - null - } - } - foundCoin?.let { FoundTokenConverter.convert(foundCoin) } - } - } - - override fun validateAddress(contractAddress: String, networkId: String): Boolean { - return when (val blockchain = Blockchain.fromNetworkId(networkId) ?: Blockchain.Unknown) { - Blockchain.Unknown, Blockchain.Binance, Blockchain.BinanceTestnet -> true - else -> blockchain.validateAddress(contractAddress) - } - } -} \ No newline at end of file diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/FindTokenByContractAddressUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/FindTokenByContractAddressUseCase.kt deleted file mode 100644 index 809e8ca270..0000000000 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/FindTokenByContractAddressUseCase.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.tangem.domain.tokens - -import arrow.core.Either -import arrow.core.raise.catch -import arrow.core.raise.either -import com.tangem.domain.tokens.model.FoundToken -import com.tangem.domain.tokens.repository.TokensListRepository - -class FindTokenByContractAddressUseCase(private val repository: TokensListRepository) { - suspend operator fun invoke(contractAddress: String, networkId: String): Either { - return either { - catch( - block = { repository.findToken(contractAddress, networkId) }, - catch = { throwable -> raise(throwable) }, - ) - } - } -} \ No newline at end of file diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetGlobalTokenListUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetGlobalTokenListUseCase.kt deleted file mode 100644 index 74ddd5b4e4..0000000000 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetGlobalTokenListUseCase.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.tangem.domain.tokens - -import androidx.paging.PagingData -import com.tangem.domain.tokens.model.Token -import com.tangem.domain.tokens.repository.TokensListRepository -import kotlinx.coroutines.flow.Flow - -/** - * Use case for retrieving a complete set of tokens with their quotes (filtered by a search text if provided). - * - * @property repository The repository responsible for fetching and preparing the list of tokens with their quotes. - */ -class GetGlobalTokenListUseCase(private val repository: TokensListRepository) { - - /** - * @param searchText The text used for filtering the list of tokens (not required). - * @return A [Flow] emitting [PagingData] containing the tokens with their quotes. - */ - operator fun invoke(searchText: String?): Flow> { - return repository.getTokens(searchText = searchText?.ifBlank(defaultValue = { null })) - } -} \ No newline at end of file diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/ValidateContractAddressUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/ValidateContractAddressUseCase.kt deleted file mode 100644 index a2c2d2c1b4..0000000000 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/ValidateContractAddressUseCase.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.tangem.domain.tokens - -import arrow.core.Either -import arrow.core.raise.catch -import arrow.core.raise.either -import com.tangem.domain.tokens.error.AddCustomTokenError -import com.tangem.domain.tokens.repository.TokensListRepository - -class ValidateContractAddressUseCase( - private val tokensListRepository: TokensListRepository, -) { - operator fun invoke(address: String, networkId: String): Either { - return either { - catch( - block = { - if (address.isEmpty()) raise(AddCustomTokenError.FIELD_IS_EMPTY) - - if (!tokensListRepository.validateAddress( - contractAddress = address, - networkId = networkId, - ) - ) { - raise(AddCustomTokenError.INVALID_CONTRACT_ADDRESS) - } - }, - catch = { - AddCustomTokenError.INVALID_CONTRACT_ADDRESS - }, - ) - } - } -} \ No newline at end of file diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/TokensListRepository.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/TokensListRepository.kt deleted file mode 100644 index 24d0605cda..0000000000 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/TokensListRepository.kt +++ /dev/null @@ -1,43 +0,0 @@ -package com.tangem.domain.tokens.repository - -import androidx.paging.PagingData -import com.tangem.domain.tokens.model.FoundToken -import com.tangem.domain.tokens.model.Token -import kotlinx.coroutines.flow.Flow - -/** - * Repository interface for managing operations related to a complete set of tokens - * (not associated with any specific card). - * */ -interface TokensListRepository { - - /** - * Retrieves a list of available tokens with quotes, can be filtered based on the provided search text. - * - * @param searchText The search text used to filter tokens. - * @return A [Flow] emitting [PagingData] containing the tokens with quotes matching the search criteria. - * @throws com.tangem.datasource.api.common.response.ApiResponseError - */ - fun getTokens(searchText: String?): Flow> - - /** - * Retrieves a token information with the specified contract address on the provided network. - * - * @param contractAddress contract address of the token - * @param networkId network of the token - * @return [FoundToken] object containing token information or null if no token is found with the provided - * contract address - */ - @Throws - suspend fun findToken(contractAddress: String, networkId: String): FoundToken? - - /** - * Validates a contract address on a particular network. - * - * @param contractAddress contract address of the token - * @param networkId network of the token - * @return [Boolean] true is address is valid (possible on the network), false if its format is not - * supported on the network - */ - fun validateAddress(contractAddress: String, networkId: String): Boolean -} \ No newline at end of file