Updated on 2026-08-14
This commit is contained in:
parent
324f365771
commit
b91efa6730
10 changed files with 29 additions and 31 deletions
|
|
@ -40,6 +40,7 @@ internal class DefaultNetworksRepository(
|
|||
override fun getNetworkStatusesUpdates(
|
||||
userWalletId: UserWalletId,
|
||||
networks: Set<Network>,
|
||||
refresh: Boolean,
|
||||
): Flow<Set<NetworkStatus>> = channelFlow {
|
||||
launch(dispatchers.io) {
|
||||
networksStatusesStore.get(userWalletId)
|
||||
|
|
@ -47,7 +48,7 @@ internal class DefaultNetworksRepository(
|
|||
}
|
||||
|
||||
withContext(dispatchers.io) {
|
||||
fetchNetworksStatusesIfCacheExpired(userWalletId, networks, refresh = false)
|
||||
fetchNetworksStatusesIfCacheExpired(userWalletId, networks, refresh)
|
||||
}
|
||||
}.cancellable()
|
||||
|
||||
|
|
|
|||
|
|
@ -37,15 +37,17 @@ class GetCurrencyStatusUpdatesUseCase(
|
|||
operator fun invoke(
|
||||
userWalletId: UserWalletId,
|
||||
currencyId: CryptoCurrency.ID,
|
||||
refresh: Boolean,
|
||||
): Flow<Either<CurrencyStatusError, CryptoCurrencyStatus>> {
|
||||
return flow {
|
||||
emitAll(getCurrency(userWalletId, currencyId))
|
||||
emitAll(getCurrency(userWalletId, currencyId, refresh))
|
||||
}.flowOn(dispatchers.io)
|
||||
}
|
||||
|
||||
private suspend fun getCurrency(
|
||||
userWalletId: UserWalletId,
|
||||
currencyId: CryptoCurrency.ID,
|
||||
refresh: Boolean,
|
||||
): Flow<Either<CurrencyStatusError, CryptoCurrencyStatus>> {
|
||||
val operations = CurrenciesStatusesOperations(
|
||||
currenciesRepository = currenciesRepository,
|
||||
|
|
@ -54,7 +56,7 @@ class GetCurrencyStatusUpdatesUseCase(
|
|||
userWalletId = userWalletId,
|
||||
)
|
||||
|
||||
return operations.getCurrencyStatusFlow(currencyId).map { maybeCurrency ->
|
||||
return operations.getCurrencyStatusFlow(currencyId, refresh).map { maybeCurrency ->
|
||||
maybeCurrency.mapLeft(CurrenciesStatusesOperations.Error::mapToCurrencyError)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,13 +67,16 @@ internal class CurrenciesStatusesOperations(
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun getCurrencyStatusFlow(currencyId: CryptoCurrency.ID): Flow<Either<Error, CryptoCurrencyStatus>> {
|
||||
suspend fun getCurrencyStatusFlow(
|
||||
currencyId: CryptoCurrency.ID,
|
||||
refresh: Boolean = false,
|
||||
): Flow<Either<Error, CryptoCurrencyStatus>> {
|
||||
val currency = recover(
|
||||
block = { getMultiCurrencyWalletCurrency(currencyId) },
|
||||
recover = { return flowOf(it.left()) },
|
||||
)
|
||||
|
||||
return getCurrencyStatusFlow(currency)
|
||||
return getCurrencyStatusFlow(currency, refresh)
|
||||
}
|
||||
|
||||
suspend fun getNetworkCoinFlow(networkId: Network.ID): Flow<Either<Error, CryptoCurrencyStatus>> {
|
||||
|
|
@ -94,7 +97,10 @@ internal class CurrenciesStatusesOperations(
|
|||
return getCurrencyStatusFlow(currency)
|
||||
}
|
||||
|
||||
private fun getCurrencyStatusFlow(currency: CryptoCurrency): Flow<Either<Error, CryptoCurrencyStatus>> {
|
||||
private fun getCurrencyStatusFlow(
|
||||
currency: CryptoCurrency,
|
||||
refresh: Boolean = false,
|
||||
): Flow<Either<Error, CryptoCurrencyStatus>> {
|
||||
val (networks, currenciesIds) = getIds(nonEmptyListOf(currency))
|
||||
|
||||
val quoteFlow = getQuotes(currenciesIds)
|
||||
|
|
@ -105,7 +111,7 @@ internal class CurrenciesStatusesOperations(
|
|||
}
|
||||
}
|
||||
|
||||
val statusFlow = getNetworksStatuses(networks)
|
||||
val statusFlow = getNetworksStatuses(networks, refresh)
|
||||
.map { maybeStatuses ->
|
||||
maybeStatuses.flatMap { statuses ->
|
||||
statuses.singleOrNull { it.network == currency.network }?.right()
|
||||
|
|
@ -204,8 +210,11 @@ internal class CurrenciesStatusesOperations(
|
|||
.onEmpty { emit(Error.EmptyQuotes.left()) }
|
||||
}
|
||||
|
||||
private fun getNetworksStatuses(networks: NonEmptySet<Network>): Flow<Either<Error, Set<NetworkStatus>>> {
|
||||
return networksRepository.getNetworkStatusesUpdates(userWalletId, networks)
|
||||
private fun getNetworksStatuses(
|
||||
networks: NonEmptySet<Network>,
|
||||
refresh: Boolean = false,
|
||||
): Flow<Either<Error, Set<NetworkStatus>>> {
|
||||
return networksRepository.getNetworkStatusesUpdates(userWalletId, networks, refresh)
|
||||
.map<Set<NetworkStatus>, Either<Error, Set<NetworkStatus>>> { it.right() }
|
||||
.catch { emit(Error.DataError(it).left()) }
|
||||
.onEmpty { emit(Error.EmptyNetworksStatuses.left()) }
|
||||
|
|
|
|||
|
|
@ -16,9 +16,14 @@ interface NetworksRepository {
|
|||
*
|
||||
* @param userWalletId The unique identifier of the user wallet.
|
||||
* @param networks A set of network which statuses are to be retrieved.
|
||||
* @param refresh A boolean flag indicating whether the data should be refreshed from remote.
|
||||
* @return A [Flow] emitting a set of [NetworkStatus] objects corresponding to the specified networks.
|
||||
*/
|
||||
fun getNetworkStatusesUpdates(userWalletId: UserWalletId, networks: Set<Network>): Flow<Set<NetworkStatus>>
|
||||
fun getNetworkStatusesUpdates(
|
||||
userWalletId: UserWalletId,
|
||||
networks: Set<Network>,
|
||||
refresh: Boolean = false,
|
||||
): Flow<Set<NetworkStatus>>
|
||||
|
||||
/**
|
||||
* Retrieves network statuses of specified blockchain networks for a specific user wallet.
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ internal class MockNetworksRepository(
|
|||
override fun getNetworkStatusesUpdates(
|
||||
userWalletId: UserWalletId,
|
||||
networks: Set<Network>,
|
||||
refresh: Boolean,
|
||||
): Flow<Set<NetworkStatus>> {
|
||||
return statuses.map { it.getOrElse { e -> throw e } }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ sealed class TokenDetailsNotification(
|
|||
|
||||
data class ExistentialDeposit(
|
||||
private val existentialInfo: CryptoCurrencyWarning.ExistentialDeposit,
|
||||
private val onCloseClick: () -> Unit,
|
||||
) : TokenDetailsNotification(
|
||||
config = NotificationConfig(
|
||||
title = TextReference.Str("Existential Deposit"),
|
||||
|
|
@ -42,7 +41,6 @@ sealed class TokenDetailsNotification(
|
|||
formatArgs = wrappedList(existentialInfo.currencyName, existentialInfo.edStringValueWithSymbol),
|
||||
),
|
||||
iconResId = R.drawable.img_attention_20,
|
||||
onCloseClick = onCloseClick,
|
||||
),
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenDeta
|
|||
import com.tangem.feature.tokendetails.presentation.tokendetails.state.components.TokenDetailsNotification
|
||||
import com.tangem.feature.tokendetails.presentation.tokendetails.viewmodels.TokenDetailsClickIntents
|
||||
import com.tangem.utils.converter.Converter
|
||||
import com.tangem.utils.extensions.removeBy
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
||||
|
|
@ -18,12 +17,6 @@ internal class TokenDetailsNotificationConverter(
|
|||
return value.map(::mapToNotification).toImmutableList()
|
||||
}
|
||||
|
||||
fun removeExistentialDeposit(currentState: TokenDetailsState): ImmutableList<TokenDetailsNotification> {
|
||||
val newNotifications = currentState.notifications.toMutableList()
|
||||
newNotifications.removeBy { it is TokenDetailsNotification.ExistentialDeposit }
|
||||
return newNotifications.toImmutableList()
|
||||
}
|
||||
|
||||
fun getStateRentInfoVisibility(
|
||||
currentState: TokenDetailsState,
|
||||
isVisible: Boolean,
|
||||
|
|
@ -44,7 +37,6 @@ internal class TokenDetailsNotificationConverter(
|
|||
)
|
||||
is CryptoCurrencyWarning.ExistentialDeposit -> TokenDetailsNotification.ExistentialDeposit(
|
||||
existentialInfo = warning,
|
||||
onCloseClick = clickIntents::onCloseExistentialDepositNotification,
|
||||
)
|
||||
is CryptoCurrencyWarning.Rent -> TokenDetailsNotification.RentInfo(
|
||||
rentInfo = warning,
|
||||
|
|
|
|||
|
|
@ -210,11 +210,6 @@ internal class TokenDetailsStateFactory(
|
|||
return state.copy(notifications = notificationConverter.convert(warnings))
|
||||
}
|
||||
|
||||
fun getStateWithRemovedExistentialNotification(): TokenDetailsState {
|
||||
val state = currentStateProvider()
|
||||
return state.copy(notifications = notificationConverter.removeExistentialDeposit(state))
|
||||
}
|
||||
|
||||
fun getStateWithRemovedRentNotification(): TokenDetailsState {
|
||||
val state = currentStateProvider()
|
||||
return state.copy(notifications = notificationConverter.getStateRentInfoVisibility(state, false))
|
||||
|
|
|
|||
|
|
@ -29,6 +29,4 @@ interface TokenDetailsClickIntents {
|
|||
fun onDismissBottomSheet()
|
||||
|
||||
fun onCloseRentInfoNotification()
|
||||
|
||||
fun onCloseExistentialDepositNotification()
|
||||
}
|
||||
|
|
@ -148,6 +148,7 @@ internal class TokenDetailsViewModel @Inject constructor(
|
|||
getCurrencyStatusUpdatesUseCase(
|
||||
userWalletId = selectedWallet.walletId,
|
||||
currencyId = cryptoCurrency.id,
|
||||
refresh = true,
|
||||
)
|
||||
.distinctUntilChanged()
|
||||
.onEach { either ->
|
||||
|
|
@ -373,10 +374,6 @@ internal class TokenDetailsViewModel @Inject constructor(
|
|||
uiState = stateFactory.getStateWithClosedBottomSheet()
|
||||
}
|
||||
|
||||
override fun onCloseExistentialDepositNotification() {
|
||||
uiState = stateFactory.getStateWithRemovedExistentialNotification()
|
||||
}
|
||||
|
||||
override fun onCloseRentInfoNotification() {
|
||||
uiState = stateFactory.getStateWithRemovedRentNotification()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue