mailbox-payment-only-actionable-for-one-scheme.diff (4280B)
1 diff --git a/wallet/src/main/java/net/taler/wallet/Utils.kt b/wallet/src/main/java/net/taler/wallet/Utils.kt 2 index 6e0ecdc0..2c2762fe 100644 3 --- a/wallet/src/main/java/net/taler/wallet/Utils.kt 4 +++ b/wallet/src/main/java/net/taler/wallet/Utils.kt 5 @@ -63,6 +63,7 @@ import net.taler.common.AmountParserException 6 import net.taler.lib.android.showError 7 import net.taler.lib.android.startActivitySafe 8 import net.taler.wallet.backend.TalerErrorInfo 9 +import java.util.Locale 10 11 const val CURRENCY_BTC = "BITCOINBTC" 12 13 @@ -117,6 +118,31 @@ private fun connectToWifiDeprecated(context: Context, ssid: String) { 14 } 15 } 16 17 +/** 18 + * The action part of a Taler URI, whatever scheme it arrived under. 19 + * 20 + * `taler://`, `ext+taler://` and `taler+http://` all carry the same actions, 21 + * and schemes are case-insensitive per RFC 3986. Testing for one spelling by 22 + * hand is how a payment that arrived by mailbox became unactionable and how 23 + * the forward-to-contact button stopped appearing in the one mode that offers 24 + * it -- so anything deciding *which* action a URI names should ask here. 25 + * 26 + * Returns null for a URI that is not a Taler URI at all. 27 + */ 28 +fun talerUriAction(uri: String): String? { 29 + val lower = uri.lowercase(Locale.ROOT) 30 + for (scheme in listOf("taler://", "ext+taler://", "taler+http://")) { 31 + if (lower.startsWith(scheme)) return lower.substring(scheme.length) 32 + } 33 + return null 34 +} 35 + 36 +/** Whether a Taler URI names one of these actions, under any scheme. */ 37 +fun talerUriIsAction(uri: String, vararg actions: String): Boolean { 38 + val action = talerUriAction(uri) ?: return false 39 + return actions.any { action.startsWith(it) } 40 +} 41 + 42 fun cleanExchange(exchange: String) = exchange.let { 43 if (it.startsWith("https://", ignoreCase = true)) it.substring(8) else it 44 }.trimEnd('/') 45 diff --git a/wallet/src/main/java/net/taler/wallet/compose/QrCodeUriComposable.kt b/wallet/src/main/java/net/taler/wallet/compose/QrCodeUriComposable.kt 46 index dd378132..57da5de0 100644 47 --- a/wallet/src/main/java/net/taler/wallet/compose/QrCodeUriComposable.kt 48 +++ b/wallet/src/main/java/net/taler/wallet/compose/QrCodeUriComposable.kt 49 @@ -61,6 +61,7 @@ import net.taler.lib.android.QrCodeManager 50 import net.taler.lib.android.QrLogoSize 51 import net.taler.lib.android.copyToClipBoard 52 import net.taler.wallet.R 53 +import net.taler.wallet.talerUriIsAction 54 55 sealed class QrCodeParams { 56 data object Taler: QrCodeParams() 57 @@ -179,7 +180,12 @@ fun ColumnScope.QrCodeUriComposable( 58 ), 59 ) 60 61 - if (devMode && onForward != null && (qrData.startsWith("taler://pay-push") || qrData.startsWith("taler://pay-pull"))) { 62 + // In developer mode the wallet's own URIs are taler+http://, so 63 + // testing for taler:// here meant this button never appeared in 64 + // the only mode that offers it. 65 + if (devMode && onForward != null && 66 + talerUriIsAction(qrData, "pay-push", "pay-pull") 67 + ) { 68 ForwardButton( 69 onClick = { onForward(qrData) }, 70 colors = ButtonDefaults.buttonColors( 71 diff --git a/wallet/src/main/java/net/taler/wallet/mailbox/MailboxScreen.kt b/wallet/src/main/java/net/taler/wallet/mailbox/MailboxScreen.kt 72 index 01073ef5..58eee7b1 100644 73 --- a/wallet/src/main/java/net/taler/wallet/mailbox/MailboxScreen.kt 74 +++ b/wallet/src/main/java/net/taler/wallet/mailbox/MailboxScreen.kt 75 @@ -68,6 +68,7 @@ import net.taler.common.Timestamp 76 import net.taler.lib.android.toAbsoluteTime 77 import net.taler.wallet.NavigateCallback 78 import net.taler.wallet.R 79 +import net.taler.wallet.talerUriIsAction 80 import net.taler.wallet.WalletDestination 81 import net.taler.wallet.compose.TalerSurface 82 import net.taler.wallet.main.MainViewModel 83 @@ -242,8 +243,8 @@ fun MessageItem( 84 onDelete: (MailboxMessageRecord) -> Unit, 85 ) { 86 val context = LocalContext.current 87 - val isPayPush = message.talerUri.startsWith("taler://pay-push") 88 - val isPayPull = message.talerUri.startsWith("taler://pay-pull") 89 + val isPayPush = talerUriIsAction(message.talerUri, "pay-push") 90 + val isPayPull = talerUriIsAction(message.talerUri, "pay-pull") 91 Row( 92 modifier = Modifier 93 .fillMaxWidth()