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()) {