Updated on 2026-08-14

This commit is contained in:
Tangem 2021-10-21 19:19:59 +03:00
parent ed1012d315
commit 5ec60f0cce
7 changed files with 47 additions and 28 deletions

View file

@ -16,7 +16,7 @@ import com.tangem.tap.domain.TapWorkarounds.isExcluded
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.TwinCardsManager
import com.tangem.tap.domain.twins.TwinsHelper
import com.tangem.tap.domain.twins.isTangemTwin
class ScanNoteTask(val card: Card? = null) : CardSessionRunnable<ScanResponse> {
@ -92,7 +92,7 @@ class ScanNoteTask(val card: Card? = null) : CardSessionRunnable<ScanResponse> {
callback(CompletionResult.Success(ScanResponse(card, ProductType.Other, null)))
return@run
}
val verified = TwinCardsManager.verifyTwinPublicKey(
val verified = TwinsHelper.verifyTwinPublicKey(
readDataResult.data.issuerData, publicKey
)
if (verified) {

View file

@ -45,7 +45,7 @@ private class CreateProductWalletTask(
override fun run(session: CardSession, callback: (result: CompletionResult<CreateWalletResponse>) -> Unit) {
val commandProcessor = when (type) {
ProductType.Note -> CreateWalletTangemNote()
ProductType.Twin -> throw UnsupportedOperationException("Use the TwinCardsManager to create a wallet")
ProductType.Twins -> throw UnsupportedOperationException("Use the TwinCardsManager to create a wallet")
ProductType.Wallet -> CreateWalletTangemWallet()
else -> CreateWalletOtherCards()
}

View file

@ -24,7 +24,7 @@ import com.tangem.tap.domain.TapWorkarounds.isExcluded
import com.tangem.tap.domain.TapWorkarounds.isTangemNote
import com.tangem.tap.domain.TapWorkarounds.isTangemWallet
import com.tangem.tap.domain.extensions.getSingleWallet
import com.tangem.tap.domain.twins.TwinCardsManager
import com.tangem.tap.domain.twins.TwinsHelper
import com.tangem.tap.domain.twins.isTangemTwin
data class ScanResponse(
@ -43,13 +43,17 @@ data class ScanResponse(
fun getPrimaryToken(): Token? {
val cardToken = walletData?.token ?: return null
return Token(
cardToken.name,
cardToken.symbol,
cardToken.contractAddress,
cardToken.decimals,
Blockchain.fromId(walletData.blockchain)
cardToken.name,
cardToken.symbol,
cardToken.contractAddress,
cardToken.decimals,
Blockchain.fromId(walletData.blockchain)
)
}
fun twinsIsTwinned(): Boolean {
return walletData != null && secondTwinPublicKey != null
}
}
class ScanProductTask(val card: Card? = null) : CardSessionRunnable<ScanResponse> {
@ -120,21 +124,21 @@ private class ScanTwinProcessor : ProductCommandProcessor<ScanResponse> {
is CompletionResult.Success -> {
val publicKey = card.getSingleWallet()?.publicKey
if (publicKey == null) {
callback(CompletionResult.Success(ScanResponse(card, ProductType.Twin, null)))
callback(CompletionResult.Success(ScanResponse(card, ProductType.Twins, null)))
return@run
}
val verified = TwinCardsManager.verifyTwinPublicKey(readDataResult.data.issuerData, publicKey)
val verified = TwinsHelper.verifyTwinPublicKey(readDataResult.data.issuerData, publicKey)
if (verified) {
val twinPublicKey = readDataResult.data.issuerData.sliceArray(0 until 65)
val walletData = session.environment.walletData
val response = ScanResponse(card, ProductType.Twin, walletData, twinPublicKey.toHexString())
val response = ScanResponse(card, ProductType.Twins, walletData, twinPublicKey.toHexString())
callback(CompletionResult.Success(response))
} else {
callback(CompletionResult.Success(ScanResponse(card, ProductType.Twin, null)))
callback(CompletionResult.Success(ScanResponse(card, ProductType.Twins, null)))
}
}
is CompletionResult.Failure ->
callback(CompletionResult.Success(ScanResponse(card, ProductType.Twin, null)))
callback(CompletionResult.Success(ScanResponse(card, ProductType.Twins, null)))
}
}
}