From f338f79230d04f62e6797f164be67d89be1ec99c Mon Sep 17 00:00:00 2001 From: Tangem Date: Sat, 12 Jul 2025 20:33:15 +0400 Subject: [PATCH] Updated on 2026-08-14 --- .../GetExtendedPublicKeyForCurrencyUseCase.kt | 20 ++++++++----- .../tokendetails/model/TokenDetailsModel.kt | 30 ++++++++++++++++++- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/domain/card/src/main/kotlin/com/tangem/domain/card/GetExtendedPublicKeyForCurrencyUseCase.kt b/domain/card/src/main/kotlin/com/tangem/domain/card/GetExtendedPublicKeyForCurrencyUseCase.kt index 7e6414e4ed..cf3ef97782 100644 --- a/domain/card/src/main/kotlin/com/tangem/domain/card/GetExtendedPublicKeyForCurrencyUseCase.kt +++ b/domain/card/src/main/kotlin/com/tangem/domain/card/GetExtendedPublicKeyForCurrencyUseCase.kt @@ -1,6 +1,7 @@ package com.tangem.domain.card import arrow.core.Either +import arrow.core.right import com.tangem.blockchain.common.Blockchain import com.tangem.blockchainsdk.utils.toBlockchain import com.tangem.common.extensions.ByteArrayKey @@ -22,16 +23,17 @@ class GetExtendedPublicKeyForCurrencyUseCase( private val derivationsRepository: DerivationsRepository, private val walletManagersFacade: WalletManagersFacade, ) { + suspend operator fun invoke(userWalletId: UserWalletId, network: Network): Either { return Either.catch { - val userWallet = walletManagersFacade.getOrCreateWalletManager(userWalletId, network) + val walletManager = walletManagersFacade.getOrCreateWalletManager(userWalletId, network) ?: error("Wallet not found") val blockchain = network.toBlockchain() val isSecp256k1Blockchain = Blockchain.secp256k1Blockchains(network.isTestnet).contains(blockchain) val hdKey = if (isSecp256k1Blockchain) { - userWallet.wallet.publicKey.derivationType?.hdKey ?: error("No derivation found") + walletManager.wallet.publicKey.derivationType?.hdKey ?: error("No derivation found") } else { error("No derivation found") } @@ -50,7 +52,7 @@ class GetExtendedPublicKeyForCurrencyUseCase( val pendingDerivations = getPendingDerivations(childKey, parentKey) val derivedKeys = deriveKeys( userWalletId = userWalletId, - seedKey = userWallet.wallet.publicKey.seedKey, + seedKey = walletManager.wallet.publicKey.seedKey, paths = pendingDerivations, ) @@ -73,15 +75,17 @@ class GetExtendedPublicKeyForCurrencyUseCase( /** * @return true if xpub generation is supported, false otherwise */ - suspend fun isSupported(userWalletId: UserWalletId, network: Network): Boolean { - val userWallet = walletManagersFacade.getOrCreateWalletManager(userWalletId, network) - ?: error("Wallet not found") + suspend fun isSupported(userWalletId: UserWalletId, network: Network): Either = Either.catch { + val walletManager = walletManagersFacade.getOrCreateWalletManager(userWalletId, network) + ?: error("Wallet not found for user wallet $userWalletId and network ${network.id}") val blockchain = network.toBlockchain() val isSecp256k1Blockchain = Blockchain.secp256k1Blockchains(network.isTestnet).contains(blockchain) - val isHdKey = userWallet.wallet.publicKey.derivationType?.hdKey + val isHdKey = walletManager.wallet.publicKey.derivationType?.hdKey - return isSecp256k1Blockchain && isHdKey != null + val isSupported = isSecp256k1Blockchain && isHdKey != null + + return isSupported.right() } private suspend fun deriveKeys( diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/model/TokenDetailsModel.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/model/TokenDetailsModel.kt index 46dba2b2a9..d845947e08 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/model/TokenDetailsModel.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/model/TokenDetailsModel.kt @@ -3,6 +3,7 @@ package com.tangem.feature.tokendetails.presentation.tokendetails.model import androidx.compose.runtime.Stable import androidx.paging.cachedIn import arrow.core.getOrElse +import arrow.core.merge import com.tangem.blockchain.common.address.AddressType import com.tangem.common.routing.AppRoute import com.tangem.common.routing.AppRouter @@ -11,7 +12,9 @@ import com.tangem.common.ui.bottomsheet.receive.mapToAddressModels import com.tangem.common.ui.expressStatus.ExpressStatusBottomSheetConfig import com.tangem.common.ui.expressStatus.state.ExpressTransactionStateUM import com.tangem.core.analytics.api.AnalyticsEventHandler +import com.tangem.core.analytics.api.AnalyticsExceptionHandler import com.tangem.core.analytics.models.AnalyticsParam +import com.tangem.core.analytics.models.ExceptionAnalyticsEvent import com.tangem.core.decompose.di.GlobalUiMessageSender import com.tangem.core.decompose.di.ModelScoped import com.tangem.core.decompose.model.Model @@ -134,6 +137,7 @@ internal class TokenDetailsModel @Inject constructor( getStakingIntegrationIdUseCase: GetStakingIntegrationIdUseCase, private val appRouter: AppRouter, private val router: InnerTokenDetailsRouter, + private val analyticsExceptionHandler: AnalyticsExceptionHandler, ) : Model(), TokenDetailsClickIntents { private val params = paramsContainer.require() @@ -444,7 +448,31 @@ internal class TokenDetailsModel @Inject constructor( network = cryptoCurrency.network, ).getOrElse { false } - val isSupported = getExtendedPublicKeyForCurrencyUseCase.isSupported(userWalletId, cryptoCurrency.network) + val isSupported = getExtendedPublicKeyForCurrencyUseCase.isSupported( + userWalletId = userWalletId, + network = cryptoCurrency.network, + ) + .mapLeft { + analyticsExceptionHandler.sendException( + event = ExceptionAnalyticsEvent( + exception = it, + params = mapOf( + "blockchainId" to cryptoCurrency.network.id.rawId.value, + "networkId" to cryptoCurrency.network.backendId, + ), + ), + ) + + Timber.e( + /* t = */ it, + /* message = */ "Unable to get wallet manager for user wallet %s and network %s", + /* ...args = */ userWalletId, + cryptoCurrency.network, + ) + + false + } + .merge() internalUiState.value = stateFactory.getStateWithUpdatedMenu( cardTypesResolver = userWallet.scanResponse.cardTypesResolver,