From 4ec7ff5c40ade64fbccfd30d0bbba35e845965a2 Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 18 May 2023 10:47:27 +0400 Subject: [PATCH] Updated on 2026-08-14 --- .../tasks/product/CreateProductWalletTask.kt | 8 ++- .../domain/tasks/product/ScanProductTask.kt | 53 +------------------ 2 files changed, 8 insertions(+), 53 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/domain/tasks/product/CreateProductWalletTask.kt b/app/src/main/java/com/tangem/tap/domain/tasks/product/CreateProductWalletTask.kt index 4a7518e9f9..cd729b3b27 100644 --- a/app/src/main/java/com/tangem/tap/domain/tasks/product/CreateProductWalletTask.kt +++ b/app/src/main/java/com/tangem/tap/domain/tasks/product/CreateProductWalletTask.kt @@ -138,7 +138,8 @@ private class CreateWalletTangemWallet : ProductCommandProcessor) -> 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 { callback(CompletionResult.Failure(result.error)) } @@ -295,4 +295,8 @@ private class CreateWalletTangemWallet : ProductCommandProcessor listOf(Blockchain.Bitcoin, Blockchain.Ethereum) } } + + private companion object { + val CURVES_FOR_WALLETS = listOf(EllipticCurve.Secp256k1, EllipticCurve.Ed25519) + } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/domain/tasks/product/ScanProductTask.kt b/app/src/main/java/com/tangem/tap/domain/tasks/product/ScanProductTask.kt index 86c7ecc477..821e82be32 100644 --- a/app/src/main/java/com/tangem/tap/domain/tasks/product/ScanProductTask.kt +++ b/app/src/main/java/com/tangem/tap/domain/tasks/product/ScanProductTask.kt @@ -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) -> 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) -> 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 { } } } -} - -fun CardDTO.getCurvesForNonCreatedWallets(): List { - val curvesPresent = wallets.map { it.curve }.toSet() - val curvesForNonCreatedWallets = supportedCurves.subtract(curvesPresent + EllipticCurve.Secp256r1) - return curvesForNonCreatedWallets.toList() } \ No newline at end of file