diff --git a/data/staking/src/main/java/com/tangem/data/staking/DefaultStakingRepository.kt b/data/staking/src/main/java/com/tangem/data/staking/DefaultStakingRepository.kt index efe1895104..2ccac4081b 100644 --- a/data/staking/src/main/java/com/tangem/data/staking/DefaultStakingRepository.kt +++ b/data/staking/src/main/java/com/tangem/data/staking/DefaultStakingRepository.kt @@ -50,9 +50,9 @@ import com.tangem.domain.walletmanager.WalletManagersFacade import com.tangem.domain.wallets.models.UserWalletId import com.tangem.domain.wallets.usecase.GetUserWalletUseCase import com.tangem.features.staking.api.featuretoggles.StakingFeatureToggles +import com.tangem.lib.crypto.BlockchainUtils.isSolana import com.tangem.utils.coroutines.CoroutineDispatcherProvider import com.tangem.utils.extensions.orZero -import com.tangem.lib.crypto.BlockchainUtils.isSolana import kotlinx.coroutines.flow.* import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -292,14 +292,18 @@ internal class DefaultStakingRepository( ) = withContext(dispatchers.io) { if (!stakingFeatureToggle.isStakingEnabled) return@withContext - val integrationId = integrationIdMap[getIntegrationKey(cryptoCurrency.id)] ?: return@withContext - - val address = walletManagersFacade.getDefaultAddress(userWalletId, cryptoCurrency.network).orEmpty() - cacheRegistry.invokeOnExpire( key = getYieldBalancesKey(userWalletId), skipCache = refresh, block = { + val integrationId = integrationIdMap[getIntegrationKey(cryptoCurrency.id)] + val address = walletManagersFacade.getDefaultAddress(userWalletId, cryptoCurrency.network) + + if (integrationId == null || address.isNullOrBlank()) { + cacheRegistry.invalidate(getYieldBalancesKey(userWalletId)) + error("IntegrationId or address is null") + } + val requestBody = getBalanceRequestData(address, integrationId) val result = stakeKitApi.getSingleYieldBalance( integrationId = requestBody.integrationId, @@ -307,10 +311,10 @@ internal class DefaultStakingRepository( ).getOrThrow() stakingBalanceStore.store( - userWalletId, - requestBody.integrationId, - address, - YieldBalanceWrapperDTO( + userWalletId = userWalletId, + integrationId = requestBody.integrationId, + address = address, + item = YieldBalanceWrapperDTO( balances = result, integrationId = requestBody.integrationId, addresses = requestBody.addresses, @@ -396,7 +400,10 @@ internal class DefaultStakingRepository( addresses.map { address -> address to integrationId } } .map { getBalanceRequestData(it.first.value, it.second) } - .ifEmpty { return@invokeOnExpire } + .ifEmpty { + cacheRegistry.invalidate(getYieldBalancesKey(userWalletId)) + error("No addresses found") + } val result = stakeKitApi.getMultipleYieldBalances(availableCurrencies).getOrThrow() stakingBalanceStore.store(userWalletId, result) diff --git a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/model/ManageTokensModel.kt b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/model/ManageTokensModel.kt index b72993de69..3c6a9b85bf 100644 --- a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/model/ManageTokensModel.kt +++ b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/model/ManageTokensModel.kt @@ -1,5 +1,6 @@ package com.tangem.features.managetokens.model +import androidx.annotation.StringRes import arrow.core.getOrElse import com.arkivanov.decompose.router.slot.SlotNavigation import com.arkivanov.decompose.router.slot.activate @@ -105,7 +106,7 @@ internal class ManageTokensModel @Inject constructor( onBackButtonClick = router::pop, ), search = SearchBarUM( - placeholderText = resourceReference(R.string.manage_tokens_search_placeholder), + placeholderText = resourceReference(R.string.common_search), query = "", onQueryChange = ::searchCurrencies, isActive = false, @@ -130,7 +131,7 @@ internal class ManageTokensModel @Inject constructor( ), ), search = SearchBarUM( - placeholderText = resourceReference(R.string.manage_tokens_search_placeholder), + placeholderText = resourceReference(R.string.common_search), query = "", onQueryChange = ::searchCurrencies, isActive = false, @@ -321,8 +322,15 @@ internal class ManageTokensModel @Inject constructor( private fun toggleSearchBar(isActive: Boolean) { state.update { state -> + @StringRes val placeholderTextRes = if (isActive) { + R.string.manage_tokens_search_placeholder + } else { + R.string.common_search + } + state.copySealed( search = state.search.copy( + placeholderText = resourceReference(placeholderTextRes), isActive = isActive, ), ) diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/tokenlist/impl/model/statemanager/MarketsListUMStateManager.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/tokenlist/impl/model/statemanager/MarketsListUMStateManager.kt index 65d8c2df96..66801cb9bd 100644 --- a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/tokenlist/impl/model/statemanager/MarketsListUMStateManager.kt +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/tokenlist/impl/model/statemanager/MarketsListUMStateManager.kt @@ -7,15 +7,14 @@ import com.tangem.core.ui.event.consumedEvent import com.tangem.core.ui.event.triggeredEvent import com.tangem.core.ui.extensions.resourceReference import com.tangem.features.markets.impl.R -import com.tangem.features.markets.tokenlist.impl.ui.state.SortByBottomSheetContentUM -import com.tangem.features.markets.tokenlist.impl.ui.state.ListUM -import com.tangem.features.markets.tokenlist.impl.ui.state.MarketsListItemUM -import com.tangem.features.markets.tokenlist.impl.ui.state.MarketsListUM -import com.tangem.features.markets.tokenlist.impl.ui.state.SortByTypeUM +import com.tangem.features.markets.tokenlist.impl.ui.state.* import com.tangem.utils.Provider import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.toImmutableList -import kotlinx.coroutines.flow.* +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.distinctUntilChanged +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.update @Stable internal class MarketsListUMStateManager( @@ -193,7 +192,7 @@ internal class MarketsListUMStateManager( private fun state(): MarketsListUM = MarketsListUM( list = ListUM.Loading, searchBar = SearchBarUM( - placeholderText = resourceReference(R.string.common_search), + placeholderText = resourceReference(R.string.markets_search_header_title), query = "", onQueryChange = { searchQuery = it }, isActive = false, diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/tokenlist/impl/ui/MarketsList.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/tokenlist/impl/ui/MarketsList.kt index 6847621b60..71d013cc58 100644 --- a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/tokenlist/impl/ui/MarketsList.kt +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/tokenlist/impl/ui/MarketsList.kt @@ -40,11 +40,11 @@ import com.tangem.features.markets.entry.BottomSheetState import com.tangem.features.markets.impl.R import com.tangem.features.markets.tokenlist.impl.ui.components.MarketsListLazyColumn import com.tangem.features.markets.tokenlist.impl.ui.components.MarketsListSortByBottomSheet +import com.tangem.features.markets.tokenlist.impl.ui.preview.MarketChartListItemPreviewDataProvider import com.tangem.features.markets.tokenlist.impl.ui.state.ListUM import com.tangem.features.markets.tokenlist.impl.ui.state.MarketsListUM import com.tangem.features.markets.tokenlist.impl.ui.state.SortByBottomSheetContentUM import com.tangem.features.markets.tokenlist.impl.ui.state.SortByTypeUM -import com.tangem.features.markets.tokenlist.impl.ui.preview.MarketChartListItemPreviewDataProvider import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toImmutableList @@ -310,7 +310,7 @@ private fun Preview() { onItemClick = {}, ), searchBar = SearchBarUM( - placeholderText = resourceReference(R.string.common_search), + placeholderText = resourceReference(R.string.markets_search_header_title), query = "", onQueryChange = {}, isActive = false,