diff --git a/app/src/main/java/com/tangem/tap/domain/tasks/product/ScanProductTask.kt b/app/src/main/java/com/tangem/tap/domain/tasks/product/ScanProductTask.kt index 2717354cc4..e17d4e2ebb 100644 --- a/app/src/main/java/com/tangem/tap/domain/tasks/product/ScanProductTask.kt +++ b/app/src/main/java/com/tangem/tap/domain/tasks/product/ScanProductTask.kt @@ -247,7 +247,10 @@ private class ScanWalletProcessor( derivationStyleProvider: DerivationStyleProvider, ): List { val userTokensRepository = userTokensRepository ?: return emptyList() - val blockchainsToDerive = userTokensRepository.loadBlockchainsToDerive(card) + val blockchainsToDerive = userTokensRepository.loadBlockchainsToDerive( + card, + derivationStyleProvider.getDerivationStyle(), + ) .toMutableList() .ifEmpty { mutableListOf( diff --git a/app/src/main/java/com/tangem/tap/domain/tokens/UserTokensRepository.kt b/app/src/main/java/com/tangem/tap/domain/tokens/UserTokensRepository.kt index 1304588781..7026203db3 100644 --- a/app/src/main/java/com/tangem/tap/domain/tokens/UserTokensRepository.kt +++ b/app/src/main/java/com/tangem/tap/domain/tokens/UserTokensRepository.kt @@ -28,18 +28,23 @@ class UserTokensRepository( private val networkConnectionManager: NetworkConnectionManager, ) { - suspend fun getUserTokens(card: CardDTO): List = withContext(dispatchers.io) { - val userWalletId = getUserWalletId(card) ?: return@withContext emptyList() + suspend fun getUserTokens(card: CardDTO, derivationStyle: DerivationStyle?): List = + withContext(dispatchers.io) { + val userWalletId = getUserWalletId(card) ?: return@withContext emptyList() - if (DemoHelper.isDemoCardId(card.cardId)) { - return@withContext loadTokensOffline(userWalletId = userWalletId).ifEmpty(::loadDemoCurrencies) + if (DemoHelper.isDemoCardId(card.cardId)) { + return@withContext loadTokensOffline(userWalletId = userWalletId).ifEmpty { + loadDemoCurrencies( + derivationStyle, + ) + } + } + + if (!networkConnectionManager.isOnline) return@withContext loadTokensOffline(userWalletId = userWalletId) + + return@withContext remoteGetUserTokens(userWalletId = userWalletId) } - if (!networkConnectionManager.isOnline) return@withContext loadTokensOffline(userWalletId = userWalletId) - - return@withContext remoteGetUserTokens(userWalletId = userWalletId) - } - suspend fun saveUserTokens(card: CardDTO, tokens: List) = withContext(dispatchers.io) { val userWalletId = getUserWalletId(card) ?: return@withContext val userTokens = tokens.toUserTokensResponse() @@ -48,28 +53,29 @@ class UserTokensRepository( } // FIXME: Move to data layer - suspend fun loadBlockchainsToDerive(card: CardDTO): List = withContext(dispatchers.io) { - val userWalletId = getUserWalletId(card) ?: return@withContext emptyList() - val blockchainNetworks = loadTokensOffline(userWalletId = userWalletId).toBlockchainNetworks() + suspend fun loadBlockchainsToDerive(card: CardDTO, derivationStyle: DerivationStyle?): List = + withContext(dispatchers.io) { + val userWalletId = getUserWalletId(card) ?: return@withContext emptyList() + val blockchainNetworks = loadTokensOffline(userWalletId = userWalletId).toBlockchainNetworks() - if (DemoHelper.isDemoCardId(card.cardId)) { - return@withContext blockchainNetworks.ifEmpty(loadDemoCurrencies()::toBlockchainNetworks) + if (DemoHelper.isDemoCardId(card.cardId)) { + return@withContext blockchainNetworks.ifEmpty(loadDemoCurrencies(derivationStyle)::toBlockchainNetworks) + } + + return@withContext blockchainNetworks } - return@withContext blockchainNetworks - } - private fun loadTokensOffline(userWalletId: String): List { return storageService.getUserTokens(userWalletId = userWalletId) ?: emptyList() } // FIXME: Move to user wallet config - private fun loadDemoCurrencies(): List { + private fun loadDemoCurrencies(derivationStyle: DerivationStyle?): List { return DemoHelper.config.demoBlockchains .map { blockchain -> BlockchainNetwork( blockchain = blockchain, - derivationPath = blockchain.derivationPath(DerivationStyle.LEGACY)?.rawPath, + derivationPath = blockchain.derivationPath(derivationStyle)?.rawPath, tokens = emptyList(), ) } diff --git a/app/src/main/java/com/tangem/tap/domain/walletStores/implementation/DefaultWalletStoresManager.kt b/app/src/main/java/com/tangem/tap/domain/walletStores/implementation/DefaultWalletStoresManager.kt index f2af46b082..4e60254106 100644 --- a/app/src/main/java/com/tangem/tap/domain/walletStores/implementation/DefaultWalletStoresManager.kt +++ b/app/src/main/java/com/tangem/tap/domain/walletStores/implementation/DefaultWalletStoresManager.kt @@ -3,6 +3,7 @@ package com.tangem.tap.domain.walletStores.implementation import com.tangem.blockchain.common.WalletManager import com.tangem.blockchain.common.address.AddressType import com.tangem.common.* +import com.tangem.domain.common.util.derivationStyleProvider import com.tangem.domain.wallets.legacy.WalletManagersRepository import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.models.UserWalletId @@ -126,8 +127,9 @@ internal class DefaultWalletStoresManager( private suspend fun fetchMultiWallets(userWallet: UserWallet): CompletionResult { val scanResponse = userWallet.scanResponse + val derivationStyle = scanResponse.derivationStyleProvider.getDerivationStyle() val userTokens = withContext(Dispatchers.IO) { - userTokensRepository.getUserTokens(scanResponse.card) + userTokensRepository.getUserTokens(scanResponse.card, derivationStyle) } val userWalletId = userWallet.walletId diff --git a/app/src/main/java/com/tangem/tap/proxy/UserWalletManagerImpl.kt b/app/src/main/java/com/tangem/tap/proxy/UserWalletManagerImpl.kt index 432dc559a1..0403ad4383 100644 --- a/app/src/main/java/com/tangem/tap/proxy/UserWalletManagerImpl.kt +++ b/app/src/main/java/com/tangem/tap/proxy/UserWalletManagerImpl.kt @@ -40,7 +40,7 @@ class UserWalletManagerImpl( val userTokensRepository = requireNotNull(appStateHolder.userTokensRepository) { "userTokensRepository is null" } return if (card != null) { - userTokensRepository.getUserTokens(card) + userTokensRepository.getUserTokens(card, null) // refactor in [REDACTED_JIRA] .filter { val checkCustom = if (isExcludeCustom) { !it.isCustomCurrency(null) diff --git a/domain/demo/src/main/java/com/tangem/domain/demo/DemoConfig.kt b/domain/demo/src/main/java/com/tangem/domain/demo/DemoConfig.kt index 1ed5f92538..864ed232f9 100644 --- a/domain/demo/src/main/java/com/tangem/domain/demo/DemoConfig.kt +++ b/domain/demo/src/main/java/com/tangem/domain/demo/DemoConfig.kt @@ -405,8 +405,6 @@ class DemoConfig { "AF04000000012014", "AF04000000012022", "AF04000000012030", - - // "AF02000000000003", ) @Suppress("ClassOrdering")