From 28082f24d9d5857eb4237d96bb0a44e1eddb620e Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 14 Dec 2022 17:07:56 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../com/tangem/tap/domain/model/UserWallet.kt | 17 +++++++++++++++++ .../BiometricUserWalletsListManager.kt | 10 ++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/domain/model/UserWallet.kt b/app/src/main/java/com/tangem/tap/domain/model/UserWallet.kt index 3106bd1527..8c3403ede9 100644 --- a/app/src/main/java/com/tangem/tap/domain/model/UserWallet.kt +++ b/app/src/main/java/com/tangem/tap/domain/model/UserWallet.kt @@ -1,5 +1,6 @@ package com.tangem.tap.domain.model +import com.tangem.common.extensions.toHexString import com.tangem.domain.common.ScanResponse import com.tangem.domain.common.util.UserWalletId @@ -33,4 +34,20 @@ data class UserWallet( get() = scanResponse.card.wallets.isEmpty() internal var isSaved: Boolean = true +} + +/** + * !!! Workaround !!! + * + * Calculate same [UserWalletId] for twins instead + * */ +fun UserWallet.isTwinnedWith(other: UserWallet): Boolean { + if (!scanResponse.isTangemTwins()) return false + if (other.scanResponse.secondTwinPublicKey == scanResponse.card.wallets.firstOrNull()?.publicKey?.toHexString()) { + return true + } + if (scanResponse.secondTwinPublicKey == other.scanResponse.card.wallets.firstOrNull()?.publicKey?.toHexString()) { + return true + } + return false } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/domain/userWalletList/implementation/BiometricUserWalletsListManager.kt b/app/src/main/java/com/tangem/tap/domain/userWalletList/implementation/BiometricUserWalletsListManager.kt index 62f961e418..248719dd20 100644 --- a/app/src/main/java/com/tangem/tap/domain/userWalletList/implementation/BiometricUserWalletsListManager.kt +++ b/app/src/main/java/com/tangem/tap/domain/userWalletList/implementation/BiometricUserWalletsListManager.kt @@ -2,8 +2,8 @@ package com.tangem.tap.domain.userWalletList.implementation import com.tangem.common.* import com.tangem.domain.common.util.UserWalletId -import com.tangem.domain.common.util.encryptionKey import com.tangem.tap.domain.model.UserWallet +import com.tangem.tap.domain.model.isTwinnedWith import com.tangem.tap.domain.userWalletList.UserWalletListError import com.tangem.tap.domain.userWalletList.UserWalletsListManager import com.tangem.tap.domain.userWalletList.model.UserWalletEncryptionKey @@ -124,14 +124,16 @@ internal class BiometricUserWalletsListManager( ): CompletionResult = withUnlock { val isWalletSaved = state.value.wallets .filter { it.isSaved } - .flatMap(UserWallet::cardsInWallet) - .contains(userWallet.cardId) + .any { + // Workaround, check [UserWallet.isTwinnedWith] + it.cardsInWallet.contains(userWallet.cardId) || it.isTwinnedWith(userWallet) + } if (isWalletSaved && !canOverride) { CompletionResult.Failure(UserWalletListError.WalletAlreadySaved) } else { val newEncryptionKeys = state.value.encryptionKeys - .plus(UserWalletEncryptionKey(userWallet.walletId, userWallet.scanResponse.card.encryptionKey)) + .plus(UserWalletEncryptionKey(userWallet)) .distinctBy { it.walletId } keysRepository.store(newEncryptionKeys)