Skip to content

Commit

Permalink
(android) Use the complete deeplink data when starting scanview
Browse files Browse the repository at this point in the history
Uri parameters are pruned from the `data` navigation arg. That
is an issue for bip-21 uris with a LN parameter.

Fixes #466
  • Loading branch information
dpad85 committed Dec 6, 2023
1 parent 846abd9 commit f0ae904
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package fr.acinq.phoenix.android

import android.Manifest
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.text.format.DateUtils
Expand Down Expand Up @@ -237,10 +238,10 @@ fun AppView(
navDeepLink { uriPattern = "scanview:{data}" },
)
) {
val input = it.arguments?.getString("data")
RequireStarted(walletState, nextUri = "scanview:$input") {
val intent = it.arguments?.getParcelable<Intent>(NavController.KEY_DEEP_LINK_INTENT)
RequireStarted(walletState, nextUri = "scanview:${intent?.data?.toString()}") {
ScanDataView(
input = input,
input = intent?.data?.toString()?.substringAfter("scanview:"),
onBackClick = { popToHome(navController) },
onAuthSchemeInfoClick = { navController.navigate("${Screen.PaymentSettings.route}/true") }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ class MainActivity : AppCompatActivity() {
// force the intent flag to single top, in order to avoid [handleDeepLink] finish the current activity.
// this would otherwise clear the app view model, i.e. loose the state which virtually reboots the app
// TODO: look into detaching the app state from the activity
log.info("receive new_intent=$intent")
log.info("receive new_intent with data=${intent?.data}")
intent?.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP

intent?.fixUri()
this.navController?.handleDeepLink(intent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ fun ScanDataView(
onPayOnchainClick = {
showPaymentModeDialog = true
postIntent(Scan.Intent.Parse(request = model.uri.copy(paymentRequest = null).write()))
},
onDismiss = {
showPaymentModeDialog = false
}
)
}
Expand Down Expand Up @@ -227,10 +230,6 @@ fun ReadDataView(
ScanErrorView(model, onFeedbackDismiss)
}

if (model is Scan.Model.BadRequest) {
ScanErrorView(model, onFeedbackDismiss)
}

if (model is Scan.Model.LnurlServiceFetch) {
Card(modifier = Modifier.align(Alignment.Center), internalPadding = PaddingValues(horizontal = 12.dp, vertical = 8.dp)) {
ProgressView(text = stringResource(R.string.scan_lnurl_fetching))
Expand Down Expand Up @@ -315,24 +314,27 @@ private fun ScanErrorView(
private fun ChoosePaymentModeDialog(
onPayOnchainClick: () -> Unit,
onPayOffchainClick: () -> Unit,
onDismiss: () -> Unit,
) {
Dialog(onDismiss = {}, properties = DialogProperties(dismissOnBackPress = false, dismissOnClickOutside = false), isScrollable = true) {
Dialog(onDismiss = onDismiss, properties = DialogProperties(dismissOnBackPress = false, dismissOnClickOutside = true), isScrollable = true, buttons = null) {
Clickable(onClick = onPayOnchainClick) {
Row(modifier = Modifier.padding(24.dp), verticalAlignment = Alignment.CenterVertically) {
Row(modifier = Modifier.padding(horizontal = 24.dp, vertical = 16.dp), verticalAlignment = Alignment.CenterVertically) {
PhoenixIcon(resourceId = R.drawable.ic_chain)
Spacer(Modifier.width(16.dp))
Column {
Text(text = stringResource(id = R.string.send_paymentmode_onchain), style = MaterialTheme.typography.body2)
Spacer(modifier = Modifier.height(4.dp))
Text(text = stringResource(id = R.string.send_paymentmode_onchain_desc), style = MaterialTheme.typography.caption.copy(fontSize = 14.sp))
}
}
}
Clickable(onClick = onPayOffchainClick) {
Row(modifier = Modifier.padding(24.dp), verticalAlignment = Alignment.CenterVertically) {
Row(modifier = Modifier.padding(horizontal = 24.dp, vertical = 18.dp), verticalAlignment = Alignment.CenterVertically) {
PhoenixIcon(resourceId = R.drawable.ic_zap)
Spacer(Modifier.width(16.dp))
Column {
Text(text = stringResource(id = R.string.send_paymentmode_lightning), style = MaterialTheme.typography.body2)
Spacer(modifier = Modifier.height(4.dp))
Text(text = stringResource(id = R.string.send_paymentmode_lightning_desc), style = MaterialTheme.typography.caption.copy(fontSize = 14.sp))
}
}
Expand Down

0 comments on commit f0ae904

Please sign in to comment.