Updated on 2026-08-14

This commit is contained in:
Tangem 2025-11-19 09:28:57 +03:00
parent 6638da98f1
commit 4574975639
11 changed files with 130 additions and 22 deletions

View file

@ -0,0 +1,43 @@
package com.tangem.domain.wallets.usecase
import arrow.core.Either
import arrow.core.raise.either
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.error.UnlockWalletError
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.models.wallet.isLocked
import com.tangem.domain.wallets.repository.WalletsRepository
class NonBiometricUnlockWalletUseCase(
private val userWalletsListRepository: UserWalletsListRepository,
private val walletsRepository: WalletsRepository,
) {
suspend operator fun invoke(userWalletId: UserWalletId): Either<UnlockWalletError, Unit> = either {
val userWallet = userWalletsListRepository.userWalletsSync()
.find { it.walletId == userWalletId }
?: raise(UnlockWalletError.UserWalletNotFound)
if (!userWallet.isLocked) {
return@either
}
val method = when (userWallet) {
is UserWallet.Cold -> UserWalletsListRepository.UnlockMethod.Scan()
is UserWallet.Hot -> UserWalletsListRepository.UnlockMethod.AccessCode
}
userWalletsListRepository.unlock(userWalletId, method)
.onRight {
if (walletsRepository.useBiometricAuthentication()) {
// After successful unlock, set biometric lock if applicable
userWalletsListRepository.setLock(
userWalletId,
UserWalletsListRepository.LockMethod.Biometric,
)
}
}
.bind()
}
}

View file

@ -0,0 +1,18 @@
package com.tangem.domain.wallets.usecase
import arrow.core.Either
import arrow.core.raise.either
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.common.wallets.error.UnlockWalletError
import com.tangem.domain.models.wallet.UserWalletId
class UnlockWalletUseCase(
private val userWalletsListRepository: UserWalletsListRepository,
private val nonBiometricUnlockWalletUseCase: NonBiometricUnlockWalletUseCase,
) {
suspend operator fun invoke(userWalletId: UserWalletId): Either<UnlockWalletError, Unit> = either {
userWalletsListRepository.unlockAllWallets()
.mapLeft { nonBiometricUnlockWalletUseCase(userWalletId).bind() }
}
}

View file

@ -17,6 +17,7 @@ import com.tangem.domain.wallets.models.UnlockWalletsError
*
[REDACTED_AUTHOR]
*/
@Deprecated("Use NonBiometricUnlockWalletUseCase after migrating to new wallets repository")
class UnlockWalletsUseCase(private val userWalletsListManager: UserWalletsListManager) {
suspend operator fun invoke(type: UnlockType = UnlockType.ANY): Either<UnlockWalletsError, Unit> = either {