NTP-39472 | pay to contacts VM scope fix (#15015)
This commit is contained in:
@@ -80,7 +80,7 @@ data class DefaultConfigContent(
|
||||
@SerializedName("frequentTransactionMaxColumns") val frequentTransactionsMaxColumns: Int = 4,
|
||||
@SerializedName("frequentTransactionTotalEntries")
|
||||
val frequentTransactionsTotalEntries: Int = 12,
|
||||
@SerializedName("frequentTransactionDays") val frequentTransactionsDays: Int = 60,
|
||||
@SerializedName("frequentTransactionDays") val frequentTransactionsDays: Int = 180,
|
||||
@SerializedName("frequentTransactionHeading")
|
||||
val frequentTransactionHeading: String = "Pay again",
|
||||
@SerializedName("upiAppLogoS3BaseUrl")
|
||||
|
||||
@@ -58,6 +58,7 @@ import javax.inject.Inject
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
@@ -244,70 +245,78 @@ constructor(
|
||||
)
|
||||
|
||||
init {
|
||||
updateNaviPaySessionId()
|
||||
updateNaviPayDefaultConfig()
|
||||
fetchFrequentOrders()
|
||||
observeAndHandleSearchResults()
|
||||
viewModelScope.launch(context = Dispatchers.IO) {
|
||||
initializeSynchronously()
|
||||
initializeAsynchronously()
|
||||
}
|
||||
}
|
||||
|
||||
private fun observeAndHandleSearchResults() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
combine(searchQuery, filteredContactList, filteredFrequentOrdersList) {
|
||||
searchQuery,
|
||||
filteredContactList,
|
||||
filteredFrequentOrdersList ->
|
||||
Triple(searchQuery, filteredContactList, filteredFrequentOrdersList)
|
||||
}
|
||||
.collectLatest { (searchQuery, filteredContactList, filteredFrequentOrdersList) ->
|
||||
updateShouldShowYourContactsTitle()
|
||||
updateIsWarningOrErrorState(
|
||||
isError = false,
|
||||
isWarning =
|
||||
filteredContactList.isEmpty() &&
|
||||
filteredFrequentOrdersList.isEmpty() &&
|
||||
searchQuery.removeSpaces().isValidSearchQuery() &&
|
||||
searchQuery.removeSpaces().isValidPhoneNumberLength().not(),
|
||||
warningMessage =
|
||||
resourceProvider.getString(R.string.np_please_enter_valid_number),
|
||||
)
|
||||
private suspend fun initializeSynchronously() {
|
||||
updateNaviPayDefaultConfig()
|
||||
}
|
||||
|
||||
_isNewContactVisible.update {
|
||||
private suspend fun initializeAsynchronously() {
|
||||
coroutineScope {
|
||||
launch { updateNaviPaySessionId() }
|
||||
launch { fetchFrequentOrders() }
|
||||
launch { observeAndHandleSearchResults() }
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun observeAndHandleSearchResults() {
|
||||
combine(searchQuery, filteredContactList, filteredFrequentOrdersList) {
|
||||
searchQuery,
|
||||
filteredContactList,
|
||||
filteredFrequentOrdersList ->
|
||||
Triple(searchQuery, filteredContactList, filteredFrequentOrdersList)
|
||||
}
|
||||
.collectLatest { (searchQuery, filteredContactList, filteredFrequentOrdersList) ->
|
||||
updateShouldShowYourContactsTitle()
|
||||
updateIsWarningOrErrorState(
|
||||
isError = false,
|
||||
isWarning =
|
||||
filteredContactList.isEmpty() &&
|
||||
filteredFrequentOrdersList.isEmpty() &&
|
||||
searchQuery.removeSpaces().isValidSearchQuery() &&
|
||||
searchQuery.removeSpaces().isValidPhoneNumberLength()
|
||||
}
|
||||
searchQuery.removeSpaces().isValidPhoneNumberLength().not(),
|
||||
warningMessage =
|
||||
resourceProvider.getString(R.string.np_please_enter_valid_number),
|
||||
)
|
||||
|
||||
if (isNewContactVisible.value) {
|
||||
updateShimmerState(showShimmer = true)
|
||||
updateNewContact(newContactEntity = null)
|
||||
fetchNewContactDetails(searchQuery)
|
||||
} else {
|
||||
updateShimmerState(showShimmer = false)
|
||||
}
|
||||
_isNewContactVisible.update {
|
||||
filteredContactList.isEmpty() &&
|
||||
filteredFrequentOrdersList.isEmpty() &&
|
||||
searchQuery.removeSpaces().isValidSearchQuery() &&
|
||||
searchQuery.removeSpaces().isValidPhoneNumberLength()
|
||||
}
|
||||
}
|
||||
|
||||
if (isNewContactVisible.value) {
|
||||
updateShimmerState(showShimmer = true)
|
||||
updateNewContact(newContactEntity = null)
|
||||
fetchNewContactDetails(searchQuery)
|
||||
} else {
|
||||
updateShimmerState(showShimmer = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateNaviPayDefaultConfig() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
naviPayDefaultConfig =
|
||||
naviPayConfigUseCase.execute<NaviPayDefaultConfig>(
|
||||
configKey = DEFAULT_CONFIG,
|
||||
type = object : TypeToken<NaviPayDefaultConfig>() {}.type,
|
||||
screenName = screenName,
|
||||
) ?: NaviPayDefaultConfig()
|
||||
private suspend fun updateNaviPayDefaultConfig() {
|
||||
naviPayDefaultConfig =
|
||||
naviPayConfigUseCase.execute<NaviPayDefaultConfig>(
|
||||
configKey = DEFAULT_CONFIG,
|
||||
type = object : TypeToken<NaviPayDefaultConfig>() {}.type,
|
||||
screenName = screenName,
|
||||
) ?: NaviPayDefaultConfig()
|
||||
|
||||
updateFrequentOrderTotalEntries(
|
||||
naviPayDefaultConfig.config.frequentTransactionsTotalEntries
|
||||
)
|
||||
updateFrequentOrderDays(naviPayDefaultConfig.config.frequentTransactionsDays)
|
||||
updateFrequentOrderHeading(naviPayDefaultConfig.config.frequentTransactionHeading)
|
||||
}
|
||||
updateFrequentOrderTotalEntries(
|
||||
naviPayDefaultConfig.config.frequentTransactionsTotalEntries
|
||||
)
|
||||
updateFrequentOrderDays(naviPayDefaultConfig.config.frequentTransactionsDays)
|
||||
updateFrequentOrderHeading(naviPayDefaultConfig.config.frequentTransactionHeading)
|
||||
}
|
||||
|
||||
private fun updateNaviPaySessionId() {
|
||||
viewModelScope.launch(Dispatchers.IO) { naviPaySessionHelper.createNewSessionId() }
|
||||
private suspend fun updateNaviPaySessionId() {
|
||||
naviPaySessionHelper.createNewSessionId()
|
||||
}
|
||||
|
||||
fun getNaviPaySessionAttributes(): Map<String, String> {
|
||||
@@ -332,7 +341,7 @@ constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun updateUiState(uiState: PayToContactsUIState) {
|
||||
private fun updateUiState(uiState: PayToContactsUIState) {
|
||||
_uiState.update { uiState }
|
||||
}
|
||||
|
||||
@@ -582,16 +591,20 @@ constructor(
|
||||
updateSearchQueryStringState(searchQuery = EMPTY)
|
||||
}
|
||||
|
||||
private fun fetchFrequentOrders() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val getFrequentOrderList =
|
||||
frequentOrdersHelper.getFrequentOrderList(
|
||||
frequentOrdersTotalEntries = frequentOrdersTotalEntries.value,
|
||||
frequentOrdersDays = frequentOrdersDays.value,
|
||||
)
|
||||
updateFrequentOrderEntityList(getFrequentOrderList)
|
||||
updateUiState(uiState = PayToContactsUIState.Loaded)
|
||||
}
|
||||
private suspend fun fetchFrequentOrders() {
|
||||
val getFrequentOrderList =
|
||||
frequentOrdersHelper.getFrequentOrderList(
|
||||
frequentOrdersTotalEntries = frequentOrdersTotalEntries.value,
|
||||
frequentOrdersDays = frequentOrdersDays.value,
|
||||
)
|
||||
updateFrequentOrderEntityList(getFrequentOrderList)
|
||||
naviPayAnalytics.onSendToContactsLoaded(
|
||||
naviPaySessionAttributes = getNaviPaySessionAttributes(),
|
||||
isPermissionGranted = true,
|
||||
isContactListEmpty = allContactList.value.isEmpty(),
|
||||
isFrequentOrderListEmpty = frequentOrders.value.isEmpty(),
|
||||
)
|
||||
updateUiState(uiState = PayToContactsUIState.Loaded)
|
||||
}
|
||||
|
||||
fun fetchContacts() {
|
||||
@@ -599,12 +612,6 @@ constructor(
|
||||
val savedContactListJob = async { contactManager.getPhoneContacts() }
|
||||
allContactList.update { savedContactListJob.await() }
|
||||
_isSavedContactListNonEmpty.update { allContactList.value.isNotEmpty() }
|
||||
naviPayAnalytics.onSendToContactsLoaded(
|
||||
naviPaySessionAttributes = getNaviPaySessionAttributes(),
|
||||
isPermissionGranted = true,
|
||||
isContactListEmpty = allContactList.value.isEmpty(),
|
||||
isFrequentOrderListEmpty = frequentOrders.value.isEmpty(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user