Skip to content

Commit

Permalink
Add support for zcash Payment URI
Browse files Browse the repository at this point in the history
  • Loading branch information
adityapk00 committed Mar 3, 2019
1 parent 54bd6cb commit c0d430a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 20 additions & 1 deletion app/src/main/java/com/adityapk/zcash/zqwandroid/SendActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c0d430a

Please sign in to comment.