-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba8bda4
commit c0765d3
Showing
14 changed files
with
592 additions
and
34 deletions.
There are no files selected for viewing
24 changes: 0 additions & 24 deletions
24
...ansfer/src/androidTest/java/org/mifospay/feature/make/transfer/ExampleInstrumentedTest.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest /> |
97 changes: 97 additions & 0 deletions
97
feature/send-money/src/main/kotlin/org/mifospay/feature/send/money/SendPaymentViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.