optimize account search in tranfer page
All checks were successful
Auto Tag on Version Change / check-version (push) Successful in 3s
All checks were successful
Auto Tag on Version Change / check-version (push) Successful in 3s
This commit is contained in:
@@ -41,6 +41,7 @@ import sh.sar.basedbank.databinding.FragmentTransferBinding
|
||||
import sh.sar.basedbank.databinding.ItemAccountDropdownBinding
|
||||
import sh.sar.basedbank.databinding.ItemPickerSectionHeaderBinding
|
||||
import sh.sar.basedbank.util.CredentialStore
|
||||
import sh.sar.basedbank.util.AccountInputParser
|
||||
import sh.sar.basedbank.util.PaymvQrParser
|
||||
import sh.sar.basedbank.util.RecentPick
|
||||
import sh.sar.basedbank.util.RecentsCache
|
||||
@@ -190,6 +191,10 @@ class TransferFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun lookupAccount() {
|
||||
if (selectedAccount == null) {
|
||||
Toast.makeText(requireContext(), R.string.transfer_select_source_first, Toast.LENGTH_SHORT).show()
|
||||
return
|
||||
}
|
||||
val accountNumber = binding.etTo.text?.toString()?.trim() ?: ""
|
||||
if (accountNumber.isBlank()) {
|
||||
Toast.makeText(requireContext(), R.string.transfer_enter_account_first, Toast.LENGTH_SHORT).show()
|
||||
@@ -225,7 +230,12 @@ class TransferFragment : Fragment() {
|
||||
var errorMsg: String? = null
|
||||
val info = withContext(Dispatchers.IO) {
|
||||
if (isBmlSource && bmlSess != null) {
|
||||
val bmlResult = try { BmlLoginFlow().validateAccount(bmlSess, accountNumber) } catch (_: Exception) { null }
|
||||
val inputType = AccountInputParser.detect(accountNumber)
|
||||
val bmlFlow = BmlLoginFlow()
|
||||
val bmlResult = try {
|
||||
if (inputType == AccountInputParser.InputType.MIB_ACCOUNT) bmlFlow.verifyMibAccount(bmlSess, accountNumber)
|
||||
else bmlFlow.validateAccount(bmlSess, accountNumber)
|
||||
} catch (_: Exception) { null }
|
||||
if (bmlResult != null) {
|
||||
val bankId = when (bmlResult.trnType) {
|
||||
"IAT" -> "MALBMVMV"
|
||||
@@ -360,7 +370,7 @@ class TransferFragment : Fragment() {
|
||||
|
||||
val isSrcBml = src.profileType.startsWith("BML")
|
||||
val isSrcCard = src.profileType == "BML_PREPAID"
|
||||
val isDestMib = resolvedAccountNumber.matches(Regex("^9\\d{16}$"))
|
||||
val isDestMib = AccountInputParser.detect(resolvedAccountNumber) == AccountInputParser.InputType.MIB_ACCOUNT
|
||||
val currency = src.currencyName.ifBlank { "MVR" }
|
||||
val allAccounts = viewModel.accounts.value ?: emptyList()
|
||||
val allContacts = viewModel.contacts.value ?: emptyList()
|
||||
@@ -430,7 +440,7 @@ class TransferFragment : Fragment() {
|
||||
?: return Triple(false, "OTP unavailable", null)
|
||||
val currencyCode = if (src.currencyName == "USD") "840" else "462"
|
||||
val currency = if (src.currencyName == "USD") "USD" else "MVR"
|
||||
val isDestMib = destAccount.matches(Regex("^9\\d{16}$"))
|
||||
val isDestMib = AccountInputParser.detect(destAccount) == AccountInputParser.InputType.MIB_ACCOUNT
|
||||
val bankNo = if (isDestMib) 2 else 3
|
||||
val toBank = when {
|
||||
isDestMib -> "MIB"
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package sh.sar.basedbank.util
|
||||
|
||||
object AccountInputParser {
|
||||
|
||||
enum class InputType {
|
||||
MIB_ACCOUNT, // 17 digits starting with 9
|
||||
BML_ACCOUNT, // 13 digits starting with 7
|
||||
PHONE, // 7 digits starting with 7 or 9
|
||||
NATIONAL_ID, // A followed by 6 digits
|
||||
EMAIL,
|
||||
UNKNOWN
|
||||
}
|
||||
|
||||
fun detect(input: String): InputType {
|
||||
val s = input.trim()
|
||||
return when {
|
||||
s.matches(Regex("^9\\d{16}$")) -> InputType.MIB_ACCOUNT
|
||||
s.matches(Regex("^7\\d{12}$")) -> InputType.BML_ACCOUNT
|
||||
s.matches(Regex("^[79]\\d{6}$")) -> InputType.PHONE
|
||||
s.matches(Regex("^[Aa]\\d{6}$")) -> InputType.NATIONAL_ID
|
||||
s.contains("@") -> InputType.EMAIL
|
||||
else -> InputType.UNKNOWN
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -148,6 +148,7 @@
|
||||
<string name="transfer_scan_qr">Scan QR</string>
|
||||
<string name="qr_pick_image">Pick image</string>
|
||||
<string name="transfer_qr_invalid">Invalid or unsupported QR code</string>
|
||||
<string name="transfer_select_source_first">Select a source account first</string>
|
||||
<string name="transfer_enter_account_first">Enter an account number first</string>
|
||||
<string name="transfer_account_not_found">Account not found</string>
|
||||
<string name="transfer_session_unavailable">Session unavailable — please re-login</string>
|
||||
|
||||
Reference in New Issue
Block a user