diff --git a/app/src/main/java/com/adityapk/zcash/zqwandroid/QrReaderActivity.kt b/app/src/main/java/com/adityapk/zcash/zqwandroid/QrReaderActivity.kt index 042c07b..dce631a 100644 --- a/app/src/main/java/com/adityapk/zcash/zqwandroid/QrReaderActivity.kt +++ b/app/src/main/java/com/adityapk/zcash/zqwandroid/QrReaderActivity.kt @@ -168,7 +168,9 @@ class QrReaderActivity : AppCompatActivity() { return } - if (code == REQUEST_ADDRESS && !DataModel.isValidAddress(StringBuilder(barcodeInfo).toString())) { + if (code == REQUEST_ADDRESS && + !DataModel.isValidAddress(StringBuilder(barcodeInfo).toString()) && + !barcodeInfo.startsWith("zcash:")) { Log.i(TAG, "Not an address") var err = barcodeInfo if (err.length > 48) { diff --git a/app/src/main/java/com/adityapk/zcash/zqwandroid/SendActivity.kt b/app/src/main/java/com/adityapk/zcash/zqwandroid/SendActivity.kt index a56e7c8..fc9cca2 100644 --- a/app/src/main/java/com/adityapk/zcash/zqwandroid/SendActivity.kt +++ b/app/src/main/java/com/adityapk/zcash/zqwandroid/SendActivity.kt @@ -192,11 +192,30 @@ class SendActivity : AppCompatActivity() { alertDialog.show() } + private fun Double.format(digits: Int): String? = java.lang.String.format("%.${digits}f", this) + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { when (requestCode) { QrReaderActivity.REQUEST_ADDRESS -> { if (resultCode == Activity.RESULT_OK) { - sendAddress.setText(data?.dataString ?: "nothing", TextView.BufferType.EDITABLE) + if (data?.scheme == "zcash") { + sendAddress.setText(data.data?.host ?: "", TextView.BufferType.EDITABLE) + + val amt = data.data?.getQueryParameter("amt") ?: + data.data?.getQueryParameter("amount") + if (amt != null) { + val amtUsd = amt.toDouble() * (DataModel.mainResponseData?.zecprice ?: 0.0) + amountUSD.setText(amtUsd.format(2)) + amountZEC.text = "${DataModel.mainResponseData?.tokenName} $amt" + } + + val memo = data.data?.getQueryParameter("memo") + if (memo != null) { + txtSendMemo.setText(memo) + } + } else { + sendAddress.setText(data?.dataString ?: "", TextView.BufferType.EDITABLE) + } amountUSD.requestFocus() val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager