Correctly handle the scenario when the user scans a QR that requests an asset that he does not own, when that happens just parse the To and Memo fields and show a snackbar with a proper message, do not fill the amount field.
This commit is contained in:
parent
dd8a52451a
commit
5d8dbd0664
4 changed files with 19 additions and 6 deletions
|
@ -17,9 +17,11 @@ import androidx.navigation.fragment.findNavController
|
||||||
import androidx.navigation.fragment.navArgs
|
import androidx.navigation.fragment.navArgs
|
||||||
import com.afollestad.materialdialogs.MaterialDialog
|
import com.afollestad.materialdialogs.MaterialDialog
|
||||||
import com.afollestad.materialdialogs.customview.customView
|
import com.afollestad.materialdialogs.customview.customView
|
||||||
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import com.google.common.primitives.UnsignedLong
|
import com.google.common.primitives.UnsignedLong
|
||||||
import com.google.zxing.BarcodeFormat
|
import com.google.zxing.BarcodeFormat
|
||||||
import com.google.zxing.Result
|
import com.google.zxing.Result
|
||||||
|
import com.jakewharton.rxbinding3.material.dismisses
|
||||||
import com.jakewharton.rxbinding3.widget.textChanges
|
import com.jakewharton.rxbinding3.widget.textChanges
|
||||||
import cy.agorise.bitsybitshareswallet.R
|
import cy.agorise.bitsybitshareswallet.R
|
||||||
import cy.agorise.bitsybitshareswallet.adapters.BalancesDetailsAdapter
|
import cy.agorise.bitsybitshareswallet.adapters.BalancesDetailsAdapter
|
||||||
|
@ -372,6 +374,12 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
|
||||||
|
|
||||||
tietTo.setText(invoice.to)
|
tietTo.setText(invoice.to)
|
||||||
|
|
||||||
|
if (invoice.memo != null) {
|
||||||
|
tietMemo.setText(invoice.memo)
|
||||||
|
if (invoice.memo.startsWith("PP"))
|
||||||
|
tietMemo.isEnabled = false
|
||||||
|
}
|
||||||
|
|
||||||
var balanceDetail: BalanceDetail? = null
|
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
|
||||||
|
@ -386,18 +394,20 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (invoice.memo != null) {
|
// If the user does not own any of the requested asset then show a SnackBar to explain the issue and
|
||||||
tietMemo.setText(invoice.memo)
|
// return early to avoid filling the asset field
|
||||||
if (invoice.memo.startsWith("PP"))
|
if (balanceDetail == null) {
|
||||||
tietMemo.isEnabled = false
|
Snackbar.make(rootView, getString(R.string.error__you_dont_own_asset, invoice.currency.toUpperCase()),
|
||||||
|
Snackbar.LENGTH_INDEFINITE).setAction(android.R.string.ok) { }.show()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var amount = 0.0
|
var amount = 0.0
|
||||||
for (nextItem in invoice.lineItems) {
|
for (nextItem in invoice.lineItems) {
|
||||||
amount += nextItem.quantity * nextItem.price
|
amount += nextItem.quantity * nextItem.price
|
||||||
}
|
}
|
||||||
// TODO Improve pattern to account for different asset precisions
|
|
||||||
val df = DecimalFormat("####." + "#".repeat(balanceDetail?.precision ?: 5))
|
val df = DecimalFormat("####." + "#".repeat(balanceDetail.precision))
|
||||||
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))
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
tools:context=".fragments.SendTransactionFragment">
|
tools:context=".fragments.SendTransactionFragment">
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:id="@+id/rootView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingTop="@dimen/activity_vertical_margin"
|
android:paddingTop="@dimen/activity_vertical_margin"
|
||||||
|
|
|
@ -98,6 +98,7 @@
|
||||||
<string name="msg__camera_permission_necessary">El permiso de cámara es necesario para leer códigos QR.</string>
|
<string name="msg__camera_permission_necessary">El permiso de cámara es necesario para leer códigos QR.</string>
|
||||||
<string name="text__transaction_sent">¡Transacción enviada!</string>
|
<string name="text__transaction_sent">¡Transacción enviada!</string>
|
||||||
<string name="msg__transaction_not_sent">No se pudo enviar la transacción</string>
|
<string name="msg__transaction_not_sent">No se pudo enviar la transacción</string>
|
||||||
|
<string name="error__you_dont_own_asset">No tienes nada de %1$s</string>
|
||||||
|
|
||||||
<!-- Send Transaction info dialog -->
|
<!-- Send Transaction info dialog -->
|
||||||
<string name="msg__to_explanation">Escribe la cuenta BitShares de la persona a la que le deseas enviar fondos.\nPor ejemplo: agorise-faucet</string>
|
<string name="msg__to_explanation">Escribe la cuenta BitShares de la persona a la que le deseas enviar fondos.\nPor ejemplo: agorise-faucet</string>
|
||||||
|
|
|
@ -99,6 +99,7 @@
|
||||||
<string name="msg__camera_permission_necessary">Camera permission is necessary to read QR codes.</string>
|
<string name="msg__camera_permission_necessary">Camera permission is necessary to read QR codes.</string>
|
||||||
<string name="text__transaction_sent">Transaction sent!</string>
|
<string name="text__transaction_sent">Transaction sent!</string>
|
||||||
<string name="msg__transaction_not_sent">Unable to send transaction</string>
|
<string name="msg__transaction_not_sent">Unable to send transaction</string>
|
||||||
|
<string name="error__you_dont_own_asset">You don\'t own any %1$s</string>
|
||||||
|
|
||||||
<!-- Send Transaction info dialog -->
|
<!-- Send Transaction info dialog -->
|
||||||
<string name="msg__to_explanation">Type in the Bitshares account name of the person you want to send funds to.\nFor example: agorise-faucet</string>
|
<string name="msg__to_explanation">Type in the Bitshares account name of the person you want to send funds to.\nFor example: agorise-faucet</string>
|
||||||
|
|
Loading…
Reference in a new issue