forked from shihaam/thijooree
remove bml linked cards from account ui, trasfer drop down and added a cards section to show master cards
This commit is contained in:
@@ -185,25 +185,66 @@ class BmlLoginFlow {
|
||||
val root = JSONObject(json)
|
||||
if (!root.optBoolean("success")) return emptyList()
|
||||
val dashboard = root.optJSONObject("payload")?.optJSONArray("dashboard") ?: return emptyList()
|
||||
return (0 until dashboard.length()).map { i ->
|
||||
|
||||
val casaAccounts = mutableListOf<MibAccount>()
|
||||
val seenPrepaid = mutableSetOf<String>()
|
||||
val prepaidCards = mutableListOf<MibAccount>()
|
||||
|
||||
for (i in 0 until dashboard.length()) {
|
||||
val item = dashboard.getJSONObject(i)
|
||||
val currency = item.optString("currency", "MVR")
|
||||
val available = item.optDouble("availableBalance", 0.0)
|
||||
MibAccount(
|
||||
profileName = "Bank of Maldives",
|
||||
profileType = "BML",
|
||||
accountNumber = item.optString("account"),
|
||||
accountBriefName = item.optString("alias"),
|
||||
currencyName = currency,
|
||||
accountTypeName = item.optString("product"),
|
||||
availableBalance = "%.2f".format(available),
|
||||
currentBalance = "%.2f".format(item.optDouble("ledgerBalance", 0.0)),
|
||||
blockedAmount = "%.2f".format(item.optDouble("lockedAmount", 0.0)),
|
||||
mvrBalance = if (currency == "MVR") "%.2f".format(available) else "0.00",
|
||||
statusDesc = item.optString("account_status", "Active"),
|
||||
profileImageHash = null
|
||||
)
|
||||
val accountType = item.optString("account_type", "CASA")
|
||||
val product = item.optString("product")
|
||||
val accountNumber = item.optString("account")
|
||||
val status = item.optString("account_status", "Active")
|
||||
|
||||
if (accountType == "CASA") {
|
||||
val available = item.optDouble("availableBalance", 0.0)
|
||||
casaAccounts.add(MibAccount(
|
||||
profileName = "Bank of Maldives",
|
||||
profileType = "BML",
|
||||
accountNumber = accountNumber,
|
||||
accountBriefName = item.optString("alias"),
|
||||
currencyName = currency,
|
||||
accountTypeName = product,
|
||||
availableBalance = "%.2f".format(available),
|
||||
currentBalance = "%.2f".format(item.optDouble("ledgerBalance", 0.0)),
|
||||
blockedAmount = "%.2f".format(item.optDouble("lockedAmount", 0.0)),
|
||||
mvrBalance = if (currency == "MVR") "%.2f".format(available) else "0.00",
|
||||
statusDesc = status,
|
||||
profileImageHash = null
|
||||
))
|
||||
} else if (accountType == "Card") {
|
||||
val isPrepaid = item.optBoolean("prepaid_card", false)
|
||||
if (isPrepaid) {
|
||||
// Deduplicate by account number, prefer Active
|
||||
if (!seenPrepaid.contains(accountNumber) || status == "Active") {
|
||||
seenPrepaid.add(accountNumber)
|
||||
prepaidCards.removeAll { it.accountNumber == accountNumber }
|
||||
val cardBalance = item.optJSONObject("cardBalance")
|
||||
val available = cardBalance?.optDouble("AvailableLimit", 0.0) ?: 0.0
|
||||
prepaidCards.add(MibAccount(
|
||||
profileName = "Cards",
|
||||
profileType = "BML_PREPAID",
|
||||
accountNumber = accountNumber,
|
||||
accountBriefName = product,
|
||||
currencyName = currency,
|
||||
accountTypeName = product,
|
||||
availableBalance = "%.2f".format(available),
|
||||
currentBalance = "%.2f".format(cardBalance?.optDouble("CurrentBalance", 0.0) ?: 0.0),
|
||||
blockedAmount = "0.00",
|
||||
mvrBalance = if (currency == "MVR") "%.2f".format(available) else "0.00",
|
||||
statusDesc = status,
|
||||
profileImageHash = null
|
||||
))
|
||||
}
|
||||
} else {
|
||||
// Linked debit cards have no independent balance or account link — skip
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return casaAccounts + prepaidCards
|
||||
}
|
||||
|
||||
private fun parseContacts(json: String): List<MibBeneficiary> {
|
||||
|
||||
Reference in New Issue
Block a user