Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: import QR private key #1206

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 36 additions & 40 deletions wallet/src/de/schildbach/wallet/ui/ImportSharedImageActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.CustomTarget
import com.bumptech.glide.request.transition.Transition
import com.google.zxing.*
import com.google.zxing.common.HybridBinarizer
import de.schildbach.wallet.WalletApplication
import de.schildbach.wallet.data.PaymentIntent
import de.schildbach.wallet.ui.util.InputParser.StringInputParser
import de.schildbach.wallet.ui.payments.SweepWalletActivity
import de.schildbach.wallet.ui.send.SendCoinsActivity
import de.schildbach.wallet.ui.util.InputParser.StringInputParser
import de.schildbach.wallet_test.R
import org.bitcoinj.core.PrefixedChecksummedBytes
import org.bitcoinj.core.Transaction
Expand Down Expand Up @@ -83,46 +82,40 @@ class ImportSharedImageActivity : AppCompatActivity() {
val imageUri = intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM)
if (imageUri != null) {
Glide.with(this)
.asBitmap()
.load(imageUri).into(object : CustomTarget<Bitmap>() {

override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
val qrCode = Qr.scanQRImage(resource)
if (qrCode != null) {
handleQRCode(qrCode)
} else {
log.info("no QR code found in image {}", imageUri)
showErrorDialog(
R.string.import_image_not_valid_qr_code,
R.string.import_image_please_use_valid_qr_code,
R.drawable.ic_not_valid_qr_code)
}
.asBitmap()
.load(imageUri).into(object : CustomTarget<Bitmap>() {
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
val qrCode = Qr.scanQRImage(resource)
if (qrCode != null) {
handleQRCode(qrCode)
} else {
log.info("no QR code found in image {}", imageUri)
AdaptiveDialog.create(
R.drawable.ic_not_valid_qr_code,
getString(R.string.import_image_not_valid_qr_code),
getString(R.string.import_image_please_use_valid_qr_code),
getString(R.string.button_ok)
).show(this@ImportSharedImageActivity)
}
}

override fun onLoadFailed(errorDrawable: Drawable?) {
log.info("load image failed {}", imageUri)
showErrorDialog(
R.string.import_image_not_valid_qr_code,
R.string.import_image_please_use_valid_qr_code,
R.drawable.ic_not_valid_qr_code)
}
override fun onLoadFailed(errorDrawable: Drawable?) {
log.info("load image failed {}", imageUri)
AdaptiveDialog.create(
R.drawable.ic_not_valid_qr_code,
getString(R.string.import_image_not_valid_qr_code),
getString(R.string.import_image_please_use_valid_qr_code),
getString(R.string.button_ok)
).show(this@ImportSharedImageActivity)
}

override fun onLoadCleared(placeholder: Drawable?) {
// nothing to do
}
})
override fun onLoadCleared(placeholder: Drawable?) {
// nothing to do
}
})
}
}

private fun showErrorDialog(title: Int, msg: Int, image: Int) {
AdaptiveDialog.create(
image,
getString(title),
getString(msg),
getString(R.string.button_ok)
).show(this)
}

private fun handleQRCode(input: String) {
object : StringInputParser(input, true) {
override fun handlePaymentIntent(paymentIntent: PaymentIntent) {
Expand All @@ -142,14 +135,17 @@ class ImportSharedImageActivity : AppCompatActivity() {
}

override fun error(x: Exception?, messageResId: Int, vararg messageArgs: Any) {
showErrorDialog(
R.string.import_image_invalid_private, 0,
R.drawable.ic_not_valid_qr_code)
AdaptiveDialog.create(
R.drawable.ic_not_valid_qr_code,
getString(R.string.import_image_invalid_private),
getString(messageResId, *messageArgs),
getString(R.string.button_ok)
).show(this@ImportSharedImageActivity)
}
}.parse()
}

companion object {
private val log = LoggerFactory.getLogger(ImportSharedImageActivity::class.java)
}
}
}
Loading