From 26c2805f430cc1ffdd351e99badb0f6637076f53 Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 4 Oct 2023 13:39:06 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../tangem/data/card/DefaultCardRepository.kt | 10 +++------- .../state/components/WalletNotification.kt | 11 ++++------- .../wallet/viewmodels/WalletClickIntents.kt | 2 ++ .../WalletNotificationsListFactory.kt | 17 +++++++++++++---- .../wallet/viewmodels/WalletViewModel.kt | 9 +++++++++ 5 files changed, 31 insertions(+), 18 deletions(-) diff --git a/data/card/src/main/java/com/tangem/data/card/DefaultCardRepository.kt b/data/card/src/main/java/com/tangem/data/card/DefaultCardRepository.kt index 4c2cb66af4..6f4a1fb553 100644 --- a/data/card/src/main/java/com/tangem/data/card/DefaultCardRepository.kt +++ b/data/card/src/main/java/com/tangem/data/card/DefaultCardRepository.kt @@ -4,6 +4,7 @@ import com.tangem.datasource.local.card.UsedCardInfo import com.tangem.datasource.local.card.UsedCardsStore import com.tangem.domain.card.repository.CardRepository import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import com.tangem.utils.extensions.addOrReplace import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.channelFlow import kotlinx.coroutines.launch @@ -42,12 +43,7 @@ internal class DefaultCardRepository( } private fun List.updateCard(cardId: String): List { - return map { cardInfo -> - if (cardInfo.cardId == cardId) { - cardInfo.copy(isScanned = true) - } else { - cardInfo - } - } + val card = find { it.cardId == cardId } ?: UsedCardInfo(cardId = cardId, isScanned = true) + return addOrReplace(item = card.copy(isScanned = true), predicate = { it.cardId == cardId }) } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletNotification.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletNotification.kt index a3828feae4..3e8335d4bd 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletNotification.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletNotification.kt @@ -57,6 +57,7 @@ sealed class WalletNotification(val config: NotificationConfig) { subtitle: TextReference, buttonsState: NotificationConfig.ButtonsState? = null, onClick: (() -> Unit)? = null, + onCloseClick: (() -> Unit)? = null, ) : WalletNotification( config = NotificationConfig( title = title, @@ -64,6 +65,7 @@ sealed class WalletNotification(val config: NotificationConfig) { iconResId = R.drawable.img_attention_20, buttonsState = buttonsState, onClick = onClick, + onCloseClick = onCloseClick, ), ) { @@ -91,15 +93,10 @@ sealed class WalletNotification(val config: NotificationConfig) { subtitle = stringReference(value = errorMessage), ) - object NumberOfSignedHashesIncorrect : Warning( + data class NumberOfSignedHashesIncorrect(val onCloseClick: () -> Unit) : Warning( title = resourceReference(id = R.string.common_warning), subtitle = resourceReference(id = R.string.alert_card_signed_transactions), - ) - - data class MultiWalletSignedHashesIncorrect(val onClick: () -> Unit) : Warning( - title = resourceReference(id = R.string.common_warning), - subtitle = resourceReference(id = R.string.warning_signed_tx_previously), - onClick = onClick, + onCloseClick = onCloseClick, ) } 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 4e9831d070..63cfe9c54c 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 @@ -17,6 +17,8 @@ internal interface WalletClickIntents { fun onBackupCardClick() + fun onSignedHashesNotificationCloseClick() + fun onLikeAppClick() fun onDislikeAppClick() diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletNotificationsListFactory.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletNotificationsListFactory.kt index 40dbab847b..859b8ccf58 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletNotificationsListFactory.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletNotificationsListFactory.kt @@ -149,8 +149,14 @@ internal class WalletNotificationsListFactory( } addIf( - element = WalletNotification.Warning.NumberOfSignedHashesIncorrect, - condition = checkSignedHashes(cardTypesResolver, isDemo, wasCardScanned), + element = WalletNotification.Warning.NumberOfSignedHashesIncorrect( + onCloseClick = clickIntents::onSignedHashesNotificationCloseClick, + ), + condition = checkSignedHashes( + cardTypesResolver = cardTypesResolver, + isDemo = isDemo, + wasCardScanned = wasCardScanned, + ), ) } } @@ -171,13 +177,16 @@ internal class WalletNotificationsListFactory( ?.errorMessage } + /** + * Warning is being shown for single wallet cards only + */ private fun checkSignedHashes( cardTypesResolver: CardTypesResolver, isDemo: Boolean, wasCardScanned: Boolean, ): Boolean { - return cardTypesResolver.isReleaseFirmwareType() && cardTypesResolver.hasWalletSignedHashes() && !isDemo && - !wasCardScanned + return cardTypesResolver.isReleaseFirmwareType() && !cardTypesResolver.isTangemTwins() && + cardTypesResolver.hasWalletSignedHashes() && !isDemo && !wasCardScanned } private companion object { 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 35fd1201e5..3944531b1c 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 @@ -406,6 +406,15 @@ internal class WalletViewModel @Inject constructor( router.openOnboardingScreen() } + override fun onSignedHashesNotificationCloseClick() { + val state = uiState as? WalletState.ContentState ?: return + viewModelScope.launch(dispatchers.main) { + setCardWasScannedUseCase( + cardId = getWallet(index = state.walletsListConfig.selectedWalletIndex).cardId, + ) + } + } + override fun onLikeAppClick() { analyticsEventsHandler.send(WalletScreenAnalyticsEvent.NoticeRateAppButton(AnalyticsParam.RateApp.Liked)) uiState = stateFactory.getStateAndTriggerEvent(