Updated on 2026-08-14

This commit is contained in:
Tangem 2021-10-22 03:14:09 +03:00
parent 66f7ab98e9
commit 913402bb7e
8 changed files with 50 additions and 57 deletions

View file

@ -17,8 +17,8 @@ import com.tangem.tap.domain.TapWorkarounds.isTangemNote
import com.tangem.tap.domain.extensions.getSingleWallet
import com.tangem.tap.domain.tasks.product.ScanResponse
import com.tangem.tap.domain.twins.TwinsHelper
import com.tangem.tap.domain.twins.isTangemTwin
@Deprecated("Use ScanProductTask instead")
class ScanNoteTask(val card: Card? = null) : CardSessionRunnable<ScanResponse> {
override fun run(
@ -38,13 +38,13 @@ class ScanNoteTask(val card: Card? = null) : CardSessionRunnable<ScanResponse> {
return@run
}
if (card.isTangemTwin()) {
if (TwinsHelper.getTwinCardNumber(card.cardId) != null) {
dealWithTwinCard(card, session, callback)
} else if (!isTangemNote(card) && card.firmwareVersion >= FirmwareVersion.MultiWalletAvailable) {
createMissingWalletsIfNeeded(card, session, callback)
} else {
callback(CompletionResult.Success(
ScanResponse(card, ProductType.Other, session.environment.walletData)))
ScanResponse(card, ProductType.Other, session.environment.walletData)))
}
}
}
@ -93,16 +93,16 @@ class ScanNoteTask(val card: Card? = null) : CardSessionRunnable<ScanResponse> {
return@run
}
val verified = TwinsHelper.verifyTwinPublicKey(
readDataResult.data.issuerData, publicKey
readDataResult.data.issuerData, publicKey
)
if (verified) {
val twinPublicKey = readDataResult.data.issuerData.sliceArray(0 until 65)
callback(CompletionResult.Success(
ScanResponse(
card = card,
ProductType.Other,
walletData = session.environment.walletData,
secondTwinPublicKey = twinPublicKey.toHexString())
ScanResponse(
card = card,
ProductType.Other,
walletData = session.environment.walletData,
secondTwinPublicKey = twinPublicKey.toHexString())
))
return@run
} else {

View file

@ -24,7 +24,6 @@ import com.tangem.tap.domain.TapWorkarounds.getTangemNoteBlockchain
import com.tangem.tap.domain.TapWorkarounds.isExcluded
import com.tangem.tap.domain.extensions.getSingleWallet
import com.tangem.tap.domain.twins.TwinsHelper
import com.tangem.tap.domain.twins.isTangemTwin
data class ScanResponse(
val card: Card,
@ -55,13 +54,7 @@ data class ScanResponse(
fun isTangemTwins(): Boolean = productType == ProductType.Twins
fun isTangemOtherCards(): Boolean = productType == ProductType.Other
fun twinsIsTwinned(): Boolean {
return card.isTangemTwin() && walletData != null && secondTwinPublicKey != null
}
}
private fun Card.isTangemTwin(): Boolean {
return TwinsHelper.getTwinCardNumber(cardId) != null
fun twinsIsTwinned(): Boolean = card.isTangemTwins() && walletData != null && secondTwinPublicKey != null
}
class ScanProductTask(val card: Card? = null) : CardSessionRunnable<ScanResponse> {
@ -83,7 +76,7 @@ class ScanProductTask(val card: Card? = null) : CardSessionRunnable<ScanResponse
val commandProcessor = when {
TapWorkarounds.isTangemNote(card) -> ScanNoteProcessor()
TwinsHelper.getTwinCardNumber(card.cardId) != null -> ScanTwinProcessor()
card.isTangemTwins() -> ScanTwinProcessor()
TapWorkarounds.isTangemWallet(card) -> ScanWalletProcessor()
else -> ScanOtherCardsProcessor()
}
@ -101,6 +94,8 @@ class ScanProductTask(val card: Card? = null) : CardSessionRunnable<ScanResponse
}
}
private fun Card.isTangemTwins(): Boolean = TwinsHelper.getTwinCardNumber(cardId) != null
private class ScanNoteProcessor : ProductCommandProcessor<ScanResponse> {
override fun proceed(
card: Card,