From 69298b05abf05546f442f2a2629d90449a522a36 Mon Sep 17 00:00:00 2001 From: Tangem Date: Fri, 15 Jul 2022 15:06:32 +0400 Subject: [PATCH 1/2] Updated on 2026-08-14 --- .../tangem/domain/common/TapWorkarounds.kt | 4 ++++ .../addCustomToken/redux/AddCustomTokenHub.kt | 9 ++++---- .../redux/AddCustomTokenState.kt | 21 ++++++++++++++----- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/domain/src/main/java/com/tangem/domain/common/TapWorkarounds.kt b/domain/src/main/java/com/tangem/domain/common/TapWorkarounds.kt index 644cc7525e..b556a3b1f8 100644 --- a/domain/src/main/java/com/tangem/domain/common/TapWorkarounds.kt +++ b/domain/src/main/java/com/tangem/domain/common/TapWorkarounds.kt @@ -32,6 +32,10 @@ object TapWorkarounds { DerivationStyle.NEW } + val Card.allowToAddCustomDerivation: Boolean + get() = useOldStyleDerivation || batchId == "AC03" + // To recover funds for users who scanned AC03 batch on old app version and got old style derivation + fun Card.isExcluded(): Boolean { val excludedBatch = excludedBatches.contains(batchId) val excludedIssuerName = excludedIssuers.contains(issuer.name.uppercase(Locale.ROOT)) diff --git a/domain/src/main/java/com/tangem/domain/features/addCustomToken/redux/AddCustomTokenHub.kt b/domain/src/main/java/com/tangem/domain/features/addCustomToken/redux/AddCustomTokenHub.kt index 9a4b0be414..60ce94068f 100644 --- a/domain/src/main/java/com/tangem/domain/features/addCustomToken/redux/AddCustomTokenHub.kt +++ b/domain/src/main/java/com/tangem/domain/features/addCustomToken/redux/AddCustomTokenHub.kt @@ -2,7 +2,6 @@ package com.tangem.domain.features.addCustomToken.redux import android.webkit.ValueCallback import com.tangem.blockchain.common.Blockchain -import com.tangem.blockchain.common.DerivationStyle import com.tangem.common.extensions.guard import com.tangem.common.services.Result import com.tangem.domain.AddCustomTokenError @@ -10,6 +9,7 @@ import com.tangem.domain.AddCustomTokenError.Warning.* import com.tangem.domain.AddCustomTokenException import com.tangem.domain.DomainDialog import com.tangem.domain.DomainWrapped +import com.tangem.domain.common.TapWorkarounds.allowToAddCustomDerivation import com.tangem.domain.common.TapWorkarounds.derivationStyle import com.tangem.domain.common.extensions.canHandleToken import com.tangem.domain.common.extensions.fromNetworkId @@ -572,9 +572,10 @@ private class AddCustomTokenReducer( ) var derivationPathState = state.screenState.derivationPath - derivationPathState = when (card.derivationStyle) { - DerivationStyle.LEGACY -> derivationPathState.copy(isVisible = true) - null, DerivationStyle.NEW -> derivationPathState.copy(isVisible = false) + derivationPathState = if (card.allowToAddCustomDerivation) { + derivationPathState.copy(isVisible = true) + } else { + derivationPathState.copy(isVisible = false) } val form = Form(AddCustomTokenState.createFormFields(card, CustomTokenType.Blockchain)) state.copy( diff --git a/domain/src/main/java/com/tangem/domain/features/addCustomToken/redux/AddCustomTokenState.kt b/domain/src/main/java/com/tangem/domain/features/addCustomToken/redux/AddCustomTokenState.kt index ed18fe69f5..97c652da19 100644 --- a/domain/src/main/java/com/tangem/domain/features/addCustomToken/redux/AddCustomTokenState.kt +++ b/domain/src/main/java/com/tangem/domain/features/addCustomToken/redux/AddCustomTokenState.kt @@ -50,7 +50,7 @@ data class AddCustomTokenState( fun blockchainToName(blockchain: Blockchain, isDerivationPath: Boolean = false): String? { return when { - isDerivationPath -> blockchain.derivationPath(cardDerivationStyle)?.rawPath + isDerivationPath -> blockchain.derivationPath(DerivationStyle.LEGACY)?.rawPath else -> { when (blockchain) { Blockchain.Unknown -> null @@ -150,10 +150,21 @@ data class AddCustomTokenState( mainNetwork: Blockchain, derivationNetwork: Blockchain, derivationStyle: DerivationStyle? - ): com.tangem.common.hdWallet.DerivationPath? = when (derivationNetwork) { - Blockchain.Unknown -> mainNetwork - else -> derivationNetwork - }.derivationPath(derivationStyle) + ): com.tangem.common.hdWallet.DerivationPath? { + // If we allow user to select derivations, we need to provide different derivations + // (Legacy style derivations). + // But the mainNetwork derivation depends on whether a user has a card + // with legacy derivations or new style derivations. + val derivationStyleToUse = if (derivationNetwork == Blockchain.Unknown) { + derivationStyle + } else { + DerivationStyle.LEGACY + } + return when (derivationNetwork) { + Blockchain.Unknown -> mainNetwork + else -> derivationNetwork + }.derivationPath(derivationStyleToUse) + } internal fun createFormFields(card: Card, type: CustomTokenType): List> { return listOf( From 795087e814ae0cc7cb5f035295a20475bb69cef2 Mon Sep 17 00:00:00 2001 From: Tangem Date: Fri, 15 Jul 2022 15:21:20 +0400 Subject: [PATCH 2/2] Updated on 2026-08-14 --- .../main/java/com/tangem/domain/common/TapWorkarounds.kt | 4 ---- .../features/addCustomToken/redux/AddCustomTokenHub.kt | 8 -------- 2 files changed, 12 deletions(-) diff --git a/domain/src/main/java/com/tangem/domain/common/TapWorkarounds.kt b/domain/src/main/java/com/tangem/domain/common/TapWorkarounds.kt index b556a3b1f8..644cc7525e 100644 --- a/domain/src/main/java/com/tangem/domain/common/TapWorkarounds.kt +++ b/domain/src/main/java/com/tangem/domain/common/TapWorkarounds.kt @@ -32,10 +32,6 @@ object TapWorkarounds { DerivationStyle.NEW } - val Card.allowToAddCustomDerivation: Boolean - get() = useOldStyleDerivation || batchId == "AC03" - // To recover funds for users who scanned AC03 batch on old app version and got old style derivation - fun Card.isExcluded(): Boolean { val excludedBatch = excludedBatches.contains(batchId) val excludedIssuerName = excludedIssuers.contains(issuer.name.uppercase(Locale.ROOT)) diff --git a/domain/src/main/java/com/tangem/domain/features/addCustomToken/redux/AddCustomTokenHub.kt b/domain/src/main/java/com/tangem/domain/features/addCustomToken/redux/AddCustomTokenHub.kt index 60ce94068f..1c09b4116a 100644 --- a/domain/src/main/java/com/tangem/domain/features/addCustomToken/redux/AddCustomTokenHub.kt +++ b/domain/src/main/java/com/tangem/domain/features/addCustomToken/redux/AddCustomTokenHub.kt @@ -9,7 +9,6 @@ import com.tangem.domain.AddCustomTokenError.Warning.* import com.tangem.domain.AddCustomTokenException import com.tangem.domain.DomainDialog import com.tangem.domain.DomainWrapped -import com.tangem.domain.common.TapWorkarounds.allowToAddCustomDerivation import com.tangem.domain.common.TapWorkarounds.derivationStyle import com.tangem.domain.common.extensions.canHandleToken import com.tangem.domain.common.extensions.fromNetworkId @@ -571,18 +570,11 @@ private class AddCustomTokenReducer( supportedTokenNetworkIds = supportedTokenNetworkIds ) - var derivationPathState = state.screenState.derivationPath - derivationPathState = if (card.allowToAddCustomDerivation) { - derivationPathState.copy(isVisible = true) - } else { - derivationPathState.copy(isVisible = false) - } val form = Form(AddCustomTokenState.createFormFields(card, CustomTokenType.Blockchain)) state.copy( cardDerivationStyle = card.derivationStyle, form = form, tangemTechServiceManager = tangemTechServiceManager, - screenState = state.screenState.copy(derivationPath = derivationPathState) ) } is OnDestroy -> {