diff --git a/android/navi-pay/src/main/kotlin/com/navi/pay/management/lite/viewmodel/UPILiteViewModel.kt b/android/navi-pay/src/main/kotlin/com/navi/pay/management/lite/viewmodel/UPILiteViewModel.kt index 7ba08ccf1d..460653c282 100644 --- a/android/navi-pay/src/main/kotlin/com/navi/pay/management/lite/viewmodel/UPILiteViewModel.kt +++ b/android/navi-pay/src/main/kotlin/com/navi/pay/management/lite/viewmodel/UPILiteViewModel.kt @@ -2315,6 +2315,12 @@ constructor( fun onDisableUpiLiteClicked() { viewModelScope.launch(coroutineDispatcherProvider.io) { + if (!checkIsInternetAvailableOrShowError()) return@launch + if (checkIsAirplaneModeOnOrShowError()) return@launch + + val currentSimInfoList = naviPayNetworkConnectivity.getCurrentSimInfoList() + if (!validateSimInfoOrShowError(currentSimInfoList)) return@launch + showLoadingBottomSheet( headerResId = R.string.disabling_upi_lite, descriptionResId = R.string.disabling_upi_lite_desc diff --git a/android/navi-pay/src/main/kotlin/com/navi/pay/onboarding/account/detail/viewmodel/LinkedAccountDetailViewModel.kt b/android/navi-pay/src/main/kotlin/com/navi/pay/onboarding/account/detail/viewmodel/LinkedAccountDetailViewModel.kt index c3deb036be..baaaaf106e 100644 --- a/android/navi-pay/src/main/kotlin/com/navi/pay/onboarding/account/detail/viewmodel/LinkedAccountDetailViewModel.kt +++ b/android/navi-pay/src/main/kotlin/com/navi/pay/onboarding/account/detail/viewmodel/LinkedAccountDetailViewModel.kt @@ -22,6 +22,7 @@ import com.navi.pay.analytics.NaviPayAnalytics import com.navi.pay.common.connectivity.NaviPayNetworkConnectivity import com.navi.pay.common.model.view.DisableUpiLiteAction import com.navi.pay.common.model.view.NaviPayVmData +import com.navi.pay.common.model.view.SimInfo import com.navi.pay.common.repository.CommonRepository import com.navi.pay.common.repository.SharedPreferenceRepository import com.navi.pay.common.usecase.DisableUpiLiteUseCase @@ -230,10 +231,7 @@ constructor( fun makeAccountPrimary() { viewModelScope.launch(Dispatchers.IO) { - if (!naviPayNetworkConnectivity.isInternetConnected()) { - notifyError(getNoInternetErrorConfig()) - return@launch - } + if (!checkIsInternetAvailableOrShowError()) return@launch var linkedAccountEntity: LinkedAccountEntity? = null @@ -281,10 +279,7 @@ constructor( fun deleteAccount() { apiCallJob = viewModelScope.launch(Dispatchers.IO) { - if (!naviPayNetworkConnectivity.isInternetConnected()) { - notifyError(getNoInternetErrorConfig()) - return@launch - } + if (!checkIsInternetAvailableOrShowError()) return@launch var linkedAccountEntity: LinkedAccountEntity? = null @@ -356,27 +351,11 @@ constructor( fun changePin() { viewModelScope.launch(Dispatchers.IO) { - if (!naviPayNetworkConnectivity.isInternetConnected()) { - notifyError(getNoInternetErrorConfig()) - return@launch - } - - if (naviPayNetworkConnectivity.isAirplaneModeOn()) { - notifyError(getAirplaneModeOnErrorConfig()) - return@launch - } + if (!checkIsInternetAvailableOrShowError()) return@launch + if (checkIsAirplaneModeOnOrShowError()) return@launch val currentSimInfoList = naviPayNetworkConnectivity.getCurrentSimInfoList() - val simInfoValidationResult = - NaviPayCommonUtils.validateSimInfo( - currentSimInfoList = currentSimInfoList, - deviceInfoProvider = deviceInfoProvider - ) - - if (!simInfoValidationResult) { - notifyError(getSimFailureErrorConfig(isNoSimPresent = currentSimInfoList.isEmpty())) - return@launch - } + if (!validateSimInfoOrShowError(currentSimInfoList)) return@launch updateShowLoaderState(showLoader = true) @@ -467,27 +446,11 @@ constructor( fun checkBalance() { viewModelScope.launch(Dispatchers.IO) { - if (!naviPayNetworkConnectivity.isInternetConnected()) { - notifyError(getNoInternetErrorConfig()) - return@launch - } - - if (naviPayNetworkConnectivity.isAirplaneModeOn()) { - notifyError(getAirplaneModeOnErrorConfig()) - return@launch - } + if (!checkIsInternetAvailableOrShowError()) return@launch + if (checkIsAirplaneModeOnOrShowError()) return@launch val currentSimInfoList = naviPayNetworkConnectivity.getCurrentSimInfoList() - val simInfoValidationResult = - NaviPayCommonUtils.validateSimInfo( - currentSimInfoList = currentSimInfoList, - deviceInfoProvider = deviceInfoProvider - ) - - if (!simInfoValidationResult) { - notifyError(getSimFailureErrorConfig(isNoSimPresent = currentSimInfoList.isEmpty())) - return@launch - } + if (!validateSimInfoOrShowError(currentSimInfoList)) return@launch updateShowLoaderState(showLoader = true) @@ -575,6 +538,12 @@ constructor( fun onDisableUpiLiteClicked() { viewModelScope.launch(Dispatchers.IO) { + if (!checkIsInternetAvailableOrShowError()) return@launch + if (checkIsAirplaneModeOnOrShowError()) return@launch + + val currentSimInfoList = naviPayNetworkConnectivity.getCurrentSimInfoList() + if (!validateSimInfoOrShowError(currentSimInfoList)) return@launch + showLoadingBottomSheet( headerResId = R.string.disabling_upi_lite, descriptionResId = R.string.disabling_upi_lite_desc @@ -738,6 +707,35 @@ constructor( apiCallJob?.cancel() updateShowLoaderState(showLoader = false) } + + private fun checkIsInternetAvailableOrShowError(): Boolean { + if (!naviPayNetworkConnectivity.isInternetConnected()) { + notifyError(getNoInternetErrorConfig()) + return false + } + return true + } + + private fun checkIsAirplaneModeOnOrShowError(): Boolean { + if (naviPayNetworkConnectivity.isAirplaneModeOn()) { + notifyError(getAirplaneModeOnErrorConfig()) + return true + } + return false + } + + private suspend fun validateSimInfoOrShowError(currentSimInfoList: List): Boolean { + val simInfoValidationResult = + NaviPayCommonUtils.validateSimInfo( + currentSimInfoList = currentSimInfoList, + deviceInfoProvider = deviceInfoProvider + ) + if (!simInfoValidationResult) { + notifyError(getSimFailureErrorConfig(isNoSimPresent = currentSimInfoList.isEmpty())) + return false + } + return true + } } sealed class LinkedAccountDetailScreenUIState {