Updated on 2026-08-14

This commit is contained in:
Tangem 2026-02-09 18:55:13 +03:00
parent 65a2f369c8
commit 481eb81f7a
2 changed files with 29 additions and 24 deletions

View file

@ -31,14 +31,10 @@ import com.tangem.hot.sdk.TangemHotSdk
import com.tangem.hot.sdk.model.HotAuth import com.tangem.hot.sdk.model.HotAuth
import com.tangem.hot.sdk.model.HotWalletId import com.tangem.hot.sdk.model.HotWalletId
import com.tangem.utils.coroutines.CoroutineDispatcherProvider import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.*
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.coroutines.suspendCancellableCoroutine
import javax.inject.Inject import javax.inject.Inject
import kotlin.coroutines.resume import kotlin.coroutines.resume
@ -220,19 +216,11 @@ internal class AccessCodeModel @Inject constructor(
} }
} }
/**
* Set access code for hot wallet
* !!! Be aware that order of operations is important here !!!
*/
private suspend fun setCodeOperation(userWallet: UserWallet.Hot, accessCode: String) { private suspend fun setCodeOperation(userWallet: UserWallet.Hot, accessCode: String) {
userWalletsListRepository.setLock(
userWalletId = userWallet.walletId,
lockMethod = UserWalletsListRepository.LockMethod.AccessCode(accessCode.toCharArray()),
)
if (walletsRepository.useBiometricAuthentication()) {
userWalletsListRepository.setLock(
userWalletId = userWallet.walletId,
lockMethod = UserWalletsListRepository.LockMethod.Biometric,
)
}
val unlockHotWallet = getHotWalletContextualUnlockUseCase(userWallet.hotWalletId) val unlockHotWallet = getHotWalletContextualUnlockUseCase(userWallet.hotWalletId)
.getOrNull() .getOrNull()
?: run { ?: run {
@ -243,22 +231,39 @@ internal class AccessCodeModel @Inject constructor(
hotWalletAccessor.unlockContextual(userWallet.hotWalletId) hotWalletAccessor.unlockContextual(userWallet.hotWalletId)
} }
var updatedHotWalletId = tangemHotSdk.changeAuth( val newHotWalletIdWithPass = tangemHotSdk.changeAuth(
unlockHotWallet = unlockHotWallet, unlockHotWallet = unlockHotWallet,
auth = HotAuth.Password(accessCode.toCharArray()), auth = HotAuth.Password(accessCode.toCharArray()),
) )
userWalletsListRepository.saveWithoutLock(
userWallet.copy(hotWalletId = newHotWalletIdWithPass),
canOverride = true,
)
userWalletsListRepository.setLock(
userWalletId = userWallet.walletId,
lockMethod = UserWalletsListRepository.LockMethod.AccessCode(accessCode.toCharArray()),
)
if (walletsRepository.requireAccessCode().not() && canUseBiometryUseCase()) { if (walletsRepository.requireAccessCode().not() && canUseBiometryUseCase()) {
updatedHotWalletId = tangemHotSdk.changeAuth( val newHotWalletIdWithBiometry = tangemHotSdk.changeAuth(
unlockHotWallet = unlockHotWallet, unlockHotWallet = unlockHotWallet,
auth = HotAuth.Biometry, auth = HotAuth.Biometry,
) )
userWalletsListRepository.saveWithoutLock(
userWallet.copy(hotWalletId = newHotWalletIdWithBiometry),
canOverride = true,
)
} }
userWalletsListRepository.saveWithoutLock( if (walletsRepository.useBiometricAuthentication()) {
userWallet.copy(hotWalletId = updatedHotWalletId), userWalletsListRepository.setLock(
canOverride = true, userWalletId = userWallet.walletId,
) lockMethod = UserWalletsListRepository.LockMethod.Biometric,
)
}
clearHotWalletContextualUnlockUseCase.invoke(params.userWalletId) clearHotWalletContextualUnlockUseCase.invoke(params.userWalletId)
} }

View file

@ -11,7 +11,7 @@ tangemCardSdk = "releases-5.33-576"
#tangemCardSdk = "0.0.1" # Keep it! - used for local builds ^ #tangemCardSdk = "0.0.1" # Keep it! - used for local builds ^
tangemVico = "2.0.0-alpha.25-tangem12" tangemVico = "2.0.0-alpha.25-tangem12"
#tangemVico = "0.0.1" # Keep it! - used for local builds ^ #tangemVico = "0.0.1" # Keep it! - used for local builds ^
tangemHotSdk = "develop-541" tangemHotSdk = "develop-545"
#tangemHotSdk = "0.0.1" # Keep it! - used for local builds ^ #tangemHotSdk = "0.0.1" # Keep it! - used for local builds ^