Fix error in SendTransactionFragment, when the user typed an amount larger than its current balance an error would appear, but if after that the user erased everything the error would still be there. Also solved a similar error with the To account field.
This commit is contained in:
parent
c068efa84c
commit
f0b959b496
1 changed files with 23 additions and 10 deletions
|
@ -180,9 +180,9 @@ class SendTransactionFragment : Fragment(), ZXingScannerView.ResultHandler, Serv
|
||||||
// Use RxJava Debounce to avoid making calls to the NetworkService on every text change event
|
// Use RxJava Debounce to avoid making calls to the NetworkService on every text change event
|
||||||
mDisposables.add(
|
mDisposables.add(
|
||||||
tietTo.textChanges()
|
tietTo.textChanges()
|
||||||
|
.skipInitialValue()
|
||||||
.debounce(500, TimeUnit.MILLISECONDS)
|
.debounce(500, TimeUnit.MILLISECONDS)
|
||||||
.map { it.toString().trim() }
|
.map { it.toString().trim() }
|
||||||
.filter { it.length > 1 }
|
|
||||||
.subscribe {
|
.subscribe {
|
||||||
val id = mNetworkService!!.sendMessage(GetAccountByName(it!!), GetAccountByName.REQUIRED_API)
|
val id = mNetworkService!!.sendMessage(GetAccountByName(it!!), GetAccountByName.REQUIRED_API)
|
||||||
responseMap[id] = RESPONSE_GET_ACCOUNT_BY_NAME
|
responseMap[id] = RESPONSE_GET_ACCOUNT_BY_NAME
|
||||||
|
@ -192,9 +192,9 @@ class SendTransactionFragment : Fragment(), ZXingScannerView.ResultHandler, Serv
|
||||||
// Use RxJava Debounce to update the Amount error only after the user stops writing for > 500 ms
|
// Use RxJava Debounce to update the Amount error only after the user stops writing for > 500 ms
|
||||||
mDisposables.add(
|
mDisposables.add(
|
||||||
tietAmount.textChanges()
|
tietAmount.textChanges()
|
||||||
|
.skipInitialValue()
|
||||||
.debounce(500, TimeUnit.MILLISECONDS)
|
.debounce(500, TimeUnit.MILLISECONDS)
|
||||||
.filter { it.isNotEmpty() }
|
.map { it.toString().trim() }
|
||||||
.map { it.toString().trim().toDouble() }
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe { validateAmount(it!!) }
|
.subscribe { validateAmount(it!!) }
|
||||||
)
|
)
|
||||||
|
@ -370,17 +370,30 @@ class SendTransactionFragment : Fragment(), ZXingScannerView.ResultHandler, Serv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun validateAmount(amount: Double) {
|
private fun validateAmount(txtAmount: String) {
|
||||||
if (mBalancesDetailsAdapter?.isEmpty != false) return
|
if (mBalancesDetailsAdapter?.isEmpty != false) return
|
||||||
val balance = mBalancesDetailsAdapter?.getItem(spAsset.selectedItemPosition) ?: return
|
val balance = mBalancesDetailsAdapter?.getItem(spAsset.selectedItemPosition) ?: return
|
||||||
val currentAmount = balance.amount.toDouble() / Math.pow(10.0, balance.precision.toDouble())
|
val currentAmount = balance.amount.toDouble() / Math.pow(10.0, balance.precision.toDouble())
|
||||||
|
|
||||||
if (currentAmount < amount) {
|
val amount: Double = try {
|
||||||
tilAmount.error = getString(R.string.error__not_enough_funds)
|
txtAmount.toDouble()
|
||||||
isAmountCorrect = false
|
} catch (e: Exception) {
|
||||||
} else {
|
0.0
|
||||||
tilAmount.isErrorEnabled = false
|
}
|
||||||
isAmountCorrect = true
|
|
||||||
|
when {
|
||||||
|
currentAmount < amount -> {
|
||||||
|
tilAmount.error = getString(R.string.error__not_enough_funds)
|
||||||
|
isAmountCorrect = false
|
||||||
|
}
|
||||||
|
amount == 0.0 -> {
|
||||||
|
tilAmount.isErrorEnabled = false
|
||||||
|
isAmountCorrect = false
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
tilAmount.isErrorEnabled = false
|
||||||
|
isAmountCorrect = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enableDisableSendFAB()
|
enableDisableSendFAB()
|
||||||
|
|
Loading…
Reference in a new issue