diff --git a/app/src/main/java/com/tangem/tap/features/saveWallet/redux/SaveWalletMiddleware.kt b/app/src/main/java/com/tangem/tap/features/saveWallet/redux/SaveWalletMiddleware.kt index f68fa4579e..1a1bdd7dd9 100644 --- a/app/src/main/java/com/tangem/tap/features/saveWallet/redux/SaveWalletMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/saveWallet/redux/SaveWalletMiddleware.kt @@ -112,6 +112,7 @@ internal class SaveWalletMiddleware { // Enable saving access codes only if this is the first time user save the wallet if (isFirstSavedWallet) { + preferencesStorage.shouldSaveAccessCodes = true store.state.daggerGraphState.get(DaggerGraphState::cardSdkConfigRepository) .setAccessCodeRequestPolicy( isBiometricsRequestPolicy = userWallet.hasAccessCode, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletAlertState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletAlertState.kt index be52fb2220..97d4baa78c 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletAlertState.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletAlertState.kt @@ -2,12 +2,28 @@ package com.tangem.feature.wallet.presentation.wallet.state import androidx.compose.runtime.Immutable import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.feature.wallet.impl.R @Immutable internal sealed class WalletAlertState { + + abstract val title: TextReference? + abstract val message: TextReference + open val confirmButtonText: TextReference = resourceReference(id = R.string.common_ok) + open val isWarningConfirmButton: Boolean = false + abstract val onConfirmClick: (() -> Unit)? + data class DefaultAlert( - val title: TextReference, - val message: TextReference, - val onActionClick: (() -> Unit)?, + override val title: TextReference, + override val message: TextReference, + override val onConfirmClick: (() -> Unit)?, ) : WalletAlertState() + + data class RemoveWalletAlert(override val onConfirmClick: (() -> Unit)?) : WalletAlertState() { + override val title: TextReference? = null + override val message: TextReference = resourceReference(id = R.string.user_wallet_list_delete_prompt) + override val confirmButtonText: TextReference = resourceReference(id = R.string.common_delete) + override val isWarningConfirmButton: Boolean = true + } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletEvent.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletEvent.kt index 16cfffd301..9c619d9a9c 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletEvent.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletEvent.kt @@ -12,11 +12,7 @@ internal sealed class WalletEvent { data class ShowToast(val text: TextReference) : WalletEvent() - data class ShowAlert( - val title: TextReference, - val message: TextReference, - val onActionClick: (() -> Unit)?, - ) : WalletEvent() + data class ShowAlert(val state: WalletAlertState) : WalletEvent() data class CopyAddress(val address: String, val toast: TextReference) : WalletEvent() diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletSkeletonStateConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletSkeletonStateConverter.kt index df44339b4d..4b26019576 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletSkeletonStateConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletSkeletonStateConverter.kt @@ -118,7 +118,7 @@ internal class WalletSkeletonStateConverter( additionalInfo = WalletAdditionalInfoFactory.resolve(wallet = this), imageResId = createImageResId(), onRenameClick = clickIntents::onRenameClick, - onDeleteClick = clickIntents::onDeleteClick, + onDeleteClick = clickIntents::onDeleteBeforeConfirmationClick, ) } @@ -129,7 +129,7 @@ internal class WalletSkeletonStateConverter( additionalInfo = if (isMultiCurrency) WalletAdditionalInfoFactory.resolve(wallet = this) else null, imageResId = createImageResId(), onRenameClick = clickIntents::onRenameClick, - onDeleteClick = clickIntents::onDeleteClick, + onDeleteClick = clickIntents::onDeleteBeforeConfirmationClick, ) } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletAlert.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletAlert.kt index 77374812d7..1edcb46df5 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletAlert.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletAlert.kt @@ -9,23 +9,22 @@ import com.tangem.feature.wallet.impl.R import com.tangem.feature.wallet.presentation.wallet.state.WalletAlertState @Composable -internal fun WalletAlert(config: WalletAlertState, onDismiss: () -> Unit) { - when (config) { - is WalletAlertState.DefaultAlert -> { - DefaultAlert(config = config, onDismiss = onDismiss) - } - } +internal fun WalletAlert(state: WalletAlertState, onDismiss: () -> Unit) { + DefaultAlert(state = state, onDismiss = onDismiss) } @Composable -private fun DefaultAlert(config: WalletAlertState.DefaultAlert, onDismiss: () -> Unit) { +private fun DefaultAlert(state: WalletAlertState, onDismiss: () -> Unit) { val confirmButton: DialogButton val dismissButton: DialogButton? - if (config.onActionClick != null) { + + val onActionClick = state.onConfirmClick + if (onActionClick != null) { confirmButton = DialogButton( - title = stringResource(id = R.string.common_ok), + title = state.confirmButtonText.resolveReference(), + warning = state.isWarningConfirmButton, onClick = { - config.onActionClick.invoke() + onActionClick() onDismiss() }, ) @@ -35,16 +34,18 @@ private fun DefaultAlert(config: WalletAlertState.DefaultAlert, onDismiss: () -> ) } else { confirmButton = DialogButton( - title = stringResource(id = R.string.common_ok), + title = state.confirmButtonText.resolveReference(), + warning = state.isWarningConfirmButton, onClick = onDismiss, ) dismissButton = null } + BasicDialog( - message = config.message.resolveReference(), + message = state.message.resolveReference(), confirmButton = confirmButton, onDismissDialog = onDismiss, - title = config.title.resolveReference(), + title = state.title?.resolveReference(), dismissButton = dismissButton, ) } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletEventEffect.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletEventEffect.kt index efdc905452..ea7437eeb8 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletEventEffect.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletEventEffect.kt @@ -48,15 +48,7 @@ internal fun WalletEventEffect( clipboardManager.setText(AnnotatedString(value.address)) Toast.makeText(context, value.toast.resolveReference(resources), Toast.LENGTH_SHORT).show() } - is WalletEvent.ShowAlert -> { - onAlertConfigSet( - WalletAlertState.DefaultAlert( - title = value.title, - message = value.message, - onActionClick = value.onActionClick, - ), - ) - } + is WalletEvent.ShowAlert -> onAlertConfigSet(value.state) is WalletEvent.RateApp -> { val reviewManager = ReviewManagerFactory.create(context) val requestTask = reviewManager.requestReviewFlow() diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreen.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreen.kt index 76dc0bac3d..449909bf02 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreen.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreen.kt @@ -82,7 +82,7 @@ internal fun WalletScreen(state: WalletState) { ) alertConfig?.let { - WalletAlert(config = it, onDismiss = { alertConfig = null }) + WalletAlert(state = it, onDismiss = { alertConfig = null }) } } is WalletState.Initial -> Unit diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletClickIntents.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletClickIntents.kt index 63cfe9c54c..06fc109344 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletClickIntents.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletClickIntents.kt @@ -45,7 +45,9 @@ internal interface WalletClickIntents { fun onRenameClick(userWalletId: UserWalletId, name: String) - fun onDeleteClick(userWalletId: UserWalletId) + fun onDeleteBeforeConfirmationClick(userWalletId: UserWalletId) + + fun onDeleteAfterConfirmationClick(userWalletId: UserWalletId) fun onSingleCurrencySendClick(cryptoCurrencyStatus: CryptoCurrencyStatus? = null) diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt index e690d4303a..7f14b96010 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt @@ -752,7 +752,19 @@ internal class WalletViewModel @Inject constructor( } } - override fun onDeleteClick(userWalletId: UserWalletId) { + override fun onDeleteBeforeConfirmationClick(userWalletId: UserWalletId) { + uiState = stateFactory.getStateAndTriggerEvent( + state = uiState, + event = WalletEvent.ShowAlert( + state = WalletAlertState.RemoveWalletAlert( + onConfirmClick = { onDeleteAfterConfirmationClick(userWalletId) }, + ), + ), + setUiState = { uiState = it }, + ) + } + + override fun onDeleteAfterConfirmationClick(userWalletId: UserWalletId) { val state = uiState as? WalletState.ContentState ?: return viewModelScope.launch(dispatchers.io) { deleteWalletUseCase(userWalletId) @@ -820,29 +832,33 @@ internal class WalletViewModel @Inject constructor( val currency = cryptoCurrencyStatus.currency return if (currency is CryptoCurrency.Coin && !isCryptoCurrencyCoinCouldHide(userWalletId, currency)) { WalletEvent.ShowAlert( - title = resourceReference( - id = R.string.token_details_unable_hide_alert_title, - formatArgs = WrappedList(listOf(cryptoCurrencyStatus.currency.name)), - ), - message = resourceReference( - id = R.string.token_details_unable_hide_alert_message, - formatArgs = WrappedList( - listOf( - cryptoCurrencyStatus.currency.name, - cryptoCurrencyStatus.currency.network.name, + state = WalletAlertState.DefaultAlert( + title = resourceReference( + id = R.string.token_details_unable_hide_alert_title, + formatArgs = WrappedList(listOf(cryptoCurrencyStatus.currency.name)), + ), + message = resourceReference( + id = R.string.token_details_unable_hide_alert_message, + formatArgs = WrappedList( + listOf( + cryptoCurrencyStatus.currency.name, + cryptoCurrencyStatus.currency.network.name, + ), ), ), + onConfirmClick = null, ), - onActionClick = null, ) } else { WalletEvent.ShowAlert( - title = resourceReference( - id = R.string.token_details_hide_alert_title, - formatArgs = WrappedList(listOf(cryptoCurrencyStatus.currency.name)), + state = WalletAlertState.DefaultAlert( + title = resourceReference( + id = R.string.token_details_hide_alert_title, + formatArgs = WrappedList(listOf(cryptoCurrencyStatus.currency.name)), + ), + message = resourceReference(R.string.token_details_hide_alert_message), + onConfirmClick = { onPerformHideToken(cryptoCurrencyStatus) }, ), - message = resourceReference(R.string.token_details_hide_alert_message), - onActionClick = { onPerformHideToken(cryptoCurrencyStatus) }, ) } }