Updated on 2026-08-14

This commit is contained in:
Tangem 2026-06-18 21:51:32 +03:00
parent 33cb6d92b5
commit 15d8fde8ad
11 changed files with 11 additions and 479 deletions

View file

@ -1,58 +0,0 @@
package com.tangem.domain.wallets.usecase
import com.tangem.domain.card.common.util.cardTypesResolver
import com.tangem.domain.card.repository.CardRepository
import com.tangem.domain.demo.models.DemoConfig
import com.tangem.domain.models.network.Network
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.walletmanager.WalletManagersFacade
import com.tangem.utils.logging.TangemLogger
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
class HasSingleWalletSignedHashesUseCase(
private val cardRepository: CardRepository,
private val walletManagersFacade: WalletManagersFacade,
) {
operator fun invoke(userWallet: UserWallet.Cold, network: Network): Flow<Boolean> {
return cardRepository.wasCardScanned(cardId = userWallet.cardId)
.map { wasCardScanned ->
if (wasCardScanned || !userWallet.isCorrectCardType()) return@map false
if (!userWallet.scanResponse.cardTypesResolver.hasWalletSignedHashes()) {
cardRepository.setCardWasScanned(cardId = userWallet.cardId)
return@map false
}
val signedHashes = userWallet.scanResponse.card.wallets
.firstOrNull()
?.totalSignedHashes
?: 0
return@map try {
walletManagersFacade.validateSignatureCount(
userWalletId = userWallet.walletId,
network = network,
signedHashes = signedHashes,
)
.fold(
ifLeft = { true },
ifRight = {
cardRepository.setCardWasScanned(cardId = userWallet.cardId)
false
},
)
} catch (e: IllegalArgumentException) {
TangemLogger.w("Unable to validate signature count: user wallet not found", e)
false
}
}
}
private fun UserWallet.Cold.isCorrectCardType(): Boolean {
return with(scanResponse.cardTypesResolver) {
!DemoConfig.isDemoCardId(cardId) && isReleaseFirmwareType() && !isMultiwalletAllowed() && !isTangemTwins()
}
}
}