diff --git a/app/src/main/java/com/tangem/tap/LockUserWalletsTimer.kt b/app/src/main/java/com/tangem/tap/LockUserWalletsTimer.kt index e3d0a18067..4a26816830 100644 --- a/app/src/main/java/com/tangem/tap/LockUserWalletsTimer.kt +++ b/app/src/main/java/com/tangem/tap/LockUserWalletsTimer.kt @@ -11,6 +11,7 @@ import com.tangem.domain.settings.repositories.SettingsRepository import com.tangem.domain.wallets.legacy.UserWalletsListManager import com.tangem.domain.wallets.legacy.asLockable import com.tangem.domain.core.wallets.UserWalletsListRepository +import com.tangem.domain.wallets.usecase.ClearAllHotWalletContextualUnlockUseCase import com.tangem.features.hotwallet.HotWalletFeatureToggles import com.tangem.tap.LockTimerWorker.Companion.TAG import com.tangem.tap.common.extensions.dispatchNavigationAction @@ -22,6 +23,7 @@ import timber.log.Timber import java.util.concurrent.TimeUnit import kotlin.time.Duration +@Suppress("LongParameterList") internal class LockUserWalletsTimer( private val context: Context, private val settingsRepository: SettingsRepository, @@ -30,6 +32,7 @@ internal class LockUserWalletsTimer( private val userWalletsListRepository: UserWalletsListRepository, private val hotWalletFeatureToggles: HotWalletFeatureToggles, private val coroutineScope: CoroutineScope, + private val clearAllHotWalletContextualUnlockUseCase: ClearAllHotWalletContextualUnlockUseCase, ) : LifecycleOwner by context as LifecycleOwner, DefaultLifecycleObserver { @@ -55,6 +58,9 @@ internal class LockUserWalletsTimer( ) if (shouldOpenWelcomeScreenOnResume) { + if (hotWalletFeatureToggles.isHotWalletEnabled) { + clearAllHotWalletContextualUnlockUseCase.invoke() + } store.dispatchNavigationAction { replaceAll(AppRoute.Welcome()) } settingsRepository.setShouldOpenWelcomeScreenOnResume(value = false) } @@ -120,6 +126,7 @@ internal class LockUserWalletsTimer( start() } .onRight { + clearAllHotWalletContextualUnlockUseCase.invoke() store.dispatchNavigationAction { replaceAll(AppRoute.Welcome()) } } } diff --git a/app/src/main/java/com/tangem/tap/MainActivity.kt b/app/src/main/java/com/tangem/tap/MainActivity.kt index 7217bbef8d..287b4a7688 100644 --- a/app/src/main/java/com/tangem/tap/MainActivity.kt +++ b/app/src/main/java/com/tangem/tap/MainActivity.kt @@ -50,6 +50,7 @@ import com.tangem.domain.staking.SendUnsubmittedHashesUseCase import com.tangem.domain.tokens.GetPolkadotCheckHasImmortalUseCase import com.tangem.domain.tokens.GetPolkadotCheckHasResetUseCase import com.tangem.domain.wallets.legacy.UserWalletsListManager +import com.tangem.domain.wallets.usecase.ClearAllHotWalletContextualUnlockUseCase import com.tangem.feature.wallet.presentation.wallet.analytics.WalletScreenAnalyticsEvent import com.tangem.features.hotwallet.HotWalletFeatureToggles import com.tangem.features.tangempay.TangemPayFeatureToggles @@ -186,6 +187,9 @@ class MainActivity : AppCompatActivity(), ActivityResultCallbackHolder { @Inject internal lateinit var hotWalletFeatureToggles: HotWalletFeatureToggles + @Inject + internal lateinit var clearAllHotWalletContextualUnlockUseCase: ClearAllHotWalletContextualUnlockUseCase + @Inject internal lateinit var tangemPayFeatureToggles: TangemPayFeatureToggles @@ -274,6 +278,7 @@ class MainActivity : AppCompatActivity(), ActivityResultCallbackHolder { coroutineScope = mainScope, userWalletsListRepository = userWalletsListRepository, hotWalletFeatureToggles = hotWalletFeatureToggles, + clearAllHotWalletContextualUnlockUseCase = clearAllHotWalletContextualUnlockUseCase, ) initIntentHandlers() diff --git a/app/src/main/java/com/tangem/tap/di/domain/WalletsDomainModule.kt b/app/src/main/java/com/tangem/tap/di/domain/WalletsDomainModule.kt index 0f1f035a13..c116c9d81f 100644 --- a/app/src/main/java/com/tangem/tap/di/domain/WalletsDomainModule.kt +++ b/app/src/main/java/com/tangem/tap/di/domain/WalletsDomainModule.kt @@ -384,6 +384,16 @@ internal object WalletsDomainModule { ) } + @Provides + @Singleton + fun providesGetHotWalletContextualUnlockUseCase( + hotWalletAccessor: HotWalletAccessor, + ): GetHotWalletContextualUnlockUseCase { + return GetHotWalletContextualUnlockUseCase( + hotWalletAccessor = hotWalletAccessor, + ) + } + @Provides @Singleton fun providesClearHotWalletContextualUnlockUseCase( @@ -394,6 +404,16 @@ internal object WalletsDomainModule { ) } + @Provides + @Singleton + fun providesClearAllHotWalletContextualUnlockUseCase( + hotWalletAccessor: HotWalletAccessor, + ): ClearAllHotWalletContextualUnlockUseCase { + return ClearAllHotWalletContextualUnlockUseCase( + hotWalletAccessor = hotWalletAccessor, + ) + } + @Provides @Singleton fun providesExportSeedPhraseUseCase(hotWalletAccessor: HotWalletAccessor): ExportSeedPhraseUseCase { diff --git a/data/wallets/src/main/java/com/tangem/data/wallets/hot/DefaultHotWalletAccessor.kt b/data/wallets/src/main/java/com/tangem/data/wallets/hot/DefaultHotWalletAccessor.kt index 70273f2684..33dc7635a7 100644 --- a/data/wallets/src/main/java/com/tangem/data/wallets/hot/DefaultHotWalletAccessor.kt +++ b/data/wallets/src/main/java/com/tangem/data/wallets/hot/DefaultHotWalletAccessor.kt @@ -52,6 +52,9 @@ class DefaultHotWalletAccessor @Inject constructor( } } + override fun getContextualUnlock(hotWalletId: HotWalletId): UnlockHotWallet? = + contextualUnlockHotWallet[hotWalletId] + override fun clearContextualUnlock(hotWalletId: HotWalletId) { contextualUnlockHotWallet[hotWalletId] = null scope.launch { @@ -59,6 +62,14 @@ class DefaultHotWalletAccessor @Inject constructor( } } + override fun clearAllContextualUnlock() { + val hotWalletsIds = contextualUnlockHotWallet.keys.toList() + contextualUnlockHotWallet.clear() + scope.launch { + hotWalletsIds.forEach { tangemHotSdk.clearUnlockContext(it) } + } + } + private suspend fun hotSdkRequest(hotWalletId: HotWalletId, block: suspend (unlock: UnlockHotWallet) -> T): T { val isAccessCodeRequired = walletsRepository.requireAccessCode() diff --git a/domain/wallets/src/main/java/com/tangem/domain/wallets/hot/HotWalletAccessor.kt b/domain/wallets/src/main/java/com/tangem/domain/wallets/hot/HotWalletAccessor.kt index f0297ced18..41fc7f5fcb 100644 --- a/domain/wallets/src/main/java/com/tangem/domain/wallets/hot/HotWalletAccessor.kt +++ b/domain/wallets/src/main/java/com/tangem/domain/wallets/hot/HotWalletAccessor.kt @@ -12,5 +12,9 @@ interface HotWalletAccessor { suspend fun unlockContextual(hotWalletId: HotWalletId): UnlockHotWallet + fun getContextualUnlock(hotWalletId: HotWalletId): UnlockHotWallet? + fun clearContextualUnlock(hotWalletId: HotWalletId) + + fun clearAllContextualUnlock() } \ No newline at end of file diff --git a/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/ClearAllHotWalletContextualUnlockUseCase.kt b/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/ClearAllHotWalletContextualUnlockUseCase.kt new file mode 100644 index 0000000000..0dddccd934 --- /dev/null +++ b/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/ClearAllHotWalletContextualUnlockUseCase.kt @@ -0,0 +1,16 @@ + +package com.tangem.domain.wallets.usecase + +import arrow.core.Either +import com.tangem.domain.wallets.hot.HotWalletAccessor + +class ClearAllHotWalletContextualUnlockUseCase( + private val hotWalletAccessor: HotWalletAccessor, +) { + + operator fun invoke(): Either { + return Either.catch { + hotWalletAccessor.clearAllContextualUnlock() + } + } +} \ No newline at end of file diff --git a/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/GetHotWalletContextualUnlockUseCase.kt b/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/GetHotWalletContextualUnlockUseCase.kt new file mode 100644 index 0000000000..629c4cad06 --- /dev/null +++ b/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/GetHotWalletContextualUnlockUseCase.kt @@ -0,0 +1,17 @@ +package com.tangem.domain.wallets.usecase + +import arrow.core.Either +import com.tangem.domain.wallets.hot.HotWalletAccessor +import com.tangem.hot.sdk.model.HotWalletId +import com.tangem.hot.sdk.model.UnlockHotWallet + +class GetHotWalletContextualUnlockUseCase( + private val hotWalletAccessor: HotWalletAccessor, +) { + + suspend operator fun invoke(hotWalletId: HotWalletId): Either { + return Either.catch { + hotWalletAccessor.getContextualUnlock(hotWalletId) + } + } +} \ No newline at end of file diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/AccessCodeComponent.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/AccessCodeComponent.kt index 5a044f85ef..160d1a228f 100644 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/AccessCodeComponent.kt +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/AccessCodeComponent.kt @@ -34,12 +34,11 @@ internal class AccessCodeComponent @AssistedInject constructor( } interface ModelCallbacks { - fun onAccessCodeSet(userWalletId: UserWalletId, accessCode: String) - fun onAccessCodeConfirmed(userWalletId: UserWalletId) + fun onNewAccessCodeInput(userWalletId: UserWalletId, accessCode: String) + fun onAccessCodeUpdated(userWalletId: UserWalletId) } data class Params( - val isConfirmMode: Boolean, val accessCodeToConfirm: String? = null, val userWalletId: UserWalletId, val callbacks: ModelCallbacks, diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/AccessCodeModel.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/AccessCodeModel.kt index a3d0e3c9d7..e611297547 100644 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/AccessCodeModel.kt +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/accesscode/AccessCodeModel.kt @@ -16,11 +16,14 @@ import com.tangem.domain.settings.CanUseBiometryUseCase import com.tangem.domain.settings.SetAskBiometryShownUseCase import com.tangem.domain.settings.ShouldShowAskBiometryUseCase import com.tangem.domain.wallets.repository.WalletsRepository +import com.tangem.domain.wallets.usecase.ClearHotWalletContextualUnlockUseCase +import com.tangem.domain.wallets.usecase.GetHotWalletContextualUnlockUseCase import com.tangem.domain.wallets.usecase.GetUserWalletUseCase import com.tangem.features.hotwallet.accesscode.entity.AccessCodeUM import com.tangem.features.hotwallet.impl.R import com.tangem.hot.sdk.TangemHotSdk import com.tangem.hot.sdk.model.HotAuth +import com.tangem.hot.sdk.model.HotWalletId import com.tangem.hot.sdk.model.UnlockHotWallet import com.tangem.utils.coroutines.CoroutineDispatcherProvider import kotlinx.coroutines.flow.MutableStateFlow @@ -38,6 +41,8 @@ internal class AccessCodeModel @Inject constructor( paramsContainer: ParamsContainer, override val dispatchers: CoroutineDispatcherProvider, private val getUserWalletUseCase: GetUserWalletUseCase, + private val getHotWalletContextualUnlockUseCase: GetHotWalletContextualUnlockUseCase, + private val clearHotWalletContextualUnlockUseCase: ClearHotWalletContextualUnlockUseCase, private val userWalletsListRepository: UserWalletsListRepository, private val walletsRepository: WalletsRepository, private val tangemHotSdk: TangemHotSdk, @@ -49,13 +54,15 @@ internal class AccessCodeModel @Inject constructor( private val params = paramsContainer.require() + private var hotWalletId: HotWalletId? = null + internal val uiState: StateFlow field = MutableStateFlow(getInitialState()) private fun getInitialState() = AccessCodeUM( accessCode = "", onAccessCodeChange = ::onAccessCodeChange, - isConfirmMode = params.isConfirmMode, + isConfirmMode = params.accessCodeToConfirm != null, buttonEnabled = false, buttonInProgress = false, onButtonClick = ::onButtonClick, @@ -65,7 +72,7 @@ internal class AccessCodeModel @Inject constructor( uiState.update { it.copy( accessCode = value, - buttonEnabled = if (params.isConfirmMode) { + buttonEnabled = if (params.accessCodeToConfirm != null) { value == params.accessCodeToConfirm } else { value.length == uiState.value.accessCodeLength @@ -75,12 +82,10 @@ internal class AccessCodeModel @Inject constructor( } private fun onButtonClick() { - if (!params.isConfirmMode) { - params.callbacks.onAccessCodeSet(params.userWalletId, uiState.value.accessCode) + if (params.accessCodeToConfirm == null) { + params.callbacks.onNewAccessCodeInput(params.userWalletId, uiState.value.accessCode) } else { - params.accessCodeToConfirm?.let { - setCode(params.userWalletId, it) - } + setCode(params.userWalletId, params.accessCodeToConfirm) } } @@ -95,7 +100,9 @@ internal class AccessCodeModel @Inject constructor( .getOrElse { error("User wallet with id $userWalletId not found") } if (userWallet !is UserWallet.Hot) return@launch - val unlockHotWallet = UnlockHotWallet(userWallet.hotWalletId, HotAuth.NoAuth) + val unlockHotWallet = getHotWalletContextualUnlockUseCase(userWallet.hotWalletId) + .getOrNull() + ?: UnlockHotWallet(userWallet.hotWalletId, HotAuth.NoAuth) var updatedHotWalletId = tangemHotSdk.changeAuth( unlockHotWallet = unlockHotWallet, auth = HotAuth.Password(accessCode.toCharArray()), @@ -133,7 +140,7 @@ internal class AccessCodeModel @Inject constructor( ) } - params.callbacks.onAccessCodeConfirmed(params.userWalletId) + params.callbacks.onAccessCodeUpdated(params.userWalletId) }.onFailure { Timber.e(it) @@ -188,4 +195,9 @@ internal class AccessCodeModel @Inject constructor( return canUseBiometry && shouldShowAskBiometry } + + override fun onDestroy() { + hotWalletId?.let { clearHotWalletContextualUnlockUseCase.invoke(it) } + super.onDestroy() + } } \ No newline at end of file diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/addexistingwallet/entry/AddExistingWalletModel.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/addexistingwallet/entry/AddExistingWalletModel.kt index c562032c4a..b218fa6aea 100644 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/addexistingwallet/entry/AddExistingWalletModel.kt +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/addexistingwallet/entry/AddExistingWalletModel.kt @@ -127,11 +127,11 @@ internal class AddExistingWalletModel @Inject constructor( } inner class AccessCodeModelCallbacks : AccessCodeComponent.ModelCallbacks { - override fun onAccessCodeSet(userWalletId: UserWalletId, accessCode: String) { + override fun onNewAccessCodeInput(userWalletId: UserWalletId, accessCode: String) { stackNavigation.push(AddExistingWalletRoute.ConfirmAccessCode(userWalletId, accessCode)) } - override fun onAccessCodeConfirmed(userWalletId: UserWalletId) { + override fun onAccessCodeUpdated(userWalletId: UserWalletId) { navigateToPushNotificationsOrNext() } } diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/addexistingwallet/entry/routing/AddExistingWalletChildFactory.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/addexistingwallet/entry/routing/AddExistingWalletChildFactory.kt index de7e7a76f2..6393ff0d6d 100644 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/addexistingwallet/entry/routing/AddExistingWalletChildFactory.kt +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/addexistingwallet/entry/routing/AddExistingWalletChildFactory.kt @@ -46,7 +46,6 @@ internal class AddExistingWalletChildFactory @Inject constructor( is AddExistingWalletRoute.SetAccessCode -> accessCodeComponentFactory.create( context = childContext, params = AccessCodeComponent.Params( - isConfirmMode = false, userWalletId = route.userWalletId, callbacks = model.accessCodeModelCallbacks, ), @@ -54,7 +53,6 @@ internal class AddExistingWalletChildFactory @Inject constructor( is AddExistingWalletRoute.ConfirmAccessCode -> accessCodeComponentFactory.create( context = childContext, params = AccessCodeComponent.Params( - isConfirmMode = true, accessCodeToConfirm = route.accessCode, userWalletId = route.userWalletId, callbacks = model.accessCodeModelCallbacks, diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/updateaccesscode/UpdateAccessCodeModel.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/updateaccesscode/UpdateAccessCodeModel.kt index 19f8947793..5cf4e05649 100644 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/updateaccesscode/UpdateAccessCodeModel.kt +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/updateaccesscode/UpdateAccessCodeModel.kt @@ -35,11 +35,11 @@ internal class UpdateAccessCodeModel @Inject constructor( } } - override fun onAccessCodeSet(userWalletId: UserWalletId, accessCode: String) { + override fun onNewAccessCodeInput(userWalletId: UserWalletId, accessCode: String) { stackNavigation.push(UpdateAccessCodeRoute.ConfirmAccessCode(userWalletId, accessCode)) } - override fun onAccessCodeConfirmed(userWalletId: UserWalletId) { + override fun onAccessCodeUpdated(userWalletId: UserWalletId) { router.pop() } } \ No newline at end of file diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/updateaccesscode/routing/UpdateAccessCodeChildFactory.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/updateaccesscode/routing/UpdateAccessCodeChildFactory.kt index 354156a4c0..968560b8b3 100644 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/updateaccesscode/routing/UpdateAccessCodeChildFactory.kt +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/updateaccesscode/routing/UpdateAccessCodeChildFactory.kt @@ -19,7 +19,6 @@ internal class UpdateAccessCodeChildFactory @Inject constructor( is UpdateAccessCodeRoute.SetAccessCode -> accessCodeComponentFactory.create( context = childContext, params = AccessCodeComponent.Params( - isConfirmMode = false, userWalletId = route.userWalletId, callbacks = model, ), @@ -27,7 +26,6 @@ internal class UpdateAccessCodeChildFactory @Inject constructor( is UpdateAccessCodeRoute.ConfirmAccessCode -> accessCodeComponentFactory.create( context = childContext, params = AccessCodeComponent.Params( - isConfirmMode = true, accessCodeToConfirm = route.accessCode, userWalletId = route.userWalletId, callbacks = model, diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/updateaccesscode/routing/UpdateAccessCodeRoute.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/updateaccesscode/routing/UpdateAccessCodeRoute.kt index a414995364..31d9113158 100644 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/updateaccesscode/routing/UpdateAccessCodeRoute.kt +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/updateaccesscode/routing/UpdateAccessCodeRoute.kt @@ -7,8 +7,13 @@ import kotlinx.serialization.Serializable internal sealed class UpdateAccessCodeRoute : Route { @Serializable - data class SetAccessCode(val userWalletId: UserWalletId) : UpdateAccessCodeRoute() + data class SetAccessCode( + val userWalletId: UserWalletId, + ) : UpdateAccessCodeRoute() @Serializable - data class ConfirmAccessCode(val userWalletId: UserWalletId, val accessCode: String) : UpdateAccessCodeRoute() + data class ConfirmAccessCode( + val userWalletId: UserWalletId, + val accessCode: String, + ) : UpdateAccessCodeRoute() } \ No newline at end of file diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/walletactivation/entry/WalletActivationModel.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/walletactivation/entry/WalletActivationModel.kt index 722d2a7480..cfd50e4c72 100644 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/walletactivation/entry/WalletActivationModel.kt +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/walletactivation/entry/WalletActivationModel.kt @@ -141,11 +141,11 @@ internal class WalletActivationModel @Inject constructor( } inner class AccessCodeModelCallbacks : AccessCodeComponent.ModelCallbacks { - override fun onAccessCodeSet(userWalletId: UserWalletId, accessCode: String) { + override fun onNewAccessCodeInput(userWalletId: UserWalletId, accessCode: String) { stackNavigation.push(WalletActivationRoute.ConfirmAccessCode(accessCode)) } - override fun onAccessCodeConfirmed(userWalletId: UserWalletId) { + override fun onAccessCodeUpdated(userWalletId: UserWalletId) { navigateToPushNotificationsOrNext() } } diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/walletactivation/entry/routing/WalletActivationChildFactory.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/walletactivation/entry/routing/WalletActivationChildFactory.kt index e6c13bdbd9..77684cecdb 100644 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/walletactivation/entry/routing/WalletActivationChildFactory.kt +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/walletactivation/entry/routing/WalletActivationChildFactory.kt @@ -55,7 +55,6 @@ internal class WalletActivationChildFactory @Inject constructor( is WalletActivationRoute.SetAccessCode -> accessCodeComponentFactory.create( context = childContext, params = AccessCodeComponent.Params( - isConfirmMode = false, userWalletId = model.params.userWalletId, callbacks = model.accessCodeModelCallbacks, ), @@ -63,7 +62,6 @@ internal class WalletActivationChildFactory @Inject constructor( is WalletActivationRoute.ConfirmAccessCode -> accessCodeComponentFactory.create( context = childContext, params = AccessCodeComponent.Params( - isConfirmMode = true, accessCodeToConfirm = route.accessCode, userWalletId = model.params.userWalletId, callbacks = model.accessCodeModelCallbacks, diff --git a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/model/WalletSettingsModel.kt b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/model/WalletSettingsModel.kt index fac9ee92d6..3257456f21 100644 --- a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/model/WalletSettingsModel.kt +++ b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/model/WalletSettingsModel.kt @@ -46,6 +46,7 @@ import com.tangem.feature.walletsettings.utils.AccountItemsDelegate import com.tangem.feature.walletsettings.utils.ItemsBuilder import com.tangem.feature.walletsettings.utils.WalletCardItemDelegate import com.tangem.features.pushnotifications.api.analytics.PushNotificationAnalyticEvents +import com.tangem.hot.sdk.model.HotWalletId import com.tangem.utils.coroutines.CoroutineDispatcherProvider import kotlinx.collections.immutable.PersistentList import kotlinx.collections.immutable.persistentListOf @@ -57,7 +58,6 @@ import javax.inject.Inject @Suppress("LongParameterList", "LargeClass") @ModelScoped internal class WalletSettingsModel @Inject constructor( - getWalletUseCase: GetUserWalletUseCase, paramsContainer: ParamsContainer, private val router: Router, private val messageSender: UiMessageSender, @@ -73,6 +73,7 @@ internal class WalletSettingsModel @Inject constructor( private val enableWalletNFTUseCase: EnableWalletNFTUseCase, private val disableWalletNFTUseCase: DisableWalletNFTUseCase, getWalletNotificationsEnabledUseCase: GetWalletNotificationsEnabledUseCase, + private val getUserWalletUseCase: GetUserWalletUseCase, private val setNotificationsEnabledUseCase: SetNotificationsEnabledUseCase, private val settingsManager: SettingsManager, private val permissionsRepository: PermissionRepository, @@ -80,6 +81,7 @@ internal class WalletSettingsModel @Inject constructor( private val getIsHuaweiDeviceWithoutGoogleServicesUseCase: GetIsHuaweiDeviceWithoutGoogleServicesUseCase, private val isUpgradeWalletNotificationEnabledUseCase: IsUpgradeWalletNotificationEnabledUseCase, private val dismissUpgradeWalletNotificationUseCase: DismissUpgradeWalletNotificationUseCase, + private val unlockHotWalletContextualUseCase: UnlockHotWalletContextualUseCase, ) : Model() { val params: WalletSettingsComponent.Params = paramsContainer.require() @@ -144,7 +146,7 @@ internal class WalletSettingsModel @Inject constructor( ) } } - getWalletUseCase.invokeFlow(params.userWalletId) + getUserWalletUseCase.invokeFlow(params.userWalletId) .distinctUntilChanged() .filterIsInstance>() .flatMapLatest { combineUI(it.value) } @@ -361,7 +363,27 @@ internal class WalletSettingsModel @Inject constructor( if (!state.value.isWalletBackedUp) { messageSender.send(makeBackupAtFirstAlertBS) } else { - router.push(AppRoute.UpdateAccessCode(params.userWalletId)) + val userWallet = getUserWalletUseCase(params.userWalletId) + .getOrElse { error("User wallet with id ${params.userWalletId} not found") } + if (userWallet is UserWallet.Hot) { + val hotWalletId = userWallet.hotWalletId + when (hotWalletId.authType) { + HotWalletId.AuthType.NoPassword -> { + router.push(AppRoute.UpdateAccessCode(params.userWalletId)) + } + HotWalletId.AuthType.Password, + HotWalletId.AuthType.Biometry, + -> modelScope.launch { + unlockHotWalletContextualUseCase.invoke(hotWalletId) + .onLeft { + Timber.e("Unable to unlock wallet with id ${params.userWalletId}") + } + .onRight { + router.push(AppRoute.UpdateAccessCode(params.userWalletId)) + } + } + } + } } } diff --git a/gradle/tangem_dependencies.toml b/gradle/tangem_dependencies.toml index 80bdb6d116..4829355867 100644 --- a/gradle/tangem_dependencies.toml +++ b/gradle/tangem_dependencies.toml @@ -11,7 +11,7 @@ tangemCardSdk = "develop-561" #tangemCardSdk = "0.0.1" # Keep it! - used for local builds ^ tangemVico = "2.0.0-alpha.25-tangem12" #tangemVico = "0.0.1" # Keep it! - used for local builds ^ -tangemHotSdk = "develop-526" +tangemHotSdk = "develop-527" #tangemHotSdk = "0.0.1" # Keep it! - used for local builds ^