Updated on 2026-08-14
This commit is contained in:
parent
3b5b923cc2
commit
ce682d72bb
7 changed files with 0 additions and 230 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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<PagingData<Token>> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<Throwable, FoundToken?> {
|
||||
return either {
|
||||
catch(
|
||||
block = { repository.findToken(contractAddress, networkId) },
|
||||
catch = { throwable -> raise(throwable) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<PagingData<Token>> {
|
||||
return repository.getTokens(searchText = searchText?.ifBlank(defaultValue = { 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<AddCustomTokenError, Unit> {
|
||||
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
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<PagingData<Token>>
|
||||
|
||||
/**
|
||||
* 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue