diff --git a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultNetworksRepository.kt b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultNetworksRepository.kt index b8c62585a9..6f5615c1b6 100644 --- a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultNetworksRepository.kt +++ b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultNetworksRepository.kt @@ -40,6 +40,7 @@ internal class DefaultNetworksRepository( override fun getNetworkStatusesUpdates( userWalletId: UserWalletId, networks: Set, + refresh: Boolean, ): Flow> = 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() diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyStatusUpdatesUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyStatusUpdatesUseCase.kt index d018b74e85..f3cf282b1d 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyStatusUpdatesUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyStatusUpdatesUseCase.kt @@ -37,15 +37,17 @@ class GetCurrencyStatusUpdatesUseCase( operator fun invoke( userWalletId: UserWalletId, currencyId: CryptoCurrency.ID, + refresh: Boolean, ): Flow> { 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> { 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) } } diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrenciesStatusesOperations.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrenciesStatusesOperations.kt index fc4ec95f89..3a2327b7cd 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrenciesStatusesOperations.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrenciesStatusesOperations.kt @@ -67,13 +67,16 @@ internal class CurrenciesStatusesOperations( } } - suspend fun getCurrencyStatusFlow(currencyId: CryptoCurrency.ID): Flow> { + suspend fun getCurrencyStatusFlow( + currencyId: CryptoCurrency.ID, + refresh: Boolean = false, + ): Flow> { 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> { @@ -94,7 +97,10 @@ internal class CurrenciesStatusesOperations( return getCurrencyStatusFlow(currency) } - private fun getCurrencyStatusFlow(currency: CryptoCurrency): Flow> { + private fun getCurrencyStatusFlow( + currency: CryptoCurrency, + refresh: Boolean = false, + ): Flow> { 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): Flow>> { - return networksRepository.getNetworkStatusesUpdates(userWalletId, networks) + private fun getNetworksStatuses( + networks: NonEmptySet, + refresh: Boolean = false, + ): Flow>> { + return networksRepository.getNetworkStatusesUpdates(userWalletId, networks, refresh) .map, Either>> { it.right() } .catch { emit(Error.DataError(it).left()) } .onEmpty { emit(Error.EmptyNetworksStatuses.left()) } diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/NetworksRepository.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/NetworksRepository.kt index 30baab37f3..da67708111 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/NetworksRepository.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/NetworksRepository.kt @@ -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): Flow> + fun getNetworkStatusesUpdates( + userWalletId: UserWalletId, + networks: Set, + refresh: Boolean = false, + ): Flow> /** * Retrieves network statuses of specified blockchain networks for a specific user wallet. diff --git a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockNetworksRepository.kt b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockNetworksRepository.kt index ffefd750e0..363ad6202a 100644 --- a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockNetworksRepository.kt +++ b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockNetworksRepository.kt @@ -17,6 +17,7 @@ internal class MockNetworksRepository( override fun getNetworkStatusesUpdates( userWalletId: UserWalletId, networks: Set, + refresh: Boolean, ): Flow> { return statuses.map { it.getOrElse { e -> throw e } } } 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 070bc8d6dd..5d7693bd08 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 @@ -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, ), ) diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsNotificationConverter.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsNotificationConverter.kt index a379b3788f..25f691722d 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsNotificationConverter.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsNotificationConverter.kt @@ -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 { - 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, diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsStateFactory.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsStateFactory.kt index bf1c5a2ad0..40f0b4da65 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsStateFactory.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsStateFactory.kt @@ -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)) diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsClickIntents.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsClickIntents.kt index 9881457874..1adc6b021d 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsClickIntents.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsClickIntents.kt @@ -29,6 +29,4 @@ interface TokenDetailsClickIntents { fun onDismissBottomSheet() fun onCloseRentInfoNotification() - - fun onCloseExistentialDepositNotification() } \ No newline at end of file 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 2b0a8ff76e..f37726978c 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 @@ -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() }