From 43d52e0b60cecd365c0123c425b152ed5789f96e Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 11 Oct 2023 17:35:02 +0300 Subject: [PATCH] Updated on 2026-08-14 --- core/res/src/main/res/values-ru/strings.xml | 3 +++ core/res/src/main/res/values/strings.xml | 3 +++ .../domain/tokens/GetCurrencyWarningsUseCase.kt | 14 ++++++++++++-- .../state/components/TokenDetailsNotification.kt | 7 ++++--- .../viewmodels/TokenDetailsViewModel.kt | 15 ++++++++------- 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/core/res/src/main/res/values-ru/strings.xml b/core/res/src/main/res/values-ru/strings.xml index fbfba50e2f..2250396755 100644 --- a/core/res/src/main/res/values-ru/strings.xml +++ b/core/res/src/main/res/values-ru/strings.xml @@ -569,10 +569,13 @@ Понятно! Очень круто! Сеть %1$s использует концепцию экзистенциального депозита. Если баланс вашего счета опустится ниже %2$s, он будет деактивирован, а все оставшиеся средства будут уничтожены. + Для работы с сетью необходим депозит. Эта карта может быть производственным образцом или подделкой Проверка подлинности не удалась Важная информация о безопасности %s На этой карте осталось только %s подписей. Вы должны вывести все свои средства. + В данный момент сеть недоступна. Пожалуйста, попробуйте позже. + Сеть недоступна. Как вам Tangem? Один вопрос Эта карта подписывала транзакции в прошлом diff --git a/core/res/src/main/res/values/strings.xml b/core/res/src/main/res/values/strings.xml index f6e5c92913..8b245bc9b9 100644 --- a/core/res/src/main/res/values/strings.xml +++ b/core/res/src/main/res/values/strings.xml @@ -589,10 +589,13 @@ Ok, Got it! Really cool! %1$s network has a concept of Existential Deposit. If your account drops below %2$s it will be deactivated and any remaining funds will be destroyed. + Network requires Existential Deposit This card might be a production sample or counterfeit Authenticity check failed Important security information %s There are only %s signatures available on this card. You must withdraw all of your funds. + The network is currently unreachable. Please try again later. + Network is unreachable How do you like Tangem? One question Rate the app diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt index b79ffa3f49..227161d34f 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt @@ -1,6 +1,7 @@ package com.tangem.domain.tokens import com.tangem.domain.tokens.model.CryptoCurrency +import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.model.Network import com.tangem.domain.tokens.model.warnings.CryptoCurrencyWarning import com.tangem.domain.tokens.operations.CurrenciesStatusesOperations @@ -23,10 +24,11 @@ class GetCurrencyWarningsUseCase( suspend operator fun invoke( userWalletId: UserWalletId, - currency: CryptoCurrency, + currencyStatus: CryptoCurrencyStatus, derivationPath: Network.DerivationPath, isSingleWalletWithTokens: Boolean, ): Flow> { + val currency = currencyStatus.currency return combine( getFeeWarningFlow( userWalletId = userWalletId, @@ -37,7 +39,8 @@ class GetCurrencyWarningsUseCase( ), flowOf(walletManagersFacade.getRentInfo(userWalletId, currency.network)), flowOf(walletManagersFacade.getExistentialDeposit(userWalletId, currency.network)), - ) { maybeFeeWarning, maybeRentWarning, maybeEdWarning -> + flowOf(getNetworkUnavailableWarning(currencyStatus)), + ) { maybeFeeWarning, maybeRentWarning, maybeEdWarning, maybeNetworkUnavailable -> setOfNotNull( maybeRentWarning, maybeEdWarning?.let { @@ -47,6 +50,7 @@ class GetCurrencyWarningsUseCase( ) }, maybeFeeWarning, + maybeNetworkUnavailable, ) }.flowOn(dispatchers.io) } @@ -96,6 +100,12 @@ class GetCurrencyWarningsUseCase( } } + private fun getNetworkUnavailableWarning(currencyStatus: CryptoCurrencyStatus): CryptoCurrencyWarning? { + return (currencyStatus.value as? CryptoCurrencyStatus.Unreachable)?.let { + CryptoCurrencyWarning.SomeNetworksUnreachable + } + } + private fun BigDecimal?.isZero(): Boolean { return this?.signum() == 0 } diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/components/TokenDetailsNotification.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/components/TokenDetailsNotification.kt index 13b31508f4..99d77114ba 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/components/TokenDetailsNotification.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/components/TokenDetailsNotification.kt @@ -4,6 +4,7 @@ import androidx.compose.runtime.Immutable import com.tangem.core.ui.components.notifications.NotificationConfig import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.networkIconResId +import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.extensions.wrappedList import com.tangem.domain.tokens.model.warnings.CryptoCurrencyWarning import com.tangem.features.tokendetails.impl.R @@ -33,7 +34,7 @@ sealed class TokenDetailsNotification( private val existentialInfo: CryptoCurrencyWarning.ExistentialDeposit, ) : TokenDetailsNotification( config = NotificationConfig( - title = TextReference.Str("Existential Deposit"), + title = resourceReference(R.string.warning_existential_deposit_title), subtitle = TextReference.Res( id = R.string.warning_existential_deposit_message, formatArgs = wrappedList(existentialInfo.currencyName, existentialInfo.edStringValueWithSymbol), @@ -71,8 +72,8 @@ sealed class TokenDetailsNotification( object NetworksUnreachable : TokenDetailsNotification( config = NotificationConfig( - title = TextReference.Str("Some networks are unreachable"), - subtitle = TextReference.Str("The problem is on the crypto-network side. It will be fixed soon."), + title = resourceReference(R.string.warning_network_unreachable_title), + subtitle = resourceReference(R.string.warning_network_unreachable_message), iconResId = R.drawable.img_attention_20, ), ) diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt index 6c131e438b..e11faf6b7d 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt @@ -21,13 +21,13 @@ import com.tangem.domain.tokens.legacy.TradeCryptoAction import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.models.analytics.TokenReceiveAnalyticsEvent +import com.tangem.domain.txhistory.usecase.GetExplorerTransactionUrlUseCase import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsCountUseCase import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsUseCase import com.tangem.domain.walletmanager.WalletManagersFacade import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.models.UserWalletId import com.tangem.domain.wallets.usecase.GetExploreUrlUseCase -import com.tangem.domain.txhistory.usecase.GetExplorerTransactionUrlUseCase import com.tangem.domain.wallets.usecase.GetUserWalletUseCase import com.tangem.feature.tokendetails.presentation.router.InnerTokenDetailsRouter import com.tangem.feature.tokendetails.presentation.tokendetails.analytics.TokenScreenEvent @@ -81,6 +81,7 @@ internal class TokenDetailsViewModel @Inject constructor( private val marketPriceJobHolder = JobHolder() private val refreshStateJobHolder = JobHolder() + private val warningsJobHolder = JobHolder() private var cryptoCurrencyStatus: CryptoCurrencyStatus? = null private val selectedAppCurrencyFlow: StateFlow = createSelectedAppCurrencyFlow() @@ -102,9 +103,8 @@ internal class TokenDetailsViewModel @Inject constructor( } private fun updateContent() { - updateMarketPrice() + subscribeOnCurrencyStatusUpdates() updateTxHistory(refresh = false, showItemsLoading = true) - updateWarnings() } private fun handleBalanceHiding(owner: LifecycleOwner) { @@ -132,22 +132,23 @@ internal class TokenDetailsViewModel @Inject constructor( .launchIn(viewModelScope) } - private fun updateWarnings() { + private fun updateWarnings(cryptoCurrencyStatus: CryptoCurrencyStatus) { viewModelScope.launch(dispatchers.io) { val wallet = getUserWalletUseCase(userWalletId).getOrElse { return@launch } getCurrencyWarningsUseCase.invoke( userWalletId = userWalletId, - currency = cryptoCurrency, + currencyStatus = cryptoCurrencyStatus, derivationPath = cryptoCurrency.network.derivationPath, isSingleWalletWithTokens = isSingleWalletWithTokens(wallet), ) .distinctUntilChanged() .onEach { uiState = stateFactory.getStateWithNotifications(it) } .launchIn(viewModelScope) + .saveIn(warningsJobHolder) } } - private fun updateMarketPrice() { + private fun subscribeOnCurrencyStatusUpdates() { viewModelScope.launch(dispatchers.io) { val wallet = getUserWalletUseCase(userWalletId).getOrElse { return@launch } getCurrencyStatusUpdatesUseCase( @@ -162,6 +163,7 @@ internal class TokenDetailsViewModel @Inject constructor( either.onRight { status -> cryptoCurrencyStatus = status updateButtons(userWalletId = userWalletId, currencyStatus = status) + updateWarnings(status) } } .flowOn(dispatchers.io) @@ -411,7 +413,6 @@ internal class TokenDetailsViewModel @Inject constructor( showItemsLoading = uiState.txHistoryState !is TxHistoryState.Content, ) }, - async { updateWarnings() }, ).awaitAll() uiState = stateFactory.getRefreshedState() }.saveIn(refreshStateJobHolder)