Make sure to use the asset precision to correctly format the asset amount when reading QRs in SendTransactionActivity.

This commit is contained in:
Severiano Jaramillo 2019-02-11 20:10:21 -06:00
parent 1e67fdf065
commit dd8a52451a

View file

@ -372,6 +372,8 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
tietTo.setText(invoice.to) tietTo.setText(invoice.to)
var balanceDetail: BalanceDetail? = null
// Try to select the invoice's Asset in the Assets spinner // Try to select the invoice's Asset in the Assets spinner
for (i in 0 until (mBalancesDetailsAdapter?.count ?: 0)) { for (i in 0 until (mBalancesDetailsAdapter?.count ?: 0)) {
if (mBalancesDetailsAdapter?.getItem(i)?.symbol == invoice.currency.toUpperCase() || if (mBalancesDetailsAdapter?.getItem(i)?.symbol == invoice.currency.toUpperCase() ||
@ -379,6 +381,7 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
invoice.currency.replaceFirst("bit", "").toUpperCase() == invoice.currency.replaceFirst("bit", "").toUpperCase() ==
mBalancesDetailsAdapter?.getItem(i)?.symbol)) { mBalancesDetailsAdapter?.getItem(i)?.symbol)) {
spAsset.setSelection(i) spAsset.setSelection(i)
balanceDetail = mBalancesDetailsAdapter?.getItem(i)
break break
} }
} }
@ -394,7 +397,7 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
amount += nextItem.quantity * nextItem.price amount += nextItem.quantity * nextItem.price
} }
// TODO Improve pattern to account for different asset precisions // TODO Improve pattern to account for different asset precisions
val df = DecimalFormat("####.########") val df = DecimalFormat("####." + "#".repeat(balanceDetail?.precision ?: 5))
df.roundingMode = RoundingMode.CEILING df.roundingMode = RoundingMode.CEILING
df.decimalFormatSymbols = DecimalFormatSymbols(Locale.getDefault()) df.decimalFormatSymbols = DecimalFormatSymbols(Locale.getDefault())
tietAmount.setText(df.format(amount)) tietAmount.setText(df.format(amount))