diff --git a/features/welcome/impl/src/main/kotlin/com/tangem/features/welcome/impl/model/WelcomeModel.kt b/features/welcome/impl/src/main/kotlin/com/tangem/features/welcome/impl/model/WelcomeModel.kt index 0c6739540e..1901cc427a 100644 --- a/features/welcome/impl/src/main/kotlin/com/tangem/features/welcome/impl/model/WelcomeModel.kt +++ b/features/welcome/impl/src/main/kotlin/com/tangem/features/welcome/impl/model/WelcomeModel.kt @@ -67,6 +67,7 @@ internal class WelcomeModel @Inject constructor( ) private val walletsFetcherJobHolder = JobHolder() private val wallets = MutableStateFlow>(persistentListOf()) + private var routedOut = false init { modelScope.launch { @@ -87,6 +88,7 @@ internal class WelcomeModel @Inject constructor( if (canUnlockWithBiometrics()) { userWalletsListRepository.unlockAllWallets() .onRight { + routedOut = true router.replaceAll(AppRoute.Wallet) } .onLeft { @@ -100,16 +102,19 @@ internal class WelcomeModel @Inject constructor( } } - private fun tryToUnlockWithAccessCodeRightAway() = modelScope.launch { + private suspend fun tryToUnlockWithAccessCodeRightAway() { if (onlyOneHotWalletWithAccessCode()) { val userWallets = userWalletsListRepository.userWalletsSync() val userWallet = userWallets.first() + uiState.value = WelcomeUM.Empty unlockWallet(userWallet.walletId, UserWalletsListRepository.UnlockMethod.AccessCode) } } private fun setSelectWalletState() { modelScope.launch { + if (routedOut || uiState.value is WelcomeUM.SelectWallet) return@launch + uiState.value = WelcomeUM.SelectWallet( wallets = walletsFetcher.userWallets.first(), showUnlockWithBiometricButton = canUnlockWithBiometrics(), @@ -178,10 +183,14 @@ internal class WelcomeModel @Inject constructor( val unlockMethod = when (userWallet) { is UserWallet.Cold -> UserWalletsListRepository.UnlockMethod.Scan - is UserWallet.Hot -> UserWalletsListRepository.UnlockMethod.AccessCode + is UserWallet.Hot -> { + uiState.value = WelcomeUM.Empty + UserWalletsListRepository.UnlockMethod.AccessCode + } } unlockWallet(userWallet.walletId, unlockMethod) + setSelectWalletState() } private suspend fun canUnlockWithBiometrics(): Boolean { @@ -191,6 +200,7 @@ internal class WelcomeModel @Inject constructor( suspend fun unlockWallet(userWalletId: UserWalletId, unlockMethod: UserWalletsListRepository.UnlockMethod) { userWalletsListRepository.unlock(userWalletId, unlockMethod) .onRight { + routedOut = true userWalletsListRepository.select(userWalletId) router.replaceAll(AppRoute.Wallet) } @@ -199,7 +209,7 @@ internal class WelcomeModel @Inject constructor( } } - suspend fun UnlockWalletError.handle(specificWalletId: UserWalletId?, onUserCancelled: () -> Unit = { }) { + suspend fun UnlockWalletError.handle(specificWalletId: UserWalletId?, onUserCancelled: suspend () -> Unit = { }) { when (this) { UnlockWalletError.AlreadyUnlocked -> { // this should not happen, as we check for locked state before this diff --git a/features/welcome/impl/src/main/kotlin/com/tangem/features/welcome/impl/ui/Welcome.kt b/features/welcome/impl/src/main/kotlin/com/tangem/features/welcome/impl/ui/Welcome.kt index 3427544768..04b1e81910 100644 --- a/features/welcome/impl/src/main/kotlin/com/tangem/features/welcome/impl/ui/Welcome.kt +++ b/features/welcome/impl/src/main/kotlin/com/tangem/features/welcome/impl/ui/Welcome.kt @@ -35,6 +35,7 @@ internal fun Welcome(state: WelcomeUM, modifier: Modifier = Modifier) { state = st, modifier = modifier, ) + WelcomeUM.Empty -> {} } } } @@ -79,7 +80,8 @@ private fun Preview() { onClick = { currentState = when (currentState) { is WelcomeUM.Plain -> state - is WelcomeUM.SelectWallet -> WelcomeUM.Plain + is WelcomeUM.SelectWallet -> WelcomeUM.Empty + WelcomeUM.Empty -> WelcomeUM.Plain } }, ) { diff --git a/features/welcome/impl/src/main/kotlin/com/tangem/features/welcome/impl/ui/state/WelcomeUM.kt b/features/welcome/impl/src/main/kotlin/com/tangem/features/welcome/impl/ui/state/WelcomeUM.kt index 390446ba73..c86bd0befa 100644 --- a/features/welcome/impl/src/main/kotlin/com/tangem/features/welcome/impl/ui/state/WelcomeUM.kt +++ b/features/welcome/impl/src/main/kotlin/com/tangem/features/welcome/impl/ui/state/WelcomeUM.kt @@ -9,6 +9,8 @@ import kotlinx.collections.immutable.persistentListOf @Immutable internal sealed class WelcomeUM { + data object Empty : WelcomeUM() + data object Plain : WelcomeUM() data class SelectWallet(