summaryrefslogtreecommitdiff
path: root/wallet/src/main/java/net/taler
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2023-08-19 10:50:16 +0200
committerTorsten Grote <t@grobox.de>2023-09-26 18:30:52 +0200
commit0fee8e1a1bd018dfb4625389159f38cf1d5b4f9b (patch)
tree17efeed71173df24dac09bfb3cc769d6ee945b86 /wallet/src/main/java/net/taler
parent6734a0fa768a9acbb3193efbfd1bf7c1897877ce (diff)
downloadtaler-android-0fee8e1a1bd018dfb4625389159f38cf1d5b4f9b.tar.gz
taler-android-0fee8e1a1bd018dfb4625389159f38cf1d5b4f9b.tar.bz2
taler-android-0fee8e1a1bd018dfb4625389159f38cf1d5b4f9b.zip
[wallet] add some potential TODOs for pay templates
Diffstat (limited to 'wallet/src/main/java/net/taler')
-rw-r--r--wallet/src/main/java/net/taler/wallet/payment/PayTemplateComposable.kt54
1 files changed, 35 insertions, 19 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/payment/PayTemplateComposable.kt b/wallet/src/main/java/net/taler/wallet/payment/PayTemplateComposable.kt
index f9b72f7..c8c3ba0 100644
--- a/wallet/src/main/java/net/taler/wallet/payment/PayTemplateComposable.kt
+++ b/wallet/src/main/java/net/taler/wallet/payment/PayTemplateComposable.kt
@@ -35,8 +35,8 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
-import androidx.compose.ui.Alignment
import androidx.compose.ui.Alignment.Companion.Center
+import androidx.compose.ui.Alignment.Companion.End
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.KeyboardType
@@ -49,7 +49,6 @@ import net.taler.wallet.R
import net.taler.wallet.compose.TalerSurface
import net.taler.wallet.deposit.CurrencyDropdown
-
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun PayTemplateComposable(
@@ -62,23 +61,32 @@ fun PayTemplateComposable(
) {
val queryParams = uri.queryParameterNames
- var summary by remember { mutableStateOf(
- if ("summary" in queryParams)
- uri.getQueryParameter("summary") else null,
- ) }
+ var summary by remember {
+ mutableStateOf(
+ // TODO pass this in as a parameter instead
+ if ("summary" in queryParams) uri.getQueryParameter("summary") else null
+ )
+ }
- var amount by remember { mutableStateOf(
- if ("amount" in queryParams) {
- val amount = uri.getQueryParameter("amount")!!
- val parts = amount.split(':')
- when (parts.size) {
- 1 -> Amount.fromString(parts[0], "0")
- 2 -> Amount.fromString(parts[0], parts[1])
- else -> throw AmountParserException("Invalid Amount Format")
+ var amount by remember {
+ mutableStateOf(
+ // TODO don't do amount parsing in composable, but pass it in as a parameter
+ if ("amount" in queryParams) {
+ val amount = uri.getQueryParameter("amount")!!
+ val parts = amount.split(':')
+ when (parts.size) {
+ 1 -> Amount.fromString(parts[0], "0")
+ 2 -> Amount.fromString(parts[0], parts[1])
+ // FIXME This will crash the app, we should show a proper error instead.
+ else -> throw AmountParserException("Invalid Amount Format")
+ }
+ } else {
+ null
}
- } else null,
- ) }
+ )
+ }
+ // TODO we could think about splitting this up into separate composables
// If wallet is empty, there's no way the user can pay something
if (payStatus is PayStatus.InsufficientBalance || currencies.isEmpty()) {
Box(
@@ -93,7 +101,7 @@ fun PayTemplateComposable(
}
} else when (payStatus) {
is PayStatus.None -> {
- Column(horizontalAlignment = Alignment.End) {
+ Column(horizontalAlignment = End) {
if ("summary" in queryParams) {
OutlinedTextField(
modifier = Modifier
@@ -131,14 +139,16 @@ fun PayTemplateComposable(
AmountResult.InsufficientBalance -> {
onError(R.string.payment_balance_insufficient)
}
+
AmountResult.InvalidAmount -> {
onError(R.string.receive_amount_invalid)
}
+
else -> {
onSubmit(
mutableMapOf<String, String>().apply {
- if (summary != null) put("summary", summary!!)
- if (amount != null) put("amount", amount!!.toJSONString())
+ summary?.let { put("summary", it) }
+ amount?.let { put("amount", it.toJSONString()) }
}
)
}
@@ -150,12 +160,14 @@ fun PayTemplateComposable(
}
}
}
+
is PayStatus.Loading -> {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Center,
) { CircularProgressIndicator() }
}
+
is PayStatus.AlreadyPaid -> {
Box(
modifier = Modifier.fillMaxSize(),
@@ -168,12 +180,15 @@ fun PayTemplateComposable(
)
}
}
+
+ // TODO we should handle the other cases or explain why we don't handle them
else -> {}
}
}
@Composable
@OptIn(ExperimentalMaterial3Api::class)
+// TODO can we combine this with existing amount composables, e.g. whats in PayToComposable?
private fun AmountField(
modifier: Modifier = Modifier,
currencies: List<String>,
@@ -220,6 +235,7 @@ fun PayTemplateComposablePreview() {
PayTemplateComposable(
uri = Uri.parse("taler://pay-template/demo.backend.taler.net/test?amount=KUDOS&summary="),
currencies = listOf("KUDOS", "ARS"),
+ // TODO create previews for other states
payStatus = PayStatus.None,
onCreateAmount = { text, currency ->
AmountResult.Success(amount = Amount.fromString(currency, text))