Updated on 2026-08-14

This commit is contained in:
Tangem 2021-10-22 03:14:09 +03:00
parent 66f7ab98e9
commit 913402bb7e
8 changed files with 50 additions and 57 deletions

View file

@ -47,7 +47,7 @@ private val globalMiddlewareHandler: Middleware<AppState> = { 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<AppState> = { 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<AppState> = { 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)

View file

@ -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<Card> {
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 <T : CommandResponse> runTaskAsync(
runnable: CardSessionRunnable<T>, cardId: String? = null, initialMessage: Message? = null,
): CompletionResult<T> =
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 <T : CommandResponse> runTaskAsyncReturnOnMain(
runnable: CardSessionRunnable<T>, 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 {

View file

@ -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 -> {

View file

@ -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(),

View file

@ -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<ScanResponse> {
override fun run(
@ -38,13 +38,13 @@ class ScanNoteTask(val card: Card? = null) : CardSessionRunnable<ScanResponse> {
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<ScanResponse> {
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 {

View file

@ -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<ScanResponse> {
@ -83,7 +76,7 @@ class ScanProductTask(val card: Card? = null) : CardSessionRunnable<ScanResponse
val commandProcessor = when {
TapWorkarounds.isTangemNote(card) -> 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<ScanResponse
}
}
private fun Card.isTangemTwins(): Boolean = TwinsHelper.getTwinCardNumber(cardId) != null
private class ScanNoteProcessor : ProductCommandProcessor<ScanResponse> {
override fun proceed(
card: Card,

View file

@ -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<Det
if (state.cardInfo != null) {
val cardId = if (state.card?.isTangemTwin() == true) {
state.card.getTwinCardIdForUser()
val cardId = if (state.isTangemTwins) {
state.card?.getTwinCardIdForUser()
} else {
state.cardInfo.cardId
}
@ -79,8 +78,8 @@ class DetailsFragment : Fragment(R.layout.fragment_details), StoreSubscriber<Det
tv_signed_hashes.text = state.cardInfo.signedHashes.toString()
}
tv_signed_hashes.show(state.card?.isTangemTwin() != true)
tv_signed_hashes_title.show(state.card?.isTangemTwin() != true)
tv_signed_hashes.show(!state.isTangemTwins)
tv_signed_hashes_title.show(!state.isTangemTwins)
tv_disclaimer.setOnClickListener { store.dispatch(DetailsAction.ShowDisclaimer) }

View file

@ -17,7 +17,7 @@ import com.tangem.tap.domain.extensions.getSingleWallet
import com.tangem.tap.domain.extensions.hasSignedHashes
import com.tangem.tap.domain.extensions.remainingSignatures
import com.tangem.tap.domain.isMultiwalletAllowed
import com.tangem.tap.domain.twins.isTangemTwin
import com.tangem.tap.domain.tasks.product.ScanResponse
import com.tangem.tap.features.wallet.redux.WalletAction
import com.tangem.tap.network.NetworkConnectivity
import com.tangem.tap.preferencesStorage
@ -51,12 +51,12 @@ class WarningsMiddleware {
}
is WalletAction.Warnings.CheckRemainingSignatures -> {
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