Updated on 2026-08-14
This commit is contained in:
parent
91ec85c3eb
commit
43d52e0b60
5 changed files with 30 additions and 12 deletions
|
|
@ -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,
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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<AppCurrency> = 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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue