diff --git a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt index cc7c128143..ca0202ae25 100644 --- a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt +++ b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt @@ -215,8 +215,6 @@ internal class DefaultCurrenciesRepository( override suspend fun getMultiCurrencyWalletCurrency( userWalletId: UserWalletId, id: CryptoCurrency.ID, - contractAddress: String?, - derivationPath: Network.DerivationPath, ): CryptoCurrency = withContext(dispatchers.io) { val userWallet = getUserWallet(userWalletId) ensureIsCorrectUserWallet(userWallet, isMultiCurrencyWalletExpected = true) @@ -227,10 +225,8 @@ internal class DefaultCurrenciesRepository( responseCurrenciesFactory.createCurrency( currencyId = id, - contractAddress = contractAddress, response = response, scanResponse = userWallet.scanResponse, - derivationPath = derivationPath.value, ) } diff --git a/data/tokens/src/main/kotlin/com/tangem/data/tokens/utils/ResponseCryptoCurrenciesFactory.kt b/data/tokens/src/main/kotlin/com/tangem/data/tokens/utils/ResponseCryptoCurrenciesFactory.kt index 1f10b3cdf5..ef55915ce2 100644 --- a/data/tokens/src/main/kotlin/com/tangem/data/tokens/utils/ResponseCryptoCurrenciesFactory.kt +++ b/data/tokens/src/main/kotlin/com/tangem/data/tokens/utils/ResponseCryptoCurrenciesFactory.kt @@ -4,10 +4,9 @@ import com.tangem.blockchain.common.Blockchain import com.tangem.blockchain.common.Token import com.tangem.datasource.api.tangemTech.models.UserTokensResponse import com.tangem.domain.common.DerivationStyleProvider -import com.tangem.domain.common.TapWorkarounds.isTestCard import com.tangem.domain.common.extensions.fromNetworkId import com.tangem.domain.common.extensions.toCoinId -import com.tangem.domain.common.extensions.toNetworkId +import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.common.util.derivationStyleProvider import com.tangem.domain.models.scan.ScanResponse import com.tangem.domain.tokens.model.CryptoCurrency @@ -18,26 +17,13 @@ internal class ResponseCryptoCurrenciesFactory { fun createCurrency( currencyId: CryptoCurrency.ID, - contractAddress: String?, response: UserTokensResponse, scanResponse: ScanResponse, - derivationPath: String?, ): CryptoCurrency { - val responseTokenId = currencyId.rawCurrencyId - val networkId = Blockchain.fromId(currencyId.rawNetworkId).toNetworkId() - - val token = requireNotNull( - value = response.tokens - .find { - it.id == responseTokenId && it.networkId == networkId && it.derivationPath == derivationPath && - it.contractAddress == contractAddress - }, - lazyMessage = { "Unable find a token with provided TokenID($responseTokenId) and NetworkID($networkId)" }, - ) - - return requireNotNull(createCurrency(token, scanResponse)) { - "Unable to create a currency with provided ID: $currencyId" - } + return response.tokens + .asSequence() + .mapNotNull { createCurrency(it, scanResponse) } + .first { it.id == currencyId } } fun createCurrencies(response: UserTokensResponse, scanResponse: ScanResponse): List { @@ -56,9 +42,8 @@ internal class ResponseCryptoCurrenciesFactory { } val cardDerivationStyleProvider = scanResponse.derivationStyleProvider - val card = scanResponse.card - if (card.isTestCard) { + if (scanResponse.cardTypesResolver.isTestCard()) { blockchain = blockchain.getTestnetVersion() ?: blockchain } diff --git a/domain/legacy/src/main/java/com/tangem/domain/walletmanager/utils/UpdateWalletManagerResultFactory.kt b/domain/legacy/src/main/java/com/tangem/domain/walletmanager/utils/UpdateWalletManagerResultFactory.kt index 8e9babd7f2..1e9c032f6c 100644 --- a/domain/legacy/src/main/java/com/tangem/domain/walletmanager/utils/UpdateWalletManagerResultFactory.kt +++ b/domain/legacy/src/main/java/com/tangem/domain/walletmanager/utils/UpdateWalletManagerResultFactory.kt @@ -57,9 +57,7 @@ internal class UpdateWalletManagerResultFactory { } private fun getTokensAmounts(amounts: Set): Set { - val mutableAmounts = hashSetOf() - - return amounts.mapNotNullTo(mutableAmounts, ::createCurrencyAmount) + return amounts.mapNotNullTo(hashSetOf(), ::createCurrencyAmount) } private fun getDemoTokensAmounts(demoAmount: Amount, tokens: Set): Set { diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/FetchCurrencyStatusUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/FetchCurrencyStatusUseCase.kt index b392da6d64..8fbd29d4f5 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/FetchCurrencyStatusUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/FetchCurrencyStatusUseCase.kt @@ -36,20 +36,16 @@ class FetchCurrencyStatusUseCase( * * @param userWalletId The ID of the user's wallet. * @param id The ID of the cryptocurrency. - * @param contractAddress The contract address of the crypto currency - * @param derivationPath currency derivation path. * @param refresh Indicates whether to force a refresh of the status data. * @return An [Either] representing success (Right) or an error (Left) in fetching the status. */ suspend operator fun invoke( userWalletId: UserWalletId, id: CryptoCurrency.ID, - contractAddress: String?, - derivationPath: Network.DerivationPath, refresh: Boolean = false, ): Either { return either { - val currency = getCurrency(userWalletId, id, contractAddress, derivationPath) + val currency = getCurrency(userWalletId, id) fetchCurrencyStatus(userWalletId, currency, refresh) } @@ -91,17 +87,10 @@ class FetchCurrencyStatusUseCase( private suspend fun Raise.getCurrency( userWalletId: UserWalletId, id: CryptoCurrency.ID, - contractAddress: String?, - derivationPath: Network.DerivationPath, ): CryptoCurrency { return catch( block = { - currenciesRepository.getMultiCurrencyWalletCurrency( - userWalletId = userWalletId, - id = id, - contractAddress = contractAddress, - derivationPath = derivationPath, - ) + currenciesRepository.getMultiCurrencyWalletCurrency(userWalletId, id) }, ) { raise(CurrencyStatusError.DataError(it)) diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyUseCase.kt index 3959be4879..d0e47c2b62 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyUseCase.kt @@ -6,7 +6,6 @@ import arrow.core.raise.catch import arrow.core.raise.either import com.tangem.domain.tokens.error.CurrencyStatusError import com.tangem.domain.tokens.model.CryptoCurrency -import com.tangem.domain.tokens.model.Network import com.tangem.domain.tokens.repository.CurrenciesRepository import com.tangem.domain.wallets.models.UserWalletId @@ -19,17 +18,13 @@ class GetCryptoCurrencyUseCase( * * @param userWalletId The ID of the user's wallet. * @param id The ID of the cryptocurrency. - * @param contractAddress The contract address of the crypto currency - * @param derivationPath currency derivation path. * @return An [Either] representing success (Right) or an error (Left) in fetching the status. */ suspend operator fun invoke( userWalletId: UserWalletId, id: CryptoCurrency.ID, - contractAddress: String?, - derivationPath: Network.DerivationPath, ): Either { - return either { getCurrency(userWalletId, id, contractAddress, derivationPath) } + return either { getCurrency(userWalletId, id) } } /** @@ -45,17 +40,10 @@ class GetCryptoCurrencyUseCase( private suspend fun Raise.getCurrency( userWalletId: UserWalletId, id: CryptoCurrency.ID, - contractAddress: String?, - derivationPath: Network.DerivationPath, ): CryptoCurrency { return catch( block = { - currenciesRepository.getMultiCurrencyWalletCurrency( - userWalletId, - id, - contractAddress, - derivationPath, - ) + currenciesRepository.getMultiCurrencyWalletCurrency(userWalletId, id) }, catch = { raise(CurrencyStatusError.DataError(it)) }, ) diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyStatusUpdatesUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyStatusUpdatesUseCase.kt index 146a44bc4b..92e660af07 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyStatusUpdatesUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyStatusUpdatesUseCase.kt @@ -5,7 +5,6 @@ import com.tangem.domain.tokens.error.CurrencyStatusError import com.tangem.domain.tokens.error.mapper.mapToCurrencyError import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.model.CryptoCurrencyStatus -import com.tangem.domain.tokens.model.Network import com.tangem.domain.tokens.operations.CurrenciesStatusesOperations import com.tangem.domain.tokens.repository.CurrenciesRepository import com.tangem.domain.tokens.repository.NetworksRepository @@ -33,16 +32,12 @@ class GetCurrencyStatusUpdatesUseCase( * * @param userWalletId The unique identifier of the user's wallet. * @param currencyId The unique identifier of the cryptocurrency. - * @param contractAddress The contract address of the crypto currency - * @param derivationPath currency derivation path. * @param isSingleWalletWithTokens Indicates whether the user wallet contains only one token on card (old cards) * @return A [Flow] emitting either a [CurrencyStatusError] or a [CryptoCurrencyStatus], indicating the result of the fetch operation. */ operator fun invoke( userWalletId: UserWalletId, currencyId: CryptoCurrency.ID, - contractAddress: String?, - derivationPath: Network.DerivationPath, isSingleWalletWithTokens: Boolean, ): Flow> { return flow { @@ -50,8 +45,6 @@ class GetCurrencyStatusUpdatesUseCase( getCurrency( userWalletId = userWalletId, currencyId = currencyId, - contractAddress = contractAddress, - derivationPath = derivationPath, isSingleWalletWithTokens = isSingleWalletWithTokens, ), ) @@ -61,9 +54,7 @@ class GetCurrencyStatusUpdatesUseCase( private suspend fun getCurrency( userWalletId: UserWalletId, currencyId: CryptoCurrency.ID, - derivationPath: Network.DerivationPath, isSingleWalletWithTokens: Boolean, - contractAddress: String?, ): Flow> { val operations = CurrenciesStatusesOperations( currenciesRepository = currenciesRepository, @@ -75,7 +66,7 @@ class GetCurrencyStatusUpdatesUseCase( val currencyFlow = if (isSingleWalletWithTokens) { operations.getCurrencyStatusSingleWalletWithTokensFlow(currencyId) } else { - operations.getCurrencyStatusFlow(currencyId, contractAddress, derivationPath) + operations.getCurrencyStatusFlow(currencyId) } return currencyFlow.map { maybeCurrency -> maybeCurrency.mapLeft(CurrenciesStatusesOperations.Error::mapToCurrencyError) diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt index 895ee2ee8e..0ff4f92ae7 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt @@ -35,7 +35,6 @@ class GetCurrencyWarningsUseCase( networkId = currency.network.id, currencyId = currency.id, derivationPath = derivationPath, - contractAddress = (currency as? CryptoCurrency.Token)?.contractAddress, isSingleWalletWithTokens = isSingleWalletWithTokens, ), flowOf(walletManagersFacade.getRentInfo(userWalletId, currency.network)), @@ -63,7 +62,6 @@ class GetCurrencyWarningsUseCase( userWalletId: UserWalletId, networkId: Network.ID, currencyId: CryptoCurrency.ID, - contractAddress: String?, derivationPath: Network.DerivationPath, isSingleWalletWithTokens: Boolean, ): Flow> { @@ -77,7 +75,7 @@ class GetCurrencyWarningsUseCase( val currencyFlow = if (isSingleWalletWithTokens) { operations.getCurrencyStatusSingleWalletWithTokensFlow(currencyId) } else { - operations.getCurrencyStatusFlow(currencyId, contractAddress, derivationPath) + operations.getCurrencyStatusFlow(currencyId) } val networkFlow = if (isSingleWalletWithTokens) { operations.getNetworkCoinForSingleWalletWithTokenFlow(networkId) diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrenciesStatusesOperations.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrenciesStatusesOperations.kt index 3bbe439bc5..9bce6f0d35 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrenciesStatusesOperations.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrenciesStatusesOperations.kt @@ -105,13 +105,9 @@ internal class CurrenciesStatusesOperations( } } - suspend fun getCurrencyStatusFlow( - currencyId: CryptoCurrency.ID, - contractAddress: String?, - derivationPath: Network.DerivationPath, - ): Flow> { + suspend fun getCurrencyStatusFlow(currencyId: CryptoCurrency.ID): Flow> { val currency = recover( - block = { getMultiCurrencyWalletCurrency(currencyId, contractAddress, derivationPath) }, + block = { getMultiCurrencyWalletCurrency(currencyId) }, recover = { return flowOf(it.left()) }, ) @@ -245,17 +241,11 @@ internal class CurrenciesStatusesOperations( .onEmpty { emit(Error.EmptyCurrencies.left()) } } - private suspend fun Raise.getMultiCurrencyWalletCurrency( - currencyId: CryptoCurrency.ID, - contractAddress: String?, - derivationPath: Network.DerivationPath, - ): CryptoCurrency { + private suspend fun Raise.getMultiCurrencyWalletCurrency(currencyId: CryptoCurrency.ID): CryptoCurrency { return Either.catch { currenciesRepository.getMultiCurrencyWalletCurrency( userWalletId = userWalletId, id = currencyId, - contractAddress = contractAddress, - derivationPath = derivationPath, ) } .mapLeft { Error.DataError(it) } diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/CurrenciesRepository.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/CurrenciesRepository.kt index d2c1bd3b72..3901e5ad7a 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/CurrenciesRepository.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/CurrenciesRepository.kt @@ -127,18 +127,11 @@ interface CurrenciesRepository { * * @param userWalletId The unique identifier of the user wallet. * @param id The unique identifier of the cryptocurrency to be retrieved. - * @param contractAddress The contract address of the crypto currency - * @param derivationPath currency derivation path. * @return The cryptocurrency associated with the user wallet and ID. * @throws com.tangem.domain.core.error.DataError.UserWalletError.WrongUserWallet If single-currency user wallet * ID provided. */ - suspend fun getMultiCurrencyWalletCurrency( - userWalletId: UserWalletId, - id: CryptoCurrency.ID, - contractAddress: String?, - derivationPath: Network.DerivationPath, - ): CryptoCurrency + suspend fun getMultiCurrencyWalletCurrency(userWalletId: UserWalletId, id: CryptoCurrency.ID): CryptoCurrency /** * Get the coin for a specific network. diff --git a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockCurrenciesRepository.kt b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockCurrenciesRepository.kt index 97e34fcc43..ffdd5c834d 100644 --- a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockCurrenciesRepository.kt +++ b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockCurrenciesRepository.kt @@ -80,8 +80,6 @@ internal class MockCurrenciesRepository( override suspend fun getMultiCurrencyWalletCurrency( userWalletId: UserWalletId, id: CryptoCurrency.ID, - contractAddress: String?, - derivationPath: Network.DerivationPath, ): CryptoCurrency { val token = token.getOrElse { e -> throw e } diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/send/viewmodel/SendViewModel.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/send/viewmodel/SendViewModel.kt index 46377b3fe4..eac86c94a9 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/send/viewmodel/SendViewModel.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/send/viewmodel/SendViewModel.kt @@ -80,8 +80,6 @@ internal class SendViewModel @Inject constructor( getCurrencyStatusUpdatesUseCase( userWalletId = userWalletId, currencyId = cryptoCurrency.id, - derivationPath = cryptoCurrency.network.derivationPath, - contractAddress = (cryptoCurrency as? CryptoCurrency.Token)?.contractAddress, isSingleWalletWithTokens = isSingleWallet, ) .flowWithLifecycle(owner.lifecycle) diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt index e7addd38b0..b1496b2e0c 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt @@ -160,8 +160,6 @@ internal class TokenDetailsViewModel @Inject constructor( getCurrencyStatusUpdatesUseCase( userWalletId = userWalletId, currencyId = cryptoCurrency.id, - contractAddress = (cryptoCurrency as? CryptoCurrency.Token)?.contractAddress, - derivationPath = cryptoCurrency.network.derivationPath, isSingleWalletWithTokens = wallet.scanResponse.cardTypesResolver.isSingleWalletWithToken(), ) .distinctUntilChanged() @@ -456,8 +454,6 @@ internal class TokenDetailsViewModel @Inject constructor( fetchCurrencyStatusUseCase( userWalletId = userWalletId, id = cryptoCurrency.id, - contractAddress = (cryptoCurrency as? CryptoCurrency.Token)?.contractAddress, - derivationPath = cryptoCurrency.network.derivationPath, refresh = true, ) },