Updated on 2026-08-14

This commit is contained in:
Tangem 2025-09-15 12:56:45 +03:00
parent 4d39c744a7
commit 2d79953060
6 changed files with 48 additions and 29 deletions

View file

@ -4,6 +4,7 @@ import arrow.core.Either
import arrow.core.left import arrow.core.left
import arrow.core.raise.either import arrow.core.raise.either
import arrow.core.right import arrow.core.right
import com.tangem.common.CompletionResult
import com.tangem.common.doOnFailure import com.tangem.common.doOnFailure
import com.tangem.common.doOnSuccess import com.tangem.common.doOnSuccess
import com.tangem.common.flatMap import com.tangem.common.flatMap
@ -210,6 +211,7 @@ internal class DefaultUserWalletsListRepository(
} }
} }
@Suppress("CyclomaticComplexMethod")
override suspend fun unlock( override suspend fun unlock(
userWalletId: UserWalletId, userWalletId: UserWalletId,
unlockMethod: UserWalletsListRepository.UnlockMethod, unlockMethod: UserWalletsListRepository.UnlockMethod,
@ -257,13 +259,19 @@ internal class DefaultUserWalletsListRepository(
raise(UnlockWalletError.UnableToUnlock) raise(UnlockWalletError.UnableToUnlock)
} }
} }
UserWalletsListRepository.UnlockMethod.Scan -> { is UserWalletsListRepository.UnlockMethod.Scan -> {
if (userWallet !is UserWallet.Cold) { if (userWallet !is UserWallet.Cold) {
raise(UnlockWalletError.UnableToUnlock) raise(UnlockWalletError.UnableToUnlock)
} }
tangemSdkManagerProvider().scanProduct() val scanResponse = unlockMethod.scanResponse ?: run {
.doOnSuccess { scanResponse -> val res = tangemSdkManagerProvider().scanProduct()
when (res) {
is CompletionResult.Failure -> raise(UnlockWalletError.UserCancelled)
is CompletionResult.Success -> res.data
}
}
val expectedId = UserWalletIdBuilder.scanResponse(scanResponse).build() val expectedId = UserWalletIdBuilder.scanResponse(scanResponse).build()
if (expectedId != userWallet.walletId) { if (expectedId != userWallet.walletId) {
@ -279,10 +287,6 @@ internal class DefaultUserWalletsListRepository(
.doOnSuccess { sensitiveInfo -> updateWallets { it?.updateWith(sensitiveInfo) } } .doOnSuccess { sensitiveInfo -> updateWallets { it?.updateWith(sensitiveInfo) } }
.doOnFailure { error -> raise(UnlockWalletError.UnableToUnlock) } .doOnFailure { error -> raise(UnlockWalletError.UnableToUnlock) }
} }
.doOnFailure {
raise(UnlockWalletError.UserCancelled)
}
}
} }
} }

View file

@ -7,6 +7,7 @@ import com.tangem.domain.core.wallets.error.SaveWalletError
import com.tangem.domain.core.wallets.error.SelectWalletError import com.tangem.domain.core.wallets.error.SelectWalletError
import com.tangem.domain.core.wallets.error.SetLockError import com.tangem.domain.core.wallets.error.SetLockError
import com.tangem.domain.core.wallets.error.UnlockWalletError import com.tangem.domain.core.wallets.error.UnlockWalletError
import com.tangem.domain.models.scan.ScanResponse
import com.tangem.domain.models.wallet.UserWallet import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId import com.tangem.domain.models.wallet.UserWalletId
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
@ -133,10 +134,10 @@ interface UserWalletsListRepository {
data object NoLock : LockMethod() data object NoLock : LockMethod()
} }
enum class UnlockMethod { sealed class UnlockMethod {
Biometric, data object Biometric : UnlockMethod()
AccessCode, data object AccessCode : UnlockMethod()
Scan, data class Scan(val scanResponse: ScanResponse? = null) : UnlockMethod()
} }
} }

View file

@ -140,13 +140,20 @@ internal class CreateWalletSelectionModel @Inject constructor(
return return
} }
saveWalletUseCase(userWallet).fold( saveWalletUseCase(userWallet = userWallet).fold(
ifLeft = { ifLeft = {
delay(HIDE_PROGRESS_DELAY) delay(HIDE_PROGRESS_DELAY)
setLoading(false) setLoading(false)
when (it) { when (it) {
is SaveWalletError.DataError -> Timber.e(it.toString(), "Unable to save user wallet") is SaveWalletError.DataError -> Timber.e(it.toString(), "Unable to save user wallet")
is SaveWalletError.WalletAlreadySaved -> appRouter.replaceAll(AppRoute.Wallet) is SaveWalletError.WalletAlreadySaved -> {
userWalletsListRepository.unlock(
userWalletId = userWallet.walletId,
unlockMethod = UserWalletsListRepository.UnlockMethod.Scan(scanResponse),
).onRight {
appRouter.replaceAll(AppRoute.Wallet)
}
}
} }
}, },
ifRight = { ifRight = {

View file

@ -146,7 +146,14 @@ internal class AddExistingWalletStartModel @Inject constructor(
setLoading(false) setLoading(false)
when (it) { when (it) {
is SaveWalletError.DataError -> Timber.e(it.toString(), "Unable to save user wallet") is SaveWalletError.DataError -> Timber.e(it.toString(), "Unable to save user wallet")
is SaveWalletError.WalletAlreadySaved -> appRouter.replaceAll(AppRoute.Wallet) is SaveWalletError.WalletAlreadySaved -> {
userWalletsListRepository.unlock(
userWalletId = userWallet.walletId,
unlockMethod = UserWalletsListRepository.UnlockMethod.Scan(scanResponse),
).onRight {
appRouter.replaceAll(AppRoute.Wallet)
}
}
} }
}, },
ifRight = { ifRight = {

View file

@ -178,7 +178,7 @@ internal class WalletWarningsClickIntentsImplementor @Inject constructor(
.onLeft { .onLeft {
val selectedUserWallet = getSelectedUserWallet() ?: return@onLeft val selectedUserWallet = getSelectedUserWallet() ?: return@onLeft
val method = when (selectedUserWallet) { val method = when (selectedUserWallet) {
is UserWallet.Cold -> UserWalletsListRepository.UnlockMethod.Scan is UserWallet.Cold -> UserWalletsListRepository.UnlockMethod.Scan()
is UserWallet.Hot -> UserWalletsListRepository.UnlockMethod.AccessCode is UserWallet.Hot -> UserWalletsListRepository.UnlockMethod.AccessCode
} }
userWalletsListRepository.unlock(stateHolder.getSelectedWalletId(), method) userWalletsListRepository.unlock(stateHolder.getSelectedWalletId(), method)

View file

@ -208,7 +208,7 @@ internal class WelcomeModel @Inject constructor(
} }
val unlockMethod = when (userWallet) { val unlockMethod = when (userWallet) {
is UserWallet.Cold -> UserWalletsListRepository.UnlockMethod.Scan is UserWallet.Cold -> UserWalletsListRepository.UnlockMethod.Scan()
is UserWallet.Hot -> { is UserWallet.Hot -> {
uiState.value = WelcomeUM.Empty uiState.value = WelcomeUM.Empty
UserWalletsListRepository.UnlockMethod.AccessCode UserWalletsListRepository.UnlockMethod.AccessCode