Updated on 2026-08-14
This commit is contained in:
parent
33cb6d92b5
commit
15d8fde8ad
11 changed files with 11 additions and 479 deletions
|
|
@ -16,7 +16,6 @@ import com.tangem.domain.models.wallet.UserWallet
|
|||
import com.tangem.domain.settings.IsReadyToShowRateAppUseCase
|
||||
import com.tangem.domain.tokens.error.CurrencyStatusError
|
||||
import com.tangem.domain.wallets.usecase.GetWalletsUseCase
|
||||
import com.tangem.domain.wallets.usecase.HasSingleWalletSignedHashesUseCase
|
||||
import com.tangem.domain.wallets.usecase.IsNeedToBackupUseCase
|
||||
import com.tangem.feature.wallet.child.wallet.model.intents.WalletClickIntents
|
||||
import com.tangem.feature.wallet.presentation.wallet.state.model.WalletNotification
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import com.tangem.domain.models.currency.CryptoCurrency
|
|||
import com.tangem.domain.models.currency.CryptoCurrencyStatus
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.models.wallet.isMultiCurrency
|
||||
import com.tangem.domain.wallets.usecase.HasSingleWalletSignedHashesUseCase
|
||||
import com.tangem.domain.wallets.usecase.IsNeedToBackupUseCase
|
||||
import com.tangem.feature.wallet.child.wallet.model.intents.WalletClickIntents
|
||||
import com.tangem.feature.wallet.impl.R
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
package com.tangem.feature.wallet.presentation.wallet.domain
|
||||
|
||||
import com.tangem.core.decompose.di.ModelScoped
|
||||
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
|
||||
import javax.inject.Inject
|
||||
|
||||
@ModelScoped
|
||||
class HasSingleWalletSignedHashesUseCase @Inject constructor(
|
||||
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
|
||||
}
|
||||
|
||||
return@map try {
|
||||
walletManagersFacade.validateSignatureCount(
|
||||
userWalletId = userWallet.walletId,
|
||||
network = network,
|
||||
signedHashes = userWallet.scanResponse.card.wallets.firstOrNull()?.totalSignedHashes ?: 0,
|
||||
)
|
||||
.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()
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue