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 com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.customview.customView
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.google.common.primitives.UnsignedLong
|
||||
import com.google.zxing.BarcodeFormat
|
||||
import com.google.zxing.Result
|
||||
import com.jakewharton.rxbinding3.material.dismisses
|
||||
import com.jakewharton.rxbinding3.widget.textChanges
|
||||
import cy.agorise.bitsybitshareswallet.R
|
||||
import cy.agorise.bitsybitshareswallet.adapters.BalancesDetailsAdapter
|
||||
|
@ -372,6 +374,12 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
|
|||
|
||||
tietTo.setText(invoice.to)
|
||||
|
||||
if (invoice.memo != null) {
|
||||
tietMemo.setText(invoice.memo)
|
||||
if (invoice.memo.startsWith("PP"))
|
||||
tietMemo.isEnabled = false
|
||||
}
|
||||
|
||||
var balanceDetail: BalanceDetail? = null
|
||||
|
||||
// Try to select the invoice's Asset in the Assets spinner
|
||||
|
@ -386,18 +394,20 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
|
|||
}
|
||||
}
|
||||
|
||||
if (invoice.memo != null) {
|
||||
tietMemo.setText(invoice.memo)
|
||||
if (invoice.memo.startsWith("PP"))
|
||||
tietMemo.isEnabled = false
|
||||
// If the user does not own any of the requested asset then show a SnackBar to explain the issue and
|
||||
// return early to avoid filling the asset field
|
||||
if (balanceDetail == null) {
|
||||
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
|
||||
for (nextItem in invoice.lineItems) {
|
||||
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.decimalFormatSymbols = DecimalFormatSymbols(Locale.getDefault())
|
||||
tietAmount.setText(df.format(amount))
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
tools:context=".fragments.SendTransactionFragment">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/rootView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
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="text__transaction_sent">¡Transacción enviada!</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 -->
|
||||
<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="text__transaction_sent">Transaction sent!</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 -->
|
||||
<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