Updated on 2026-08-14

This commit is contained in:
Tangem 2025-12-02 14:06:26 +03:00
parent 420eb2b246
commit 683525570c
4 changed files with 39 additions and 40 deletions

View file

@ -7,6 +7,7 @@ import com.tangem.common.extensions.toMapKey
import com.tangem.crypto.hdWallet.DerivationPath
import com.tangem.data.common.network.NetworkFactory
import com.tangem.data.wallets.derivations.MissedDerivationsFinder
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.network.Network
import com.tangem.domain.models.wallet.UserWallet
@ -21,6 +22,7 @@ import timber.log.Timber
import javax.inject.Inject
internal class DefaultHotMapDerivationsRepository @Inject constructor(
private val userWalletsStore: UserWalletsStore,
private val networkFactory: NetworkFactory,
private val hotWalletAccessor: HotWalletAccessor,
private val dispatchers: CoroutineDispatcherProvider,
@ -82,10 +84,15 @@ internal class DefaultHotMapDerivationsRepository @Inject constructor(
hotWalletId = userWallet.hotWalletId,
request = request,
)
// Get the updated user wallet from the store to ensure we have the latest data
// in case it was modified during the derive operation
val updatedUserWallet = userWalletsStore.getSyncStrict(userWallet.walletId) as UserWallet.Hot
val newKeys =
result.responses.associate { ByteArrayKey(it.seedKey.publicKey) to ExtendedPublicKeysMap(it.publicKeys) }
return userWallet.updateWithNewKeys(newKeys) to newKeys
return updatedUserWallet.updateWithNewKeys(newKeys) to newKeys
}
override suspend fun hasMissedDerivations(

View file

@ -11,6 +11,7 @@ import com.tangem.hot.sdk.TangemHotSdk
import com.tangem.hot.sdk.exception.WrongPasswordException
import com.tangem.hot.sdk.model.*
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import com.tangem.utils.coroutines.runSuspendCatching
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
@ -119,25 +120,27 @@ class DefaultHotWalletAccessor @Inject constructor(
originalAuth = auth,
auth = auth,
block = { blockAuth ->
block(blockAuth).also {
// Update biometry auth if the original auth was password
updateBiometryAuthIfNeeded(
hotWalletId = hotWalletId,
originalAuth = blockAuth,
)
}
val result = block(blockAuth)
// Update biometry auth if the original auth was password
updateBiometryAuthIfNeeded(
hotWalletId = hotWalletId,
originalAuth = auth,
)
result
},
)
}
private suspend fun updateBiometryAuthIfNeeded(hotWalletId: HotWalletId, originalAuth: HotAuth) {
val isAccessCodeRequired = walletsRepository.requireAccessCode()
val isUseBiometricAuthenticationEnabled = walletsRepository.useBiometricAuthentication()
if (originalAuth is HotAuth.Password && isAccessCodeRequired.not()) {
if (originalAuth is HotAuth.Password && isUseBiometricAuthenticationEnabled && isAccessCodeRequired.not()) {
val userWallet = userWalletsListRepository.userWalletsSync()
.find { it is UserWallet.Hot && it.hotWalletId == hotWalletId }
as? UserWallet.Hot
?: return
.first { it is UserWallet.Hot && it.hotWalletId == hotWalletId }
as UserWallet.Hot
val newHotWalletId = tangemHotSdk.changeAuth(
unlockHotWallet = UnlockHotWallet(
@ -161,7 +164,7 @@ class DefaultHotWalletAccessor @Inject constructor(
originalAuth: HotAuth,
auth: HotAuth,
block: suspend (auth: HotAuth) -> T,
): T = runCatching {
): T = runSuspendCatching {
block(auth)
}.getOrElse { exception ->
if (auth is HotAuth.Biometry && exception.isBiometryError()) {

View file

@ -28,7 +28,6 @@ import com.tangem.hot.sdk.model.HotAuth
import com.tangem.hot.sdk.model.HotWalletId
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
@ -152,11 +151,6 @@ internal class AccessCodeModel @Inject constructor(
tryToAskForBiometry()
userWalletsListRepository.saveWithoutLock(
userWallet.copy(backedUp = true),
canOverride = true,
)
userWalletsListRepository.setLock(
userWallet.walletId,
UserWalletsListRepository.LockMethod.AccessCode(accessCode.toCharArray()),
@ -179,30 +173,25 @@ internal class AccessCodeModel @Inject constructor(
hotWalletAccessor.unlockContextual(userWallet.hotWalletId)
}
launch(NonCancellable) {
var updatedHotWalletId = tangemHotSdk.changeAuth(
var updatedHotWalletId = tangemHotSdk.changeAuth(
unlockHotWallet = unlockHotWallet,
auth = HotAuth.Password(accessCode.toCharArray()),
)
if (walletsRepository.requireAccessCode().not()) {
updatedHotWalletId = tangemHotSdk.changeAuth(
unlockHotWallet = unlockHotWallet,
auth = HotAuth.Password(accessCode.toCharArray()),
auth = HotAuth.Biometry,
)
if (walletsRepository.requireAccessCode().not()) {
updatedHotWalletId = tangemHotSdk.changeAuth(
unlockHotWallet = unlockHotWallet,
auth = HotAuth.Biometry,
)
}
userWalletsListRepository.saveWithoutLock(
userWallet.copy(
hotWalletId = updatedHotWalletId,
backedUp = true,
),
canOverride = true,
)
clearHotWalletContextualUnlockUseCase.invoke(params.userWalletId)
}
userWalletsListRepository.saveWithoutLock(
userWallet.copy(hotWalletId = updatedHotWalletId),
canOverride = true,
)
clearHotWalletContextualUnlockUseCase.invoke(params.userWalletId)
params.callbacks.onAccessCodeUpdated(params.userWalletId)
}
}

View file

@ -11,7 +11,7 @@ tangemCardSdk = "develop-568"
#tangemCardSdk = "0.0.1" # Keep it! - used for local builds ^
tangemVico = "2.0.0-alpha.25-tangem12"
#tangemVico = "0.0.1" # Keep it! - used for local builds ^
tangemHotSdk = "develop-531"
tangemHotSdk = "develop-532"
#tangemHotSdk = "0.0.1" # Keep it! - used for local builds ^