[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-android] 05/14: [wallet] add some potential TODOs for pay t
From: |
gnunet |
Subject: |
[taler-taler-android] 05/14: [wallet] add some potential TODOs for pay templates |
Date: |
Tue, 26 Sep 2023 18:31:25 +0200 |
This is an automated email from the git hooks/post-receive script.
torsten-grote pushed a commit to branch master
in repository taler-android.
commit 0fee8e1a1bd018dfb4625389159f38cf1d5b4f9b
Author: Torsten Grote <t@grobox.de>
AuthorDate: Sat Aug 19 10:50:16 2023 +0200
[wallet] add some potential TODOs for pay templates
---
.../taler/wallet/payment/PayTemplateComposable.kt | 54 ++++++++++++++--------
1 file 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))
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-taler-android] branch master updated (d7196a0 -> e7e2763), gnunet, 2023/09/26
- [taler-taler-android] 03/14: [wallet] first cleanup of payment template work, gnunet, 2023/09/26
- [taler-taler-android] 01/14: [wallet] Initial version of template support, gnunet, 2023/09/26
- [taler-taler-android] 10/14: [wallet] Improved AmountInputField with a VisualTransformation, gnunet, 2023/09/26
- [taler-taler-android] 11/14: [wallet] fix: AmountInputField reacts to external changes, gnunet, 2023/09/26
- [taler-taler-android] 05/14: [wallet] add some potential TODOs for pay templates,
gnunet <=
- [taler-taler-android] 09/14: [wallet] Support 0.x fractions in AmountInputField, gnunet, 2023/09/26
- [taler-taler-android] 04/14: [wallet] Improve internal logic of templates, gnunet, 2023/09/26
- [taler-taler-android] 08/14: [wallet] Refactor amount input into single composable, gnunet, 2023/09/26
- [taler-taler-android] 02/14: [wallet] Improved templates UX and PoS confirmation codes, gnunet, 2023/09/26
- [taler-taler-android] 14/14: [wallet] Fix back navigation after template prompt., gnunet, 2023/09/26
- [taler-taler-android] 13/14: [wallet] simplify pay templates, gnunet, 2023/09/26
- [taler-taler-android] 12/14: [wallet] simplify AmountInputField, gnunet, 2023/09/26
- [taler-taler-android] 06/14: [wallet] Additional refactoring of pay templates, gnunet, 2023/09/26
- [taler-taler-android] 07/14: [wallet] fixes for templates parsing and UI, gnunet, 2023/09/26