diff --git a/app/src/main/java/com/tangem/tap/domain/walletCurrencies/implementation/DefaultWalletCurrenciesManager.kt b/app/src/main/java/com/tangem/tap/domain/walletCurrencies/implementation/DefaultWalletCurrenciesManager.kt index b9292c096c..5fe6dd8e22 100644 --- a/app/src/main/java/com/tangem/tap/domain/walletCurrencies/implementation/DefaultWalletCurrenciesManager.kt +++ b/app/src/main/java/com/tangem/tap/domain/walletCurrencies/implementation/DefaultWalletCurrenciesManager.kt @@ -1,6 +1,5 @@ package com.tangem.tap.domain.walletCurrencies.implementation -import com.tangem.blockchain.common.Blockchain import com.tangem.blockchain.common.DerivationStyle import com.tangem.common.CompletionResult import com.tangem.common.flatMap @@ -69,7 +68,7 @@ internal class DefaultWalletCurrenciesManager( .flatMap { updateWalletStoresAmounts( userWallet = userWallet, - updatedBlockchains = currenciesToAdd.map { it.blockchain }.distinct(), + updatedCurrencies = currenciesToAddWithMissingBlockchains, ) } } @@ -220,11 +219,13 @@ internal class DefaultWalletCurrenciesManager( private suspend fun updateWalletStoresAmounts( userWallet: UserWallet, - updatedBlockchains: List, + updatedCurrencies: List, ): CompletionResult { + val updatedBlockchains = updatedCurrencies + .filterIsInstance() val updatedWalletStores = walletStoresRepository.get(userWallet.walletId) .firstOrNull() - ?.filter { it.blockchain in updatedBlockchains } + ?.filter { it.blockchainWalletData.currency in updatedBlockchains } ?: return CompletionResult.Success(Unit) return walletAmountsRepository.updateAmountsForWalletStores( diff --git a/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/DefaultWalletAmountsRepository.kt b/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/DefaultWalletAmountsRepository.kt index 1080f7529f..dff146b175 100644 --- a/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/DefaultWalletAmountsRepository.kt +++ b/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/DefaultWalletAmountsRepository.kt @@ -142,8 +142,8 @@ internal class DefaultWalletAmountsRepository( Timber.e( error, """ - Unable to fetch fiat rates - |- Coins ids: $coinsIds + Unable to fetch fiat rates + |- Coins ids: $coinsIds """.trimIndent(), ) @@ -278,6 +278,7 @@ internal class DefaultWalletAmountsRepository( Unable to fetch amounts |- User wallet id: ${walletStore.userWalletId} |- Blockchain: ${walletStore.blockchain} + |- Derivation path: ${walletStore.derivationPath?.rawPath} """.trimIndent(), ) @@ -310,6 +311,7 @@ internal class DefaultWalletAmountsRepository( Fetched amounts |- User wallet id: ${walletStore.userWalletId} |- Blockchain: ${walletStore.blockchain} + |- Derivation path: ${walletStore.derivationPath?.rawPath} """.trimIndent(), ) @@ -337,6 +339,7 @@ internal class DefaultWalletAmountsRepository( Missed derivation |- User wallet id: ${walletStore.userWalletId} |- Blockchain: ${walletStore.blockchain} + |- Derivation path: ${walletStore.derivationPath?.rawPath} """.trimIndent(), ) @@ -360,6 +363,7 @@ internal class DefaultWalletAmountsRepository( Wallet manager is null |- User wallet id: ${walletStore.userWalletId} |- Blockchain: ${walletStore.blockchain} + |- Derivation path: ${walletStore.derivationPath?.rawPath} """.trimIndent(), ) @@ -405,6 +409,7 @@ internal class DefaultWalletAmountsRepository( Fetched wallet rent |- User wallet id: ${walletStore.userWalletId} |- Blockchain: ${walletStore.blockchain} + |- Derivation path: ${walletStore.derivationPath?.rawPath} |- Rent: $rent """.trimIndent(), ) diff --git a/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/DefaultWalletManagersRepository.kt b/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/DefaultWalletManagersRepository.kt index d9579349d6..6c1442d65d 100644 --- a/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/DefaultWalletManagersRepository.kt +++ b/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/DefaultWalletManagersRepository.kt @@ -51,6 +51,7 @@ internal class DefaultWalletManagersRepository( val foundWalletManager = findWalletManager( userWalletId = userWallet.walletId, blockchain = blockchainNetwork?.blockchain, + derivationPath = blockchainNetwork?.derivationPath, ) foundWalletManager?.updateTokens( @@ -85,7 +86,13 @@ internal class DefaultWalletManagersRepository( return when { blockchain == Blockchain.Unknown || blockchain == null -> { val error = WalletStoresError.UnknownBlockchain() - Timber.e(error) + Timber.e( + error, + """ + Unknown blockchain while creating wallet manager + |- User wallet ID: ${userWallet.walletId} + """.trimIndent(), + ) CompletionResult.Failure(error) } walletManager != null -> { @@ -97,7 +104,15 @@ internal class DefaultWalletManagersRepository( } else -> { val error = WalletStoresError.WalletManagerNotCreated(blockchain) - Timber.e(error) + Timber.e( + error, + """ + Unable to create wallet manager + |- User wallet ID: ${userWallet.walletId} + |- Blockchain: $blockchain + |- Derivation path: ${blockchainNetwork?.derivationPath} + """.trimIndent(), + ) CompletionResult.Failure(error) } } @@ -178,15 +193,19 @@ internal class DefaultWalletManagersRepository( private suspend fun findWalletManager( userWalletId: UserWalletId, blockchain: Blockchain?, + derivationPath: String?, ): WalletManager? { return walletManagersStorage.getAll() .firstOrNull() ?.get(userWalletId) ?.let { userWalletManagers -> - if (blockchain == null) { + if (blockchain == null || derivationPath == null) { userWalletManagers.firstOrNull() } else { - userWalletManagers.firstOrNull { it.wallet.blockchain == blockchain } + userWalletManagers.firstOrNull { + it.wallet.blockchain == blockchain && + it.wallet.publicKey.derivationPath?.rawPath == derivationPath + } } } } diff --git a/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/utils/WalletStoreOperations.kt b/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/utils/WalletStoreOperations.kt index d052401b0c..efcd36e402 100644 --- a/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/utils/WalletStoreOperations.kt +++ b/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/utils/WalletStoreOperations.kt @@ -121,9 +121,10 @@ private inline fun List.replaceWalletStores( if (currentWalletStore != updatedWalletStore) { Timber.d( """ - Update wallet store in storage - |- User wallet ID: ${updatedWalletStore.userWalletId} - |- Blockchain: ${updatedWalletStore.blockchain} + Update wallet store in storage + |- User wallet ID: ${updatedWalletStore.userWalletId} + |- Blockchain: ${updatedWalletStore.blockchain} + |- Derivation path: ${updatedWalletStore.derivationPath?.rawPath} """.trimIndent(), )