Updated on 2026-08-14

This commit is contained in:
Tangem 2023-05-18 10:47:27 +04:00
parent 49726e251e
commit 4ec7ff5c40
2 changed files with 8 additions and 53 deletions

View file

@ -138,7 +138,8 @@ private class CreateWalletTangemWallet : ProductCommandProcessor<CreateProductWa
session: CardSession,
callback: (result: CompletionResult<CreateProductWalletTaskResponse>) -> Unit,
) {
val curves = card.getCurvesForNonCreatedWallets()
val walletsOnCard = card.wallets.map { it.curve }.toSet()
val curves = card.supportedCurves.intersect(CURVES_FOR_WALLETS).subtract(walletsOnCard).toList()
if (curves.isEmpty()) {
val createWalletResponses = card.wallets.map { wallet ->
@ -158,7 +159,6 @@ private class CreateWalletTangemWallet : ProductCommandProcessor<CreateProductWa
callback = callback,
)
}
is CompletionResult.Failure -> {
callback(CompletionResult.Failure(result.error))
}
@ -295,4 +295,8 @@ private class CreateWalletTangemWallet : ProductCommandProcessor<CreateProductWa
else -> listOf(Blockchain.Bitcoin, Blockchain.Ethereum)
}
}
private companion object {
val CURVES_FOR_WALLETS = listOf(EllipticCurve.Secp256k1, EllipticCurve.Ed25519)
}
}

View file

@ -3,7 +3,6 @@ package com.tangem.tap.domain.tasks.product
import com.tangem.blockchain.common.Blockchain
import com.tangem.common.CompletionResult
import com.tangem.common.card.Card
import com.tangem.common.card.EllipticCurve
import com.tangem.common.core.CardSession
import com.tangem.common.core.CardSessionRunnable
import com.tangem.common.core.TangemError
@ -29,8 +28,6 @@ import com.tangem.domain.common.TwinsHelper
import com.tangem.domain.models.scan.CardDTO
import com.tangem.domain.models.scan.ProductType
import com.tangem.domain.models.scan.ScanResponse
import com.tangem.operations.PreflightReadMode
import com.tangem.operations.PreflightReadTask
import com.tangem.operations.ScanTask
import com.tangem.operations.backup.PrimaryCard
import com.tangem.operations.backup.StartPrimaryCardLinkingTask
@ -39,7 +36,6 @@ import com.tangem.operations.files.ReadFilesTask
import com.tangem.operations.issuerAndUserData.ReadIssuerDataCommand
import com.tangem.tap.domain.TapSdkError
import com.tangem.tap.domain.extensions.getPrimaryCurve
import com.tangem.tap.domain.extensions.isFirmwareMultiwalletAllowed
import com.tangem.tap.domain.tokens.UserTokensRepository
import com.tangem.tap.domain.tokens.models.BlockchainNetwork
import com.tangem.tap.preferencesStorage
@ -114,7 +110,7 @@ private class ScanWalletProcessor(
return
}
createMissingWalletsIfNeeded(card, session, callback)
startLinkingForBackupIfNeeded(card, session, callback)
}
private fun readFile(
@ -122,7 +118,7 @@ private class ScanWalletProcessor(
session: CardSession,
callback: (result: CompletionResult<ScanResponse>) -> Unit,
) {
val funToContinue = { createMissingWalletsIfNeeded(card, session, callback) }
val funToContinue = { startLinkingForBackupIfNeeded(card, session, callback) }
ReadFilesTask(fileName = "blockchainInfo", walletPublicKey = null).run(session) { result ->
@ -185,45 +181,6 @@ private class ScanWalletProcessor(
}
}
private fun createMissingWalletsIfNeeded(
card: CardDTO,
session: CardSession,
callback: (result: CompletionResult<ScanResponse>) -> Unit,
) {
if (card.wallets.isNotEmpty() && card.backupStatus?.isActive == true) {
startLinkingForBackupIfNeeded(card, session, callback)
return
}
if (card.wallets.isEmpty() || !card.isFirmwareMultiwalletAllowed) {
startLinkingForBackupIfNeeded(card, session, callback)
return
}
val curvesToCreate = card.getCurvesForNonCreatedWallets()
if (curvesToCreate.isEmpty()) {
startLinkingForBackupIfNeeded(card, session, callback)
return
}
CreateWalletsTask(curvesToCreate).run(session) { result ->
when (result) {
is CompletionResult.Success -> {
PreflightReadTask(
readMode = PreflightReadMode.FullCardRead,
cardId = card.cardId,
).run(session) { readResult ->
when (readResult) {
is CompletionResult.Success -> startLinkingForBackupIfNeeded(card, session, callback)
is CompletionResult.Failure -> callback(CompletionResult.Failure(readResult.error))
}
}
}
is CompletionResult.Failure -> callback(CompletionResult.Failure(result.error))
}
}
}
private fun startLinkingForBackupIfNeeded(
card: CardDTO,
session: CardSession,
@ -424,10 +381,4 @@ private class ScanTwinProcessor : ProductCommandProcessor<ScanResponse> {
}
}
}
}
fun CardDTO.getCurvesForNonCreatedWallets(): List<EllipticCurve> {
val curvesPresent = wallets.map { it.curve }.toSet()
val curvesForNonCreatedWallets = supportedCurves.subtract(curvesPresent + EllipticCurve.Secp256r1)
return curvesForNonCreatedWallets.toList()
}