TP-60625 | account toggling to primary fixed (#10110)
This commit is contained in:
@@ -761,6 +761,14 @@ constructor(
|
||||
)
|
||||
}
|
||||
|
||||
// account toggling when amount is typed & accounts list is yet not populated
|
||||
if (
|
||||
paymentAmount.value.isNotEmpty() &&
|
||||
source !is SendMoneyScreenSource.CollectRequest
|
||||
) {
|
||||
updateSelectedAccountAndEligibilityStates(paymentAmount = paymentAmount.value)
|
||||
}
|
||||
|
||||
if (payeeEntity.value.amount.isNotEmpty()) {
|
||||
updatePaymentAmount(amount = payeeEntity.value.amount)
|
||||
}
|
||||
@@ -1042,9 +1050,10 @@ constructor(
|
||||
val linkedAccountsSize = linkedAccounts.size
|
||||
|
||||
fun isLiteAccountEligible(): Boolean {
|
||||
return _isActiveLiteAccountPresent.value &&
|
||||
return isActiveLiteAccountPresent.value &&
|
||||
linkedAccountsSize > 0 &&
|
||||
(_liteAccountBalance.value.toDoubleOrNull() ?: 0.0) > 0.0 &&
|
||||
(liteAccountBalance.value.toDoubleOrNull() ?: 0.0) >=
|
||||
(paymentAmount.value.toDoubleOrNull() ?: 0.0) &&
|
||||
accountsEligibility[linkedAccounts[0].accountId]?.isAccountEligible == true
|
||||
}
|
||||
|
||||
@@ -1303,9 +1312,9 @@ constructor(
|
||||
val mainCtaState =
|
||||
if (payeeEntity.value.isVerifiedVpa) {
|
||||
// selected account is a lite account
|
||||
if (_selectedBankAccount.value?.accountId?.isAccountIdOfTypeUpiLite() == true) {
|
||||
if (selectedBankAccount.value?.accountId?.isAccountIdOfTypeUpiLite() == true) {
|
||||
if (
|
||||
(_liteAccountBalance.value.toDoubleOrNull() ?: 0.0) >=
|
||||
(liteAccountBalance.value.toDoubleOrNull() ?: 0.0) >=
|
||||
(paymentAmount.toDoubleOrNull() ?: 0.0)
|
||||
) {
|
||||
SendMoneyMainCtaState.Pay(
|
||||
@@ -1832,22 +1841,27 @@ constructor(
|
||||
params =
|
||||
mapOf(
|
||||
"bankAccountState" to
|
||||
"${_bankAccountsState.value is BankAccountsState.AccountList}"
|
||||
"${bankAccountsState.value is BankAccountsState.AccountList}"
|
||||
)
|
||||
)
|
||||
|
||||
if (_bankAccountsState.value !is BankAccountsState.AccountList) return
|
||||
val linkedAccounts = (_bankAccountsState.value as BankAccountsState.AccountList).accounts
|
||||
if (bankAccountsState.value !is BankAccountsState.AccountList) return
|
||||
val linkedAccounts = (bankAccountsState.value as BankAccountsState.AccountList).accounts
|
||||
|
||||
// No toggling needed, if there is no active lite account present
|
||||
if (!isActiveLiteAccountPresent.value) {
|
||||
return
|
||||
}
|
||||
|
||||
val updatedAccountsEligibility =
|
||||
(_bankAccountsState.value as BankAccountsState.AccountList)
|
||||
(bankAccountsState.value as BankAccountsState.AccountList)
|
||||
.accountsEligibility
|
||||
.toMutableMap()
|
||||
|
||||
val accountId = linkedAccounts.firstOrNull()?.accountId ?: ""
|
||||
val amountValue = paymentAmount.toDoubleOrNull() ?: 0.0
|
||||
val liteAccountBalanceValue = _liteAccountBalance.value.toDoubleOrNull() ?: 0.0
|
||||
val maxPayableAmountValue = _maxPayableAmountThroughLiteAccount.value.toDouble()
|
||||
val liteAccountBalanceValue = liteAccountBalance.value.toDoubleOrNull() ?: 0.0
|
||||
val maxPayableAmountValue = maxPayableAmountThroughLiteAccount.value.toDouble()
|
||||
|
||||
val isBalanceSufficient =
|
||||
amountValue <= minOf(a = liteAccountBalanceValue, b = maxPayableAmountValue)
|
||||
@@ -1889,7 +1903,7 @@ constructor(
|
||||
)
|
||||
|
||||
val updatedBankAccountsState =
|
||||
(_bankAccountsState.value as BankAccountsState.AccountList).copy(
|
||||
(bankAccountsState.value as BankAccountsState.AccountList).copy(
|
||||
accounts = linkedAccounts,
|
||||
accountsEligibility = updatedAccountsEligibility
|
||||
)
|
||||
@@ -1898,39 +1912,33 @@ constructor(
|
||||
event = ::updateSelectedAccountAndEligibilityStates.name,
|
||||
params =
|
||||
mapOf(
|
||||
"isAmountTogglingEnabled" to "${_isAmountTogglingEnabled.value}",
|
||||
"isAmountTogglingEnabled" to "${isAmountTogglingEnabled.value}",
|
||||
"isBalanceSufficient" to "$isBalanceSufficient",
|
||||
"isMaxPayableAmountExceeded" to "$isMaxPayableAmountExceeded",
|
||||
"liteAccountBalanceValue" to "$liteAccountBalanceValue",
|
||||
"maxPayableAmountValue" to "$maxPayableAmountValue",
|
||||
"isActiveLiteAccountPresent" to "${_isActiveLiteAccountPresent.value}"
|
||||
"isActiveLiteAccountPresent" to "${isActiveLiteAccountPresent.value}"
|
||||
)
|
||||
)
|
||||
|
||||
if (
|
||||
_isAmountTogglingEnabled.value &&
|
||||
isBalanceSufficient.not() &&
|
||||
_isActiveLiteAccountPresent.value
|
||||
) {
|
||||
if (_liteAccountBalance.value.isNotEmpty()) {
|
||||
// toggle to bank account with highest success rate only if lite is selected
|
||||
if (_selectedBankAccount.value?.accountId?.isAccountIdOfTypeUpiLite().orFalse()) {
|
||||
_selectedBankAccount.update {
|
||||
findFirstEligibleAccountWithHighestSuccessRate(
|
||||
if (isAmountTogglingEnabled.value && !isBalanceSufficient) {
|
||||
// toggle to bank account with highest success rate only if lite is selected
|
||||
if (selectedBankAccount.value?.accountId?.isAccountIdOfTypeUpiLite() == true) {
|
||||
_selectedBankAccount.update {
|
||||
findFirstEligibleAccountWithHighestSuccessRate(
|
||||
linkedAccounts = linkedAccounts,
|
||||
accountsEligibility = accountsEligibility
|
||||
)
|
||||
?: getFallbackLinkedAccount(
|
||||
linkedAccounts = linkedAccounts,
|
||||
accountsEligibility = accountsEligibility
|
||||
)
|
||||
?: getFallbackLinkedAccount(
|
||||
linkedAccounts = linkedAccounts,
|
||||
accountsEligibility = accountsEligibility
|
||||
)
|
||||
}
|
||||
updateIsAccountTogglingEnabled(isAccountTogglingEnabled = false)
|
||||
}
|
||||
_bankAccountsState.update { updatedBankAccountsState }
|
||||
updateIsAccountTogglingEnabled(isAccountTogglingEnabled = false)
|
||||
}
|
||||
_bankAccountsState.update { updatedBankAccountsState }
|
||||
} else {
|
||||
if (_isActiveLiteAccountPresent.value && _liteAccountBalance.value.isNotEmpty()) {
|
||||
if (liteAccountBalance.value.isNotEmpty()) {
|
||||
_bankAccountsState.update { updatedBankAccountsState }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user