Updated on 2026-08-14

This commit is contained in:
Tangem 2022-12-14 17:07:56 +03:00
parent 1ce45be4a4
commit 28082f24d9
2 changed files with 23 additions and 4 deletions

View file

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

View file

@ -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<Unit> = 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)