From 913402bb7e219d80ea9b89ef14ded09727eca137 Mon Sep 17 00:00:00 2001 From: Tangem Date: Fri, 22 Oct 2021 03:14:09 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../common/redux/global/GlobalMidlleware.kt | 6 ++-- .../com/tangem/tap/domain/TangemSdkManager.kt | 21 ++++++------ .../com/tangem/tap/domain/TapWalletManager.kt | 5 ++- .../domain/extensions/WalletManagerFactory.kt | 3 +- .../tangem/tap/domain/tasks/ScanNoteTask.kt | 18 +++++------ .../domain/tasks/product/ScanProductTask.kt | 13 +++----- .../features/details/ui/DetailsFragment.kt | 9 +++--- .../redux/middlewares/WarningsMiddleware.kt | 32 ++++++++++--------- 8 files changed, 50 insertions(+), 57 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/common/redux/global/GlobalMidlleware.kt b/app/src/main/java/com/tangem/tap/common/redux/global/GlobalMidlleware.kt index ea80ab463c..10aa0f1533 100644 --- a/app/src/main/java/com/tangem/tap/common/redux/global/GlobalMidlleware.kt +++ b/app/src/main/java/com/tangem/tap/common/redux/global/GlobalMidlleware.kt @@ -47,7 +47,7 @@ private val globalMiddlewareHandler: Middleware = { dispatch, appState } is GlobalAction.RestoreAppCurrency -> { store.dispatch(GlobalAction.RestoreAppCurrency.Success( - preferencesStorage.getAppCurrency() + preferencesStorage.getAppCurrency() )) } is GlobalAction.HideWarningMessage -> { @@ -81,7 +81,7 @@ private val globalMiddlewareHandler: Middleware = { dispatch, appState val userStatusResponse = MoonpayService().getUserStatus(apiKey) if (userStatusResponse is Result.Success) { store.dispatchOnMain( - GlobalAction.GetMoonPayUserStatus.Success(userStatusResponse.data) + GlobalAction.GetMoonPayUserStatus.Success(userStatusResponse.data) ) } } @@ -94,7 +94,7 @@ private val globalMiddlewareHandler: Middleware = { dispatch, appState withMainContext { when (result) { is CompletionResult.Success -> { - tangemSdkManager.changeDisplayedCardIdNumbersCount(result.data.card) + tangemSdkManager.changeDisplayedCardIdNumbersCount(result.data) action.onSuccess?.invoke(result.data) } is CompletionResult.Failure -> action.onFailure?.invoke(result.error) diff --git a/app/src/main/java/com/tangem/tap/domain/TangemSdkManager.kt b/app/src/main/java/com/tangem/tap/domain/TangemSdkManager.kt index 5253a9f91c..3a3acc1a87 100644 --- a/app/src/main/java/com/tangem/tap/domain/TangemSdkManager.kt +++ b/app/src/main/java/com/tangem/tap/domain/TangemSdkManager.kt @@ -23,7 +23,6 @@ import com.tangem.tap.common.analytics.FirebaseAnalyticsHandler import com.tangem.tap.domain.tasks.CreateWalletAndRescanTask import com.tangem.tap.domain.tasks.product.ScanProductTask import com.tangem.tap.domain.tasks.product.ScanResponse -import com.tangem.tap.domain.twins.isTangemTwin import com.tangem.wallet.R import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext @@ -45,9 +44,9 @@ class TangemSdkManager(private val tangemSdk: TangemSdk, private val context: Co suspend fun createProductWallet(scanResponse: ScanResponse): CompletionResult { return runTaskAsync( - CreateProductWalletAndRescanTask(scanResponse.productType), - scanResponse.card.cardId, - Message(context.getString(R.string.initial_message_create_wallet_body)) + CreateProductWalletAndRescanTask(scanResponse.productType), + scanResponse.card.cardId, + Message(context.getString(R.string.initial_message_create_wallet_body)) ) } @@ -105,13 +104,13 @@ class TangemSdkManager(private val tangemSdk: TangemSdk, private val context: Co suspend fun runTaskAsync( runnable: CardSessionRunnable, cardId: String? = null, initialMessage: Message? = null, ): CompletionResult = - withContext(Dispatchers.Main) { - suspendCoroutine { continuation -> - tangemSdk.startSessionWithRunnable(runnable, cardId, initialMessage) { result -> - continuation.resume(result) + withContext(Dispatchers.Main) { + suspendCoroutine { continuation -> + tangemSdk.startSessionWithRunnable(runnable, cardId, initialMessage) { result -> + continuation.resume(result) + } } } - } private suspend fun runTaskAsyncReturnOnMain( runnable: CardSessionRunnable, cardId: String? = null, initialMessage: Message? = null, @@ -120,8 +119,8 @@ class TangemSdkManager(private val tangemSdk: TangemSdk, private val context: Co return withContext(Dispatchers.Main) { result } } - fun changeDisplayedCardIdNumbersCount(card: Card) { - tangemSdk.config.cardIdDisplayedNumbersCount = if (card.isTangemTwin()) 4 else null + fun changeDisplayedCardIdNumbersCount(scanResponse: ScanResponse) { + tangemSdk.config.cardIdDisplayedNumbersCount = if (scanResponse.isTangemTwins()) 4 else null } companion object { diff --git a/app/src/main/java/com/tangem/tap/domain/TapWalletManager.kt b/app/src/main/java/com/tangem/tap/domain/TapWalletManager.kt index edc4601d8c..75e8333a1c 100644 --- a/app/src/main/java/com/tangem/tap/domain/TapWalletManager.kt +++ b/app/src/main/java/com/tangem/tap/domain/TapWalletManager.kt @@ -17,7 +17,6 @@ import com.tangem.tap.domain.extensions.* import com.tangem.tap.domain.tasks.product.ScanResponse import com.tangem.tap.domain.tokens.CardCurrencies import com.tangem.tap.domain.twins.getTwinCardNumber -import com.tangem.tap.domain.twins.isTangemTwin import com.tangem.tap.features.tokens.redux.TokensAction import com.tangem.tap.features.twins.redux.TwinCardsAction import com.tangem.tap.features.wallet.redux.Currency @@ -91,7 +90,7 @@ class TapWalletManager { store.dispatch(GlobalAction.SaveScanNoteResponse(data)) store.dispatch(WalletAction.SetIfTestnetCard(data.card.isTestCard)) store.dispatch(WalletAction.MultiWallet.SetIsMultiwalletAllowed(data.card.isMultiwalletAllowed)) - if (data.card.isTangemTwin()) { + if (data.isTangemTwins()) { data.card.getTwinCardNumber()?.let { val isCreatingTwinsAllowed = configManager?.config?.isCreatingTwinCardsAllowed ?: false store.dispatch(TwinCardsAction.SetTwinCard(it, null, isCreatingTwinsAllowed)) @@ -233,7 +232,7 @@ class TapWalletManager { private fun getActionIfUnknownBlockchainOrEmptyWallet(data: ScanResponse): WalletAction? { return when { // check order is important - data.card.isTangemTwin() && !data.twinsIsTwinned() -> { + data.isTangemTwins() && !data.twinsIsTwinned() -> { WalletAction.EmptyWallet } data.getBlockchain() == Blockchain.Unknown && !data.card.isMultiwalletAllowed -> { diff --git a/app/src/main/java/com/tangem/tap/domain/extensions/WalletManagerFactory.kt b/app/src/main/java/com/tangem/tap/domain/extensions/WalletManagerFactory.kt index 99ed8231c4..aa85331ab2 100644 --- a/app/src/main/java/com/tangem/tap/domain/extensions/WalletManagerFactory.kt +++ b/app/src/main/java/com/tangem/tap/domain/extensions/WalletManagerFactory.kt @@ -9,7 +9,6 @@ import com.tangem.common.card.EllipticCurve import com.tangem.common.extensions.hexToBytes import com.tangem.tap.domain.TapWorkarounds.isTestCard import com.tangem.tap.domain.tasks.product.ScanResponse -import com.tangem.tap.domain.twins.isTangemTwin fun WalletManagerFactory.makeWalletManagerForApp( card: Card, @@ -65,7 +64,7 @@ fun WalletManagerFactory.makePrimaryWalletManager( val publicKey = wallet?.publicKey ?: return null val curveToUse = wallet.curve - return if (card.isTangemTwin() && data.secondTwinPublicKey != null) { + return if (data.isTangemTwins() && data.secondTwinPublicKey != null) { makeMultisigWalletManager( cardId = card.cardId, walletPublicKey = publicKey, pairPublicKey = data.secondTwinPublicKey.hexToBytes(), diff --git a/app/src/main/java/com/tangem/tap/domain/tasks/ScanNoteTask.kt b/app/src/main/java/com/tangem/tap/domain/tasks/ScanNoteTask.kt index 8b3c26a91e..22a7e5ca87 100644 --- a/app/src/main/java/com/tangem/tap/domain/tasks/ScanNoteTask.kt +++ b/app/src/main/java/com/tangem/tap/domain/tasks/ScanNoteTask.kt @@ -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 { override fun run( @@ -38,13 +38,13 @@ class ScanNoteTask(val card: Card? = null) : CardSessionRunnable { 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 { 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 { 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 3818c4b211..fa6a74564b 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 @@ -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 { @@ -83,7 +76,7 @@ class ScanProductTask(val card: Card? = null) : CardSessionRunnable 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 { override fun proceed( card: Card, diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/DetailsFragment.kt b/app/src/main/java/com/tangem/tap/features/details/ui/DetailsFragment.kt index 81b6e91032..efa81149b7 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/DetailsFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/DetailsFragment.kt @@ -12,7 +12,6 @@ import com.tangem.tap.common.redux.global.GlobalAction import com.tangem.tap.common.redux.navigation.AppScreen import com.tangem.tap.common.redux.navigation.NavigationAction import com.tangem.tap.domain.twins.getTwinCardIdForUser -import com.tangem.tap.domain.twins.isTangemTwin import com.tangem.tap.features.details.redux.DetailsAction import com.tangem.tap.features.details.redux.DetailsState import com.tangem.tap.features.details.redux.SecurityOption @@ -69,8 +68,8 @@ class DetailsFragment : Fragment(R.layout.fragment_details), StoreSubscriber { if (action.remainingSignatures != null && - action.remainingSignatures <= WarningMessagesManager.REMAINING_SIGNATURES_WARNING + action.remainingSignatures <= WarningMessagesManager.REMAINING_SIGNATURES_WARNING ) { store.state.globalState.warningManager - ?.removeWarnings( - messageRes = R.string.warning_low_signatures_format - ) + ?.removeWarnings( + messageRes = R.string.warning_low_signatures_format + ) addWarningMessage( warning = WarningMessagesManager.remainingSignaturesNotEnough(action.remainingSignatures), @@ -81,7 +81,8 @@ class WarningsMiddleware { } private fun showCardWarningsIfNeeded(globalState: GlobalState?) { - globalState?.scanResponse?.card?.let { card -> + globalState?.scanResponse?.let { scanResponse -> + val card = scanResponse.card globalState.warningManager?.removeWarnings(WarningMessage.Origin.Local) if (card.isTestCard) { addWarningMessage(WarningMessagesManager.testCardWarning(), autoUpdate = true) @@ -92,7 +93,7 @@ class WarningsMiddleware { if (card.firmwareVersion.type != FirmwareVersion.FirmwareType.Release) { addWarningMessage(WarningMessagesManager.devCardWarning()) } else if (!preferencesStorage.usedCardsPrefStorage.wasScanned(card.cardId)) { - checkIfWarningNeeded(card)?.let { warning -> addWarningMessage(warning) } + checkIfWarningNeeded(scanResponse)?.let { warning -> addWarningMessage(warning) } } if (card.firmwareVersion.type == FirmwareVersion.FirmwareType.Release) { if (!globalState.cardVerifiedOnline) { @@ -106,7 +107,7 @@ class WarningsMiddleware { private fun showWarningLowRemainingSignaturesIfNeeded(card: Card) { val remainingSignatures = card.remainingSignatures if (remainingSignatures != null && - remainingSignatures <= WarningMessagesManager.REMAINING_SIGNATURES_WARNING + remainingSignatures <= WarningMessagesManager.REMAINING_SIGNATURES_WARNING ) { addWarningMessage( WarningMessagesManager.remainingSignaturesNotEnough( @@ -117,12 +118,12 @@ class WarningsMiddleware { } private fun checkIfWarningNeeded( - card: Card, + scanResponse: ScanResponse, ): WarningMessage? { - if (card.isTangemTwin()) return null + if (scanResponse.isTangemTwins()) return null - if (card.isMultiwalletAllowed) { - return if (card.hasSignedHashes()) { + if (scanResponse.card.isMultiwalletAllowed) { + return if (scanResponse.card.hasSignedHashes()) { WarningMessagesManager.signedHashesMultiWalletWarning() } else { store.dispatch(WalletAction.Warnings.CheckHashesCount.SaveCardId) @@ -133,7 +134,7 @@ class WarningsMiddleware { val validator = store.state.walletState.walletManagers.firstOrNull() as? SignatureCountValidator return if (validator == null) { - if (card.hasSignedHashes()) { + if (scanResponse.card.hasSignedHashes()) { WarningMessagesManager.alreadySignedHashesWarning() } else { store.dispatch(WalletAction.Warnings.CheckHashesCount.SaveCardId) @@ -149,10 +150,11 @@ class WarningsMiddleware { if (store.state.walletState.hashesCountVerified != false) return if (!NetworkConnectivity.getInstance().isOnlineOrConnecting()) return - val card = store.state.globalState.scanResponse?.card + val scanResponse = store.state.globalState.scanResponse + val card = scanResponse?.card if (card == null || preferencesStorage.usedCardsPrefStorage.wasScanned(card.cardId)) return - if (card.isTangemTwin() || card.isMultiwalletAllowed) return + if (scanResponse.isTangemTwins() || card.isMultiwalletAllowed) return val validator = store.state.walletState.walletManagers.firstOrNull() as? SignatureCountValidator