Updated on 2026-08-14

This commit is contained in:
Tangem 2024-09-08 11:16:10 +05:00
parent ad014930b2
commit db9990920e
15 changed files with 44 additions and 41 deletions

View file

@ -0,0 +1,15 @@
package com.tangem.core.ui.pullToRefresh
/**
* Pull to refresh config data
*
* @property isRefreshing state is indicator visible
* @property onRefresh lambda be invoked when pulled to refresh
*/
data class PullToRefreshConfig(val isRefreshing: Boolean, val onRefresh: (ShowRefreshState) -> Unit) {
@JvmInline
value class ShowRefreshState(
val value: Boolean = true,
)
}

View file

@ -12,10 +12,10 @@ import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.core.ui.extensions.stringReference
import com.tangem.core.ui.extensions.wrappedList
import com.tangem.core.ui.pullToRefresh.PullToRefreshConfig
import com.tangem.core.ui.res.TangemTheme
import com.tangem.feature.tokendetails.presentation.tokendetails.state.*
import com.tangem.feature.tokendetails.presentation.tokendetails.state.components.TokenDetailsActionButton
import com.tangem.feature.tokendetails.presentation.tokendetails.state.components.TokenDetailsPullToRefreshConfig
import com.tangem.features.tokendetails.impl.R
import kotlinx.collections.immutable.persistentListOf
import kotlinx.coroutines.flow.MutableStateFlow
@ -164,7 +164,7 @@ internal object TokenDetailsPreviewData {
onStakeClicked = {},
)
private val pullToRefreshConfig = TokenDetailsPullToRefreshConfig(
private val pullToRefreshConfig = PullToRefreshConfig(
isRefreshing = false,
onRefresh = {},
)

View file

@ -6,9 +6,9 @@ import com.tangem.core.ui.components.transactions.state.TransactionState
import com.tangem.core.ui.components.transactions.state.TxHistoryState
import com.tangem.core.ui.event.StateEvent
import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.pullToRefresh.PullToRefreshConfig
import com.tangem.feature.tokendetails.presentation.tokendetails.state.components.TokenDetailsDialogConfig
import com.tangem.feature.tokendetails.presentation.tokendetails.state.components.TokenDetailsNotification
import com.tangem.feature.tokendetails.presentation.tokendetails.state.components.TokenDetailsPullToRefreshConfig
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.PersistentList
@ -23,7 +23,7 @@ internal data class TokenDetailsState(
val swapTxs: PersistentList<SwapTransactionsState>,
val txHistoryState: TxHistoryState,
val dialogConfig: TokenDetailsDialogConfig?,
val pullToRefreshConfig: TokenDetailsPullToRefreshConfig,
val pullToRefreshConfig: PullToRefreshConfig,
val bottomSheetConfig: TangemBottomSheetConfig?,
val isBalanceHidden: Boolean,
val isMarketPriceAvailable: Boolean,

View file

@ -1,3 +0,0 @@
package com.tangem.feature.tokendetails.presentation.tokendetails.state.components
data class TokenDetailsPullToRefreshConfig(val isRefreshing: Boolean, val onRefresh: () -> Unit)

View file

@ -7,6 +7,7 @@ import com.tangem.core.ui.event.consumedEvent
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.pullToRefresh.PullToRefreshConfig
import com.tangem.core.ui.res.TangemTheme
import com.tangem.domain.card.NetworkHasDerivationUseCase
import com.tangem.domain.tokens.model.CryptoCurrency
@ -15,7 +16,6 @@ import com.tangem.domain.wallets.models.UserWalletId
import com.tangem.domain.wallets.usecase.GetUserWalletUseCase
import com.tangem.feature.tokendetails.presentation.tokendetails.state.*
import com.tangem.feature.tokendetails.presentation.tokendetails.state.components.TokenDetailsActionButton
import com.tangem.feature.tokendetails.presentation.tokendetails.state.components.TokenDetailsPullToRefreshConfig
import com.tangem.feature.tokendetails.presentation.tokendetails.viewmodels.TokenDetailsClickIntents
import com.tangem.features.tokendetails.featuretoggles.TokenDetailsFeatureToggles
import com.tangem.features.tokendetails.impl.R
@ -137,8 +137,8 @@ internal class TokenDetailsSkeletonStateConverter(
)
}
private fun createPullToRefresh(): TokenDetailsPullToRefreshConfig = TokenDetailsPullToRefreshConfig(
private fun createPullToRefresh(): PullToRefreshConfig = PullToRefreshConfig(
isRefreshing = false,
onRefresh = clickIntents::onRefreshSwipe,
onRefresh = { clickIntents.onRefreshSwipe(it.value) } ,
)
}

View file

@ -38,6 +38,7 @@ import com.tangem.core.ui.event.EventEffect
import com.tangem.core.ui.event.StateEvent
import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.extensions.resolveReference
import com.tangem.core.ui.pullToRefresh.PullToRefreshConfig
import com.tangem.core.ui.res.TangemTheme
import com.tangem.core.ui.res.TangemThemePreview
import com.tangem.feature.tokendetails.presentation.tokendetails.TokenDetailsPreviewData
@ -80,7 +81,7 @@ internal fun TokenDetailsScreen(state: TokenDetailsState, tokenMarketBlockCompon
) { scaffoldPaddings ->
val pullRefreshState = rememberPullRefreshState(
refreshing = state.pullToRefreshConfig.isRefreshing,
onRefresh = state.pullToRefreshConfig.onRefresh,
onRefresh = { state.pullToRefreshConfig.onRefresh(PullToRefreshConfig.ShowRefreshState()) } ,
)
val txHistoryItems = if (state.txHistoryState is TxHistoryState.Content) {

View file

@ -29,7 +29,7 @@ interface TokenDetailsClickIntents {
fun onHideConfirmed()
fun onRefreshSwipe()
fun onRefreshSwipe(isRefreshing: Boolean)
fun onBuyCoinClick(cryptoCurrency: CryptoCurrency)

View file

@ -711,7 +711,7 @@ internal class TokenDetailsViewModel @Inject constructor(
)
}
override fun onRefreshSwipe() {
override fun onRefreshSwipe(isRefreshing: Boolean) {
analyticsEventsHandler.send(TokenScreenAnalyticsEvent.Refreshed(cryptoCurrency.symbol))
internalUiState.value = stateFactory.getRefreshingState()

View file

@ -6,6 +6,7 @@ import com.tangem.core.ui.components.token.state.TokenItemState
import com.tangem.core.ui.event.consumedEvent
import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.extensions.stringReference
import com.tangem.core.ui.pullToRefresh.PullToRefreshConfig
import com.tangem.core.ui.utils.BigDecimalFormatter
import com.tangem.domain.wallets.models.UserWalletId
import com.tangem.feature.wallet.impl.R
@ -112,7 +113,7 @@ internal object WalletScreenPreviewData {
}
private val multiWalletState by lazy {
WalletState.MultiCurrency.Content(
pullToRefreshConfig = WalletPullToRefreshConfig(
pullToRefreshConfig = PullToRefreshConfig(
isRefreshing = false,
onRefresh = {},
),

View file

@ -1,15 +0,0 @@
package com.tangem.feature.wallet.presentation.wallet.state.model
/**
* Wallet screen top bar config
*
* @property isRefreshing state is indicator visible
* @property onRefresh lambda be invoked when pulled to refresh
*/
data class WalletPullToRefreshConfig(val isRefreshing: Boolean, val onRefresh: (ShowRefreshState) -> Unit) {
@JvmInline
value class ShowRefreshState(
val value: Boolean,
)
}

View file

@ -4,6 +4,7 @@ import androidx.compose.runtime.Immutable
import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig
import com.tangem.core.ui.components.marketprice.MarketPriceBlockState
import com.tangem.core.ui.components.transactions.state.TxHistoryState
import com.tangem.core.ui.pullToRefresh.PullToRefreshConfig
import com.tangem.feature.wallet.presentation.wallet.state.model.holder.LockedTxHistoryStateHolder
import com.tangem.feature.wallet.presentation.wallet.state.model.holder.LockedWalletStateHolder
import com.tangem.feature.wallet.presentation.wallet.state.model.holder.TxHistoryStateHolder
@ -22,7 +23,7 @@ internal sealed interface WalletState : WalletStateHolder {
abstract val manageTokensButtonConfig: ManageTokensButtonConfig?
data class Content(
override val pullToRefreshConfig: WalletPullToRefreshConfig,
override val pullToRefreshConfig: PullToRefreshConfig,
override val walletCardState: WalletCardState,
override val warnings: ImmutableList<WalletNotification>,
override val bottomSheetConfig: TangemBottomSheetConfig?,
@ -52,7 +53,7 @@ internal sealed interface WalletState : WalletStateHolder {
abstract val marketPriceBlockState: MarketPriceBlockState?
data class Content(
override val pullToRefreshConfig: WalletPullToRefreshConfig,
override val pullToRefreshConfig: PullToRefreshConfig,
override val walletCardState: WalletCardState,
override val warnings: ImmutableList<WalletNotification>,
override val bottomSheetConfig: TangemBottomSheetConfig?,
@ -84,7 +85,7 @@ internal sealed interface WalletState : WalletStateHolder {
abstract val balancesAndLimitBlockState: BalancesAndLimitsBlockState?
data class Content(
override val pullToRefreshConfig: WalletPullToRefreshConfig,
override val pullToRefreshConfig: PullToRefreshConfig,
override val walletCardState: WalletCardState,
override val warnings: ImmutableList<WalletNotification>,
override val bottomSheetConfig: TangemBottomSheetConfig?,

View file

@ -1,15 +1,15 @@
package com.tangem.feature.wallet.presentation.wallet.state.model.holder
import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig
import com.tangem.core.ui.pullToRefresh.PullToRefreshConfig
import com.tangem.feature.wallet.presentation.wallet.state.model.WalletCardState
import com.tangem.feature.wallet.presentation.wallet.state.model.WalletNotification
import com.tangem.feature.wallet.presentation.wallet.state.model.WalletPullToRefreshConfig
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
internal interface WalletStateHolder {
val pullToRefreshConfig: WalletPullToRefreshConfig
val pullToRefreshConfig: PullToRefreshConfig
val walletCardState: WalletCardState
val warnings: ImmutableList<WalletNotification>
val bottomSheetConfig: TangemBottomSheetConfig?
@ -21,8 +21,8 @@ internal class LockedWalletStateHolder(
onUnlockNotificationClick: () -> Unit,
) : WalletStateHolder {
override val pullToRefreshConfig: WalletPullToRefreshConfig
get() = WalletPullToRefreshConfig(isRefreshing = false, onRefresh = {})
override val pullToRefreshConfig: PullToRefreshConfig
get() = PullToRefreshConfig(isRefreshing = false, onRefresh = {})
override val warnings: ImmutableList<WalletNotification> = persistentListOf(
WalletNotification.UnlockWallets(onUnlockNotificationClick),

View file

@ -1,5 +1,6 @@
package com.tangem.feature.wallet.presentation.wallet.state.transformers
import com.tangem.core.ui.pullToRefresh.PullToRefreshConfig
import com.tangem.domain.wallets.models.UserWalletId
import com.tangem.feature.wallet.presentation.wallet.state.model.*
import kotlinx.collections.immutable.PersistentList
@ -38,7 +39,7 @@ internal class SetRefreshStateTransformer(
}
}
private fun WalletPullToRefreshConfig.toUpdatedState(isRefreshing: Boolean): WalletPullToRefreshConfig {
private fun PullToRefreshConfig.toUpdatedState(isRefreshing: Boolean): PullToRefreshConfig {
return copy(isRefreshing = isRefreshing)
}

View file

@ -2,6 +2,7 @@ package com.tangem.feature.wallet.presentation.wallet.state.utils
import com.tangem.core.ui.components.marketprice.MarketPriceBlockState
import com.tangem.core.ui.components.transactions.state.TxHistoryState
import com.tangem.core.ui.pullToRefresh.PullToRefreshConfig
import com.tangem.domain.common.util.cardTypesResolver
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.feature.wallet.presentation.wallet.domain.WalletAdditionalInfoFactory
@ -71,8 +72,8 @@ internal class WalletLoadingStateFactory(private val clickIntents: WalletClickIn
)
}
private fun createPullToRefreshConfig(): WalletPullToRefreshConfig {
return WalletPullToRefreshConfig(onRefresh = { clickIntents.onRefreshSwipe(it.value) }, isRefreshing = false)
private fun createPullToRefreshConfig(): PullToRefreshConfig {
return PullToRefreshConfig(onRefresh = { clickIntents.onRefreshSwipe(it.value) }, isRefreshing = false)
}
private fun UserWallet.toLoadingWalletCardState(): WalletCardState {

View file

@ -57,6 +57,7 @@ import com.tangem.core.ui.components.snackbar.CopiedTextSnackbar
import com.tangem.core.ui.components.snackbar.TangemSnackbar
import com.tangem.core.ui.components.transactions.state.TxHistoryState
import com.tangem.core.ui.event.StateEvent
import com.tangem.core.ui.pullToRefresh.PullToRefreshConfig
import com.tangem.core.ui.res.LocalMainBottomSheetColor
import com.tangem.core.ui.res.LocalWindowSize
import com.tangem.core.ui.res.TangemTheme
@ -305,7 +306,7 @@ private fun BaseScaffold(
val pullRefreshState = rememberPullRefreshState(
refreshing = selectedWallet.pullToRefreshConfig.isRefreshing,
onRefresh = {
selectedWallet.pullToRefreshConfig.onRefresh(WalletPullToRefreshConfig.ShowRefreshState(true))
selectedWallet.pullToRefreshConfig.onRefresh(PullToRefreshConfig.ShowRefreshState())
},
)
@ -426,7 +427,7 @@ private inline fun BaseScaffoldWithMarkets(
val pullRefreshState = rememberPullRefreshState(
refreshing = selectedWallet.pullToRefreshConfig.isRefreshing,
onRefresh = {
selectedWallet.pullToRefreshConfig.onRefresh(WalletPullToRefreshConfig.ShowRefreshState(true))
selectedWallet.pullToRefreshConfig.onRefresh(PullToRefreshConfig.ShowRefreshState())
},
)