Updated on 2026-08-14
This commit is contained in:
parent
668c886fb9
commit
4b97be34f3
2 changed files with 18 additions and 11 deletions
|
|
@ -7,6 +7,7 @@ import com.tangem.domain.pay.model.TangemPayCustomerInfoError
|
|||
import com.tangem.domain.pay.usecase.TangemPayMainScreenCustomerInfoUseCase
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
|
|
@ -16,11 +17,13 @@ internal class TangemPayMainInfoManager @Inject constructor(
|
|||
) {
|
||||
|
||||
val mainScreenCustomerInfo:
|
||||
StateFlow<Pair<UserWalletId, Either<TangemPayCustomerInfoError, MainScreenCustomerInfo>>?>
|
||||
field = MutableStateFlow(null)
|
||||
StateFlow<Map<UserWalletId, Either<TangemPayCustomerInfoError, MainScreenCustomerInfo>>>
|
||||
field = MutableStateFlow(mapOf())
|
||||
|
||||
suspend fun refreshTangemPayInfo(userWalletId: UserWalletId) {
|
||||
val info = tangemPayMainScreenCustomerInfoUseCase(userWalletId)
|
||||
mainScreenCustomerInfo.value = Pair(userWalletId, info)
|
||||
mainScreenCustomerInfo.update { currentMap ->
|
||||
val info = tangemPayMainScreenCustomerInfoUseCase(userWalletId)
|
||||
currentMap.toMutableMap().apply { this[userWalletId] = info }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -19,7 +19,10 @@ import dagger.assisted.Assisted
|
|||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import timber.log.Timber
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
|
|
@ -39,10 +42,11 @@ internal class TangemPayMainSubscriber @AssistedInject constructor(
|
|||
|
||||
private fun subscribeOnTangemPayInfoUpdates(): Flow<*> {
|
||||
return tangemPayMainInfoManager.mainScreenCustomerInfo
|
||||
.filterNotNull()
|
||||
.filter { it.first == userWallet.walletId }
|
||||
.filter { it.isNotEmpty() }
|
||||
.distinctUntilChanged()
|
||||
.onEach { (userWalletId, mainInfoData) ->
|
||||
.onEach { data ->
|
||||
val userWalletId = userWallet.walletId
|
||||
val mainInfoData = data[userWalletId] ?: return@onEach
|
||||
mainInfoData.onLeft { tangemPayError ->
|
||||
when (tangemPayError) {
|
||||
TangemPayCustomerInfoError.RefreshNeededError -> {
|
||||
|
|
@ -66,9 +70,9 @@ internal class TangemPayMainSubscriber @AssistedInject constructor(
|
|||
)
|
||||
}
|
||||
}
|
||||
}.onRight { data ->
|
||||
updateTangemPay(data, userWalletId)
|
||||
analytics.send(customerInfo = data)
|
||||
}.onRight { customerInfo ->
|
||||
updateTangemPay(customerInfo, userWalletId)
|
||||
analytics.send(customerInfo = customerInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue