Skip to content

Commit

Permalink
fix: Pay-Money feature module
Browse files Browse the repository at this point in the history
  • Loading branch information
therajanmaurya committed May 27, 2024
1 parent ba8bda4 commit c0765d3
Show file tree
Hide file tree
Showing 14 changed files with 592 additions and 34 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ import org.mifospay.core.designsystem.component.MifosOverlayLoadingWheel

@Composable
fun MakeTransferScreenRoute(
viewModel: MakeTransferViewModel = hiltViewModel()
viewModel: MakeTransferViewModel = hiltViewModel(),
onDismiss: () -> Unit
) {
val fetchPayeeClient by viewModel.fetchPayeeClient.collectAsStateWithLifecycle()
val makeTransferState by viewModel.makeTransferState.collectAsStateWithLifecycle()
Expand All @@ -58,7 +59,8 @@ fun MakeTransferScreenRoute(
toClientId,
transferAmount
)
}
},
onDismiss = onDismiss
)
}

Expand All @@ -67,6 +69,7 @@ fun MakeTransferScreen(
uiState: MakeTransferState,
showTransactionStatus: ShowTransactionStatus,
makeTransfer: (Long, Double) -> Unit,
onDismiss: () -> Unit
) {
val context = LocalContext.current
when (uiState) {
Expand Down Expand Up @@ -97,7 +100,8 @@ fun MakeTransferScreen(
externalId,
transferAmount,
showTransactionStatus,
makeTransfer = makeTransfer
makeTransfer = makeTransfer,
onDismiss = onDismiss
)
}
}
Expand All @@ -113,6 +117,7 @@ fun MakeTransferBottomSheetContent(
transferAmount: Double,
showTransactionStatus: ShowTransactionStatus,
makeTransfer: (Long, Double) -> Unit,
onDismiss: () -> Unit
) {
val sheetState = rememberModalBottomSheetState()

Expand All @@ -125,6 +130,7 @@ fun MakeTransferBottomSheetContent(
sheetState = sheetState,
onDismissRequest = {
showBottomSheet = false
onDismiss.invoke()
},
dragHandle = { BottomSheetDefaults.DragHandle() },
) {
Expand Down Expand Up @@ -340,7 +346,8 @@ fun PreviewWithMakeTransferContentLoading() {
showSuccessStatus = false,
showErrorStatus = false
),
makeTransfer = { _, _ -> }
makeTransfer = { _, _ -> },
onDismiss = { }
)
}

Expand All @@ -359,7 +366,8 @@ fun PreviewWithMakeTransferContentSuccess() {
showSuccessStatus = false,
showErrorStatus = false
),
makeTransfer = { _, _ -> }
makeTransfer = { _, _ -> },
onDismiss = { }
)
}

Expand Down Expand Up @@ -391,7 +399,8 @@ fun PreviewMakeTransferBottomSheetContent() {
showSuccessStatus = false,
showErrorStatus = false
),
makeTransfer = { _, _ -> }
makeTransfer = { _, _ -> },
onDismiss = { }
)
}

Expand All @@ -404,7 +413,8 @@ fun PreviewWithMakeTransferContentError() {
showSuccessStatus = false,
showErrorStatus = false
),
makeTransfer = { _, _ -> }
makeTransfer = { _, _ -> },
onDismiss = { }
)
}

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ fun NavController.navigateToMakeTransferScreen(
navigate(route, navOptions)
}

fun NavGraphBuilder.makeTransferScreen() {
fun NavGraphBuilder.makeTransferScreen(
onDismiss: () -> Unit
) {
composable(
route = MAKE_TRANSFER_ROUTE,
arguments = listOf(
Expand All @@ -46,6 +48,8 @@ fun NavGraphBuilder.makeTransferScreen() {
}
)
) {
MakeTransferScreenRoute()
MakeTransferScreenRoute(
onDismiss = onDismiss
)
}
}
1 change: 1 addition & 0 deletions feature/send-money/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
19 changes: 19 additions & 0 deletions feature/send-money/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
plugins {
alias(libs.plugins.mifospay.android.feature)
alias(libs.plugins.mifospay.android.library.compose)
}

android {
namespace = "org.mifospay.feature.send.money"
}

dependencies {
implementation(projects.core.data)

// we need it for country picker library
implementation("androidx.compose.material:material:1.6.0")
implementation(libs.compose.country.code.picker) // remove after moving auth code to module

// Google Bar code scanner
implementation(libs.google.play.services.code.scanner)
}
2 changes: 2 additions & 0 deletions feature/send-money/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest />
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package org.mifospay.feature.send.money

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import org.mifospay.core.data.base.UseCase
import org.mifospay.core.data.base.UseCaseHandler
import org.mifospay.core.data.domain.usecase.account.FetchAccount
import org.mifospay.core.data.repository.local.LocalRepository
import javax.inject.Inject

@HiltViewModel
class SendPaymentViewModel @Inject constructor(
private val useCaseHandler: UseCaseHandler,
private val localRepository: LocalRepository,
private val fetchAccount: FetchAccount
) : ViewModel() {

private val _showProgress = MutableStateFlow(false)
val showProgress: StateFlow<Boolean> = _showProgress

private val _vpa = MutableStateFlow("")
val vpa: StateFlow<String> = _vpa

private val _mobile = MutableStateFlow("")
val mobile: StateFlow<String> = _mobile

init {
fetchVpa()
fetchMobile()
}

fun updateProgressState(isVisible: Boolean) {
_showProgress.update { isVisible }
}

private fun fetchVpa() {
viewModelScope.launch {
_vpa.value = localRepository.clientDetails.externalId.toString()
}
}

private fun fetchMobile() {
viewModelScope.launch {
_mobile.value = localRepository.preferencesHelper.mobile.toString()
}
}

fun checkSelfTransfer(
selfVpa: String?,
selfMobile: String?,
externalIdOrMobile: String?,
sendMethodType: SendMethodType,
): Boolean {
return when (sendMethodType) {
SendMethodType.VPA -> {
selfVpa.takeIf { !it.isNullOrEmpty() }?.let { it == externalIdOrMobile } ?: false
}

SendMethodType.MOBILE -> {
selfMobile.takeIf { !it.isNullOrEmpty() }?.let { it == externalIdOrMobile } ?: false
}
}
}

fun checkBalanceAvailabilityAndTransfer(
externalId: String?,
transferAmount: Double,
onAnyError: (Int) -> Unit,
proceedWithTransferFlow: (String, Double) -> Unit
) {
updateProgressState(true)
useCaseHandler.execute(fetchAccount,
FetchAccount.RequestValues(localRepository.clientDetails.clientId),
object : UseCase.UseCaseCallback<FetchAccount.ResponseValue> {
override fun onSuccess(response: FetchAccount.ResponseValue) {
updateProgressState(false)
if (transferAmount > response.account.balance) {
onAnyError(R.string.insufficient_balance)
} else {
if (externalId != null) {
proceedWithTransferFlow(externalId, transferAmount)
}
}
}

override fun onError(message: String) {
updateProgressState(false)
onAnyError.invoke(R.string.error_fetching_balance)
}
})
}
}
Loading

0 comments on commit c0765d3

Please sign in to comment.