From 6dc5e54ad18dec515cb602a73b310cca4d391ff5 Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Tue, 15 Jan 2019 17:13:02 -0600 Subject: [PATCH] Force amount validation in SendTransactionFragment when an asset is selected in Assets spinner. The amount validation was done only after the user changed the amount but it has to also be validated when the user selects a different Asset, because it is probable to have less of that asset than what is already typed in the amount field. --- .../fragments/SendTransactionFragment.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SendTransactionFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SendTransactionFragment.kt index bb572e1..e1e2afc 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SendTransactionFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SendTransactionFragment.kt @@ -191,9 +191,8 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand tietAmount.textChanges() .skipInitialValue() .debounce(500, TimeUnit.MILLISECONDS) - .map { it.toString().trim() } .observeOn(AndroidSchedulers.mainThread()) - .subscribe { validateAmount(it!!) } + .subscribe { validateAmount() } ) } @@ -210,6 +209,8 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand tvAvailableAssetAmount.text = String.format("%." + Math.min(balance.precision, 8) + "f %s", amount, balance.symbol) + + validateAmount() } } @@ -381,7 +382,9 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand } } - private fun validateAmount(txtAmount: String) { + private fun validateAmount() { + val txtAmount = tietAmount.text.toString() + if (mBalancesDetailsAdapter?.isEmpty != false) return val balance = mBalancesDetailsAdapter?.getItem(spAsset.selectedItemPosition) ?: return val currentAmount = balance.amount.toDouble() / Math.pow(10.0, balance.precision.toDouble())