From 438aecc1678b24534953a391fcfd12fc52ecdc65 Mon Sep 17 00:00:00 2001 From: Tangem Date: Fri, 5 May 2023 23:38:49 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../redux/WalletSelectorAction.kt | 2 + .../redux/WalletSelectorMiddleware.kt | 8 +++- .../redux/WalletSelectorReducer.kt | 1 + .../ui/WalletSelectorViewModel.kt | 6 ++- .../features/welcome/redux/WelcomeAction.kt | 2 + .../welcome/redux/WelcomeMiddleware.kt | 45 ++++++++++++------- .../features/welcome/ui/WelcomeViewModel.kt | 6 ++- core/res/src/main/res/values/strings.xml | 2 +- 8 files changed, 53 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/features/walletSelector/redux/WalletSelectorAction.kt b/app/src/main/java/com/tangem/tap/features/walletSelector/redux/WalletSelectorAction.kt index b41635abb0..e997860d4e 100644 --- a/app/src/main/java/com/tangem/tap/features/walletSelector/redux/WalletSelectorAction.kt +++ b/app/src/main/java/com/tangem/tap/features/walletSelector/redux/WalletSelectorAction.kt @@ -57,4 +57,6 @@ internal sealed interface WalletSelectorAction : Action { ) : WalletSelectorAction object CloseError : WalletSelectorAction + + object ClearUserWallets : WalletSelectorAction } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/walletSelector/redux/WalletSelectorMiddleware.kt b/app/src/main/java/com/tangem/tap/features/walletSelector/redux/WalletSelectorMiddleware.kt index 675ca89cdf..53cd284846 100644 --- a/app/src/main/java/com/tangem/tap/features/walletSelector/redux/WalletSelectorMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/walletSelector/redux/WalletSelectorMiddleware.kt @@ -7,8 +7,8 @@ import com.tangem.common.doOnSuccess import com.tangem.common.flatMap import com.tangem.common.map import com.tangem.core.analytics.Analytics -import com.tangem.domain.models.scan.ScanResponse import com.tangem.domain.common.util.UserWalletId +import com.tangem.domain.models.scan.ScanResponse import com.tangem.tap.common.analytics.events.AnalyticsParam import com.tangem.tap.common.analytics.events.Basic import com.tangem.tap.common.analytics.events.MyWallets @@ -81,6 +81,12 @@ internal class WalletSelectorMiddleware { is WalletSelectorAction.ChangeAppCurrency -> { refreshUserWalletsAmounts() } + is WalletSelectorAction.ClearUserWallets -> scope.launch { + clearUserWallets() + .doOnFailure { e -> + Timber.e(e, "Unable to clear user wallets") + } + } is WalletSelectorAction.AddWallet.Success, is WalletSelectorAction.AddWallet.Error, is WalletSelectorAction.SelectedWalletChanged, diff --git a/app/src/main/java/com/tangem/tap/features/walletSelector/redux/WalletSelectorReducer.kt b/app/src/main/java/com/tangem/tap/features/walletSelector/redux/WalletSelectorReducer.kt index 2d06b37937..2a8ace7ad3 100644 --- a/app/src/main/java/com/tangem/tap/features/walletSelector/redux/WalletSelectorReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/walletSelector/redux/WalletSelectorReducer.kt @@ -59,6 +59,7 @@ internal object WalletSelectorReducer { is WalletSelectorAction.SelectWallet, is WalletSelectorAction.RemoveWallets, is WalletSelectorAction.RenameWallet, + is WalletSelectorAction.ClearUserWallets, -> state } } diff --git a/app/src/main/java/com/tangem/tap/features/walletSelector/ui/WalletSelectorViewModel.kt b/app/src/main/java/com/tangem/tap/features/walletSelector/ui/WalletSelectorViewModel.kt index 99024dad35..5a947b1cbd 100644 --- a/app/src/main/java/com/tangem/tap/features/walletSelector/ui/WalletSelectorViewModel.kt +++ b/app/src/main/java/com/tangem/tap/features/walletSelector/ui/WalletSelectorViewModel.kt @@ -200,13 +200,17 @@ internal class WalletSelectorViewModel : ViewModel(), StoreSubscriber WarningModel.BiometricsDisabledWarning( - onConfirm = { /* [REDACTED_TODO_COMMENT] */ }, + onConfirm = this::clearUserWallets, onDismiss = this::dismissWarningDialog, ) else -> currentDialog } } + private fun clearUserWallets() { + store.dispatch(WalletSelectorAction.ClearUserWallets) + } + private fun dismissWarningDialog() { stateInternal.update { prevState -> prevState.copy( diff --git a/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeAction.kt b/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeAction.kt index 0d248ec7af..a0484fc798 100644 --- a/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeAction.kt +++ b/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeAction.kt @@ -18,4 +18,6 @@ internal sealed interface WelcomeAction : Action { data class HandleIntentIfNeeded(val intent: Intent?) : WelcomeAction object CloseError : WelcomeAction + + object ClearUserWallets : WelcomeAction } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeMiddleware.kt b/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeMiddleware.kt index 6e7da12221..5e242d9cec 100644 --- a/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeMiddleware.kt @@ -3,11 +3,14 @@ package com.tangem.tap.features.welcome.redux import android.content.Intent import com.tangem.common.core.TangemSdkError import com.tangem.common.doOnFailure +import com.tangem.common.doOnResult import com.tangem.common.doOnSuccess +import com.tangem.common.flatMap import com.tangem.domain.models.scan.ScanResponse import com.tangem.tap.common.analytics.events.AnalyticsParam import com.tangem.tap.common.analytics.events.Basic import com.tangem.tap.common.extensions.dispatchOnMain +import com.tangem.tap.common.extensions.dispatchWithMain import com.tangem.tap.common.extensions.onUserWalletSelected import com.tangem.tap.common.redux.AppState import com.tangem.tap.common.redux.navigation.AppScreen @@ -51,6 +54,9 @@ internal class WelcomeMiddleware { is WelcomeAction.HandleIntentIfNeeded -> { handleInitialIntent(action.intent) } + is WelcomeAction.ClearUserWallets -> { + clearUserWallets() + } is WelcomeAction.ProceedWithBiometrics.Error, is WelcomeAction.ProceedWithCard.Error, is WelcomeAction.ProceedWithBiometrics.Success, @@ -60,22 +66,31 @@ internal class WelcomeMiddleware { } } - private fun proceedWithBiometrics(state: WelcomeState) { - scope.launch { - userWalletsListManager.unlockIfLockable() - .doOnFailure { error -> - Timber.e(error, "Unable to unlock user wallets with biometrics") - store.dispatchOnMain(WelcomeAction.ProceedWithBiometrics.Error(error)) - } - .doOnSuccess { selectedUserWallet -> - store.dispatchOnMain(SignInAction.SetSignInType(Basic.SignedIn.SignInType.Biometric)) - store.dispatchOnMain(NavigationAction.NavigateTo(AppScreen.Wallet)) - store.dispatchOnMain(WelcomeAction.ProceedWithBiometrics.Success) - store.onUserWalletSelected(userWallet = selectedUserWallet) + private fun clearUserWallets() = scope.launch { + userWalletsListManager.clear() + .flatMap { tangemSdkManager.clearSavedUserCodes() } + .doOnFailure { e -> + Timber.e(e, "Unable to clear user wallets") + } + .doOnResult { + store.dispatchWithMain(NavigationAction.PopBackTo(AppScreen.Home)) + } + } - intentHandler.handleWalletConnectLink(state.intent) - } - } + private fun proceedWithBiometrics(state: WelcomeState) = scope.launch { + userWalletsListManager.unlockIfLockable() + .doOnFailure { error -> + Timber.e(error, "Unable to unlock user wallets with biometrics") + store.dispatchOnMain(WelcomeAction.ProceedWithBiometrics.Error(error)) + } + .doOnSuccess { selectedUserWallet -> + store.dispatchOnMain(SignInAction.SetSignInType(Basic.SignedIn.SignInType.Biometric)) + store.dispatchOnMain(NavigationAction.NavigateTo(AppScreen.Wallet)) + store.dispatchOnMain(WelcomeAction.ProceedWithBiometrics.Success) + store.onUserWalletSelected(userWallet = selectedUserWallet) + + intentHandler.handleWalletConnectLink(state.intent) + } } private fun proceedWithCard(state: WelcomeState) = scope.launch { diff --git a/app/src/main/java/com/tangem/tap/features/welcome/ui/WelcomeViewModel.kt b/app/src/main/java/com/tangem/tap/features/welcome/ui/WelcomeViewModel.kt index e19891caa2..ad39cbe5ae 100644 --- a/app/src/main/java/com/tangem/tap/features/welcome/ui/WelcomeViewModel.kt +++ b/app/src/main/java/com/tangem/tap/features/welcome/ui/WelcomeViewModel.kt @@ -72,7 +72,7 @@ internal class WelcomeViewModel : ViewModel(), StoreSubscriber { onDismiss = this::dismissWarning, ) is UserWalletsListError.BiometricsAuthenticationDisabled -> WarningModel.BiometricsDisabledWarning( - onConfirm = { /* [REDACTED_TODO_COMMENT] */ }, + onConfirm = this::clearUserWallets, onDismiss = this::dismissWarning, ) else -> null @@ -88,6 +88,10 @@ internal class WelcomeViewModel : ViewModel(), StoreSubscriber { closeError() } + private fun clearUserWallets() { + store.dispatch(WelcomeAction.ClearUserWallets) + } + private fun subscribeToStoreChanges() { store.subscribe(this) { appState -> appState.skip { old, new -> old.welcomeState == new.welcomeState } diff --git a/core/res/src/main/res/values/strings.xml b/core/res/src/main/res/values/strings.xml index eda6534993..0bf985e22a 100644 --- a/core/res/src/main/res/values/strings.xml +++ b/core/res/src/main/res/values/strings.xml @@ -27,7 +27,7 @@ Please scan the card Please try again in 30 seconds or scan the card Too many attempts - You have disabled biometric authentication on your phone and will not be able to save wallets in the app. To save wallets, please enable the biometric authentication function in your phone settings. You have disabled biometric authentication on your phone and will not be able to save wallets in the app. To save wallets, please enable the biometric authentication function in your phone settings. + You have disabled biometric authentication on your phone and will not be able to save wallets in the app. To save wallets, please enable the biometric authentication function in your phone settings. Disable this option if you don\'t want this card to be used to reset access codes on other cards of this wallet. Note that you will not be able to reset access code on this card as well. Allows you to use this card to reset access code on other cards in this wallet Disable the ability to reset access code on this card or other cards in this wallet