diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/wallet/model/TangemPayMainInfoManager.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/wallet/model/TangemPayMainInfoManager.kt index 184cc926bd..ee1c60aee1 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/wallet/model/TangemPayMainInfoManager.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/wallet/model/TangemPayMainInfoManager.kt @@ -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>?> - field = MutableStateFlow(null) + StateFlow>> + 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 } + } } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/TangemPayMainSubscriber.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/TangemPayMainSubscriber.kt index 0664439d54..4ba4c3e8f1 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/TangemPayMainSubscriber.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/TangemPayMainSubscriber.kt @@ -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) } } }