Updated on 2026-08-14
This commit is contained in:
parent
ece6065010
commit
0fe533f267
3 changed files with 34 additions and 4 deletions
|
|
@ -32,6 +32,7 @@ import com.tangem.features.tangempay.model.transformers.*
|
|||
import com.tangem.features.tangempay.navigation.TangemPayDetailsInnerRoute
|
||||
import com.tangem.features.tangempay.utils.TangemPayMessagesFactory
|
||||
import com.tangem.features.tangempay.utils.TangemPayTxHistoryUiActions
|
||||
import com.tangem.features.tangempay.utils.TangemPayTxHistoryUpdateListener
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import com.tangem.utils.coroutines.JobHolder
|
||||
import com.tangem.utils.coroutines.saveIn
|
||||
|
|
@ -52,6 +53,7 @@ internal class TangemPayDetailsModel @Inject constructor(
|
|||
private val cardDetailsRepository: TangemPayCardDetailsRepository,
|
||||
private val uiMessageSender: UiMessageSender,
|
||||
private val cardDetailsEventListener: CardDetailsEventListener,
|
||||
private val txHistoryUpdateListener: TangemPayTxHistoryUpdateListener,
|
||||
) : Model(), TangemPayTxHistoryUiActions, AddFundsListener {
|
||||
|
||||
private val params: TangemPayDetailsContainerComponent.Params = paramsContainer.require()
|
||||
|
|
@ -187,8 +189,9 @@ internal class TangemPayDetailsModel @Inject constructor(
|
|||
|
||||
private fun onRefreshSwipe(refreshState: ShowRefreshState) {
|
||||
modelScope.launch {
|
||||
cardDetailsEventListener.send(CardDetailsEvent.Hide)
|
||||
uiState.update(TangemPayDetailsRefreshTransformer(isRefreshing = refreshState.value))
|
||||
cardDetailsEventListener.send(CardDetailsEvent.Hide)
|
||||
txHistoryUpdateListener.triggerUpdate()
|
||||
fetchBalance().join()
|
||||
uiState.update(TangemPayDetailsRefreshTransformer(isRefreshing = false))
|
||||
}.saveIn(refreshStateJobHolder)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import com.tangem.domain.tangempay.repository.TangemPayTxHistoryRepository
|
|||
import com.tangem.features.tangempay.components.txHistory.DefaultTangemPayTxHistoryComponent
|
||||
import com.tangem.features.tangempay.entity.TangemPayTxHistoryUM
|
||||
import com.tangem.features.tangempay.utils.TangemPayTxHistoryListManager
|
||||
import com.tangem.features.tangempay.utils.TangemPayTxHistoryUpdateListener
|
||||
import com.tangem.pagination.PaginationStatus
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
|
|
@ -19,10 +20,11 @@ import javax.inject.Inject
|
|||
@Stable
|
||||
@ModelScoped
|
||||
internal class TangemPayTxHistoryModel @Inject constructor(
|
||||
private val getBalanceHidingSettingsUseCase: GetBalanceHidingSettingsUseCase,
|
||||
override val dispatchers: CoroutineDispatcherProvider,
|
||||
tangemPayTxHistoryRepository: TangemPayTxHistoryRepository,
|
||||
paramsContainer: ParamsContainer,
|
||||
tangemPayTxHistoryRepository: TangemPayTxHistoryRepository,
|
||||
override val dispatchers: CoroutineDispatcherProvider,
|
||||
private val getBalanceHidingSettingsUseCase: GetBalanceHidingSettingsUseCase,
|
||||
private val txHistoryUpdateListener: TangemPayTxHistoryUpdateListener,
|
||||
) : Model() {
|
||||
|
||||
private val params: DefaultTangemPayTxHistoryComponent.Params = paramsContainer.require()
|
||||
|
|
@ -40,6 +42,7 @@ internal class TangemPayTxHistoryModel @Inject constructor(
|
|||
handleBalanceHiding()
|
||||
launchPagination()
|
||||
subscribeToUiItemChanges()
|
||||
subscribeToUpdateListener()
|
||||
}
|
||||
|
||||
private fun launchPagination() {
|
||||
|
|
@ -58,6 +61,12 @@ internal class TangemPayTxHistoryModel @Inject constructor(
|
|||
.launchIn(modelScope)
|
||||
}
|
||||
|
||||
private fun subscribeToUpdateListener() {
|
||||
txHistoryUpdateListener.updates
|
||||
.onEach { reload() }
|
||||
.launchIn(modelScope)
|
||||
}
|
||||
|
||||
private fun updateState(items: ImmutableList<TangemPayTxHistoryUM.TangemPayTxHistoryItemUM>) {
|
||||
if (items.isEmpty()) return // fast exit. If items is empty, no need to update ui items
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
package com.tangem.features.tangempay.utils
|
||||
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.receiveAsFlow
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
internal class TangemPayTxHistoryUpdateListener @Inject constructor() {
|
||||
|
||||
private val updateChannel = Channel<Unit>(Channel.BUFFERED)
|
||||
val updates: Flow<Unit> = updateChannel.receiveAsFlow()
|
||||
|
||||
suspend fun triggerUpdate() {
|
||||
updateChannel.send(Unit)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue