gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-taler-android] 03/04: [wallet] Expand JSON error in Compose trans


From: gnunet
Subject: [taler-taler-android] 03/04: [wallet] Expand JSON error in Compose transaction detail fragments
Date: Tue, 21 Mar 2023 17:29:00 +0100

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 1a230b0ca1c691e195d302ec5cebbb8e2acd667b
Author: Iván Ávalos <avalos@disroot.org>
AuthorDate: Fri Mar 10 00:18:33 2023 -0600

    [wallet] Expand JSON error in Compose transaction detail fragments
    
    bug 0007606
---
 .../wallet/deposit/TransactionDepositComposable.kt |  11 ++-
 .../taler/wallet/peer/TransactionPeerPullCredit.kt |   5 +-
 .../taler/wallet/peer/TransactionPeerPullDebit.kt  |   5 +-
 .../taler/wallet/peer/TransactionPeerPushCredit.kt |   5 +-
 .../taler/wallet/peer/TransactionPeerPushDebit.kt  |   5 +-
 .../transactions/ErrorTransactionComposable.kt     | 104 +++++++++++++++++++++
 .../transactions/TransactionDepositFragment.kt     |   2 +-
 .../wallet/transactions/TransactionPeerFragment.kt |   7 +-
 .../wallet/transactions/TransactionTipFragment.kt  |  12 ++-
 9 files changed, 144 insertions(+), 12 deletions(-)

diff --git 
a/wallet/src/main/java/net/taler/wallet/deposit/TransactionDepositComposable.kt 
b/wallet/src/main/java/net/taler/wallet/deposit/TransactionDepositComposable.kt
index a06fed4..810cee8 100644
--- 
a/wallet/src/main/java/net/taler/wallet/deposit/TransactionDepositComposable.kt
+++ 
b/wallet/src/main/java/net/taler/wallet/deposit/TransactionDepositComposable.kt
@@ -35,14 +35,17 @@ import net.taler.common.Amount
 import net.taler.common.Timestamp
 import net.taler.common.toAbsoluteTime
 import net.taler.wallet.R
+import net.taler.wallet.backend.TalerErrorCode.EXCHANGE_GENERIC_KYC_REQUIRED
+import net.taler.wallet.backend.TalerErrorInfo
 import net.taler.wallet.transactions.AmountType
 import net.taler.wallet.transactions.DeleteTransactionComposable
+import net.taler.wallet.transactions.ErrorTransactionButton
 import net.taler.wallet.transactions.ExtendedStatus.Pending
 import net.taler.wallet.transactions.TransactionAmountComposable
 import net.taler.wallet.transactions.TransactionDeposit
 
 @Composable
-fun TransactionDepositComposable(t: TransactionDeposit, onDelete: () -> Unit) {
+fun TransactionDepositComposable(t: TransactionDeposit, devMode: Boolean?, 
onDelete: () -> Unit) {
     val scrollState = rememberScrollState()
     Column(
         modifier = Modifier
@@ -75,6 +78,9 @@ fun TransactionDepositComposable(t: TransactionDeposit, 
onDelete: () -> Unit) {
             )
         }
         DeleteTransactionComposable(onDelete)
+        if (devMode == true && t.error != null) {
+            ErrorTransactionButton(transaction = t)
+        }
     }
 }
 
@@ -89,8 +95,9 @@ fun TransactionDepositComposablePreview() {
         amountRaw = Amount.fromDouble("TESTKUDOS", 42.1337),
         amountEffective = Amount.fromDouble("TESTKUDOS", 42.23),
         targetPaytoUri = "https://exchange.example.org/peer/pull/credit";,
+        error = TalerErrorInfo(code = EXCHANGE_GENERIC_KYC_REQUIRED),
     )
     Surface {
-        TransactionDepositComposable(t) {}
+        TransactionDepositComposable(t, true) {}
     }
 }
diff --git 
a/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPullCredit.kt 
b/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPullCredit.kt
index 0687b0f..d6b798c 100644
--- a/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPullCredit.kt
+++ b/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPullCredit.kt
@@ -29,6 +29,8 @@ import androidx.compose.ui.unit.dp
 import net.taler.common.Amount
 import net.taler.common.Timestamp
 import net.taler.wallet.R
+import net.taler.wallet.backend.TalerErrorCode.EXCHANGE_GENERIC_KYC_REQUIRED
+import net.taler.wallet.backend.TalerErrorInfo
 import net.taler.wallet.compose.QrCodeUriComposable
 import net.taler.wallet.transactions.AmountType
 import net.taler.wallet.transactions.ExtendedStatus.Pending
@@ -92,8 +94,9 @@ fun TransactionPeerPullCreditPreview() {
             summary = "test invoice",
         ),
         talerUri = "https://exchange.example.org/peer/pull/credit";,
+        error = TalerErrorInfo(code = EXCHANGE_GENERIC_KYC_REQUIRED),
     )
     Surface {
-        TransactionPeerComposable(t) {}
+        TransactionPeerComposable(t, true) {}
     }
 }
diff --git 
a/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPullDebit.kt 
b/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPullDebit.kt
index 3325776..1bbc223 100644
--- a/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPullDebit.kt
+++ b/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPullDebit.kt
@@ -23,6 +23,8 @@ import androidx.compose.ui.tooling.preview.Preview
 import net.taler.common.Amount
 import net.taler.common.Timestamp
 import net.taler.wallet.R
+import net.taler.wallet.backend.TalerErrorCode.EXCHANGE_GENERIC_KYC_REQUIRED
+import net.taler.wallet.backend.TalerErrorInfo
 import net.taler.wallet.transactions.AmountType
 import net.taler.wallet.transactions.ExtendedStatus.Pending
 import net.taler.wallet.transactions.PeerInfoShort
@@ -71,8 +73,9 @@ fun TransactionPeerPullDebitPreview() {
             expiration = Timestamp.fromMillis(System.currentTimeMillis() + 60 
* 60 * 1000),
             summary = "test invoice",
         ),
+        error = TalerErrorInfo(code = EXCHANGE_GENERIC_KYC_REQUIRED),
     )
     Surface {
-        TransactionPeerComposable(t) {}
+        TransactionPeerComposable(t, true) {}
     }
 }
diff --git 
a/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPushCredit.kt 
b/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPushCredit.kt
index e6fd002..d6f4cab 100644
--- a/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPushCredit.kt
+++ b/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPushCredit.kt
@@ -23,6 +23,8 @@ import androidx.compose.ui.tooling.preview.Preview
 import net.taler.common.Amount
 import net.taler.common.Timestamp
 import net.taler.wallet.R
+import net.taler.wallet.backend.TalerErrorCode.EXCHANGE_GENERIC_KYC_REQUIRED
+import net.taler.wallet.backend.TalerErrorInfo
 import net.taler.wallet.transactions.AmountType
 import net.taler.wallet.transactions.ExtendedStatus.Pending
 import net.taler.wallet.transactions.PeerInfoShort
@@ -71,8 +73,9 @@ fun TransactionPeerPushCreditPreview() {
             expiration = Timestamp.fromMillis(System.currentTimeMillis() + 60 
* 60 * 1000),
             summary = "test invoice",
         ),
+        error = TalerErrorInfo(code = EXCHANGE_GENERIC_KYC_REQUIRED),
     )
     Surface {
-        TransactionPeerComposable(t) {}
+        TransactionPeerComposable(t, true) {}
     }
 }
diff --git 
a/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPushDebit.kt 
b/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPushDebit.kt
index 56b3626..b8e8ff4 100644
--- a/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPushDebit.kt
+++ b/wallet/src/main/java/net/taler/wallet/peer/TransactionPeerPushDebit.kt
@@ -29,6 +29,8 @@ import androidx.compose.ui.unit.dp
 import net.taler.common.Amount
 import net.taler.common.Timestamp
 import net.taler.wallet.R
+import net.taler.wallet.backend.TalerErrorCode.EXCHANGE_GENERIC_KYC_REQUIRED
+import net.taler.wallet.backend.TalerErrorInfo
 import net.taler.wallet.compose.QrCodeUriComposable
 import net.taler.wallet.transactions.AmountType
 import net.taler.wallet.transactions.ExtendedStatus.Pending
@@ -90,8 +92,9 @@ fun TransactionPeerPushDebitPreview() {
             summary = "test invoice",
         ),
         talerUri = "https://exchange.example.org/peer/pull/credit";,
+        error = TalerErrorInfo(code = EXCHANGE_GENERIC_KYC_REQUIRED),
     )
     Surface {
-        TransactionPeerComposable(t) {}
+        TransactionPeerComposable(t, true) {}
     }
 }
diff --git 
a/wallet/src/main/java/net/taler/wallet/transactions/ErrorTransactionComposable.kt
 
b/wallet/src/main/java/net/taler/wallet/transactions/ErrorTransactionComposable.kt
new file mode 100644
index 0000000..7af219a
--- /dev/null
+++ 
b/wallet/src/main/java/net/taler/wallet/transactions/ErrorTransactionComposable.kt
@@ -0,0 +1,104 @@
+/*
+ * This file is part of GNU Taler
+ * (C) 2023 Taler Systems S.A.
+ *
+ * GNU Taler is free software; you can redistribute it and/or modify it under 
the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
FOR
+ * A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+
+package net.taler.wallet.transactions
+
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.size
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.Error
+import androidx.compose.material3.AlertDialog
+import androidx.compose.material3.Button
+import androidx.compose.material3.ButtonDefaults
+import androidx.compose.material3.Icon
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Text
+import androidx.compose.material3.TextButton
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.text.font.FontFamily
+import kotlinx.serialization.json.Json
+import net.taler.wallet.R
+import net.taler.wallet.backend.TalerErrorInfo
+import net.taler.wallet.compose.copyToClipBoard
+
+val json = Json { prettyPrint = true }
+
+@Composable
+fun ErrorTransactionButton(
+    modifier: Modifier = Modifier,
+    transaction: Transaction
+) {
+    val showDialog = remember { mutableStateOf(false) }
+
+    if (transaction.error != null && showDialog.value) {
+        val message = json.encodeToString(TalerErrorInfo.serializer(), 
transaction.error!!)
+        AlertDialog(onDismissRequest = {
+            showDialog.value = false
+        },
+        title = {
+            Text(stringResource(R.string.nav_error))
+        },
+        text = {
+            Column {
+                Text(
+                    fontFamily = FontFamily.Monospace,
+                    text = message,
+                )
+            }
+        },
+        dismissButton = {
+            TextButton(onClick = {
+                showDialog.value = false
+            }) {
+                Text(stringResource(R.string.close))
+            }
+        },
+        confirmButton = {
+            val context = LocalContext.current
+            TextButton(onClick = {
+                copyToClipBoard(context, 
context.getString(R.string.nav_error), message)
+            }) {
+                Text(stringResource(R.string.copy))
+            }
+        })
+    }
+
+    Button(
+       modifier = modifier,
+       colors = ButtonDefaults.buttonColors(
+           contentColor = MaterialTheme.colorScheme.onError,
+           containerColor = MaterialTheme.colorScheme.error,
+       ),
+       onClick = {
+           showDialog.value = true
+       }
+    ) {
+        val label = stringResource(R.string.nav_error)
+        Icon(
+            Icons.Default.Error,
+            label,
+            modifier = Modifier.size(ButtonDefaults.IconSize),
+        )
+        Spacer(Modifier.size(ButtonDefaults.IconSpacing))
+        Text(label)
+    }
+}
\ No newline at end of file
diff --git 
a/wallet/src/main/java/net/taler/wallet/transactions/TransactionDepositFragment.kt
 
b/wallet/src/main/java/net/taler/wallet/transactions/TransactionDepositFragment.kt
index dd09b4c..3fd37ce 100644
--- 
a/wallet/src/main/java/net/taler/wallet/transactions/TransactionDepositFragment.kt
+++ 
b/wallet/src/main/java/net/taler/wallet/transactions/TransactionDepositFragment.kt
@@ -35,7 +35,7 @@ class TransactionDepositFragment : 
TransactionDetailFragment() {
         setContent {
             TalerSurface {
                 val t = 
transactionManager.selectedTransaction.observeAsState().value
-                if (t is TransactionDeposit) TransactionDepositComposable(t) {
+                if (t is TransactionDeposit) TransactionDepositComposable(t, 
devMode.value) {
                     onDeleteButtonClicked(t)
                 }
             }
diff --git 
a/wallet/src/main/java/net/taler/wallet/transactions/TransactionPeerFragment.kt 
b/wallet/src/main/java/net/taler/wallet/transactions/TransactionPeerFragment.kt
index 3d99774..ef227ed 100644
--- 
a/wallet/src/main/java/net/taler/wallet/transactions/TransactionPeerFragment.kt
+++ 
b/wallet/src/main/java/net/taler/wallet/transactions/TransactionPeerFragment.kt
@@ -56,7 +56,7 @@ class TransactionPeerFragment : TransactionDetailFragment() {
         setContent {
             TalerSurface {
                 val t = 
transactionManager.selectedTransaction.observeAsState(null).value
-                if (t != null) TransactionPeerComposable(t) {
+                if (t != null) TransactionPeerComposable(t, devMode.value) {
                     onDeleteButtonClicked(t)
                 }
             }
@@ -65,7 +65,7 @@ class TransactionPeerFragment : TransactionDetailFragment() {
 }
 
 @Composable
-fun TransactionPeerComposable(t: Transaction, onDelete: () -> Unit) {
+fun TransactionPeerComposable(t: Transaction, devMode: Boolean?, onDelete: () 
-> Unit) {
     val scrollState = rememberScrollState()
     Column(
         modifier = Modifier
@@ -87,6 +87,9 @@ fun TransactionPeerComposable(t: Transaction, onDelete: () -> 
Unit) {
             else -> error("unexpected transaction: ${t::class.simpleName}")
         }
         DeleteTransactionComposable(onDelete)
+        if (devMode == true && t.error != null) {
+            ErrorTransactionButton(transaction = t)
+        }
     }
 }
 
diff --git 
a/wallet/src/main/java/net/taler/wallet/transactions/TransactionTipFragment.kt 
b/wallet/src/main/java/net/taler/wallet/transactions/TransactionTipFragment.kt
index 02b522f..df2077d 100644
--- 
a/wallet/src/main/java/net/taler/wallet/transactions/TransactionTipFragment.kt
+++ 
b/wallet/src/main/java/net/taler/wallet/transactions/TransactionTipFragment.kt
@@ -41,6 +41,8 @@ import net.taler.common.Amount
 import net.taler.common.Timestamp
 import net.taler.common.toAbsoluteTime
 import net.taler.wallet.R
+import net.taler.wallet.backend.TalerErrorCode.EXCHANGE_GENERIC_KYC_REQUIRED
+import net.taler.wallet.backend.TalerErrorInfo
 import net.taler.wallet.compose.TalerSurface
 import net.taler.wallet.transactions.ExtendedStatus.Pending
 
@@ -54,7 +56,7 @@ class TransactionTipFragment : TransactionDetailFragment() {
         setContent {
             TalerSurface {
                 val t = 
transactionManager.selectedTransaction.observeAsState(null).value
-                if (t is TransactionTip) TransactionTipComposable(t) {
+                if (t is TransactionTip) TransactionTipComposable(t, 
devMode.value) {
                     onDeleteButtonClicked(t)
                 }
             }
@@ -63,7 +65,7 @@ class TransactionTipFragment : TransactionDetailFragment() {
 }
 
 @Composable
-fun TransactionTipComposable(t: TransactionTip, onDelete: () -> Unit) {
+fun TransactionTipComposable(t: TransactionTip, devMode: Boolean?, onDelete: 
() -> Unit) {
     val scrollState = rememberScrollState()
     Column(
         modifier = Modifier
@@ -101,6 +103,9 @@ fun TransactionTipComposable(t: TransactionTip, onDelete: 
() -> Unit) {
             info = t.merchantBaseUrl,
         )
         DeleteTransactionComposable(onDelete)
+        if (devMode == true && t.error != null) {
+            ErrorTransactionButton(transaction = t)
+        }
     }
 }
 
@@ -114,8 +119,9 @@ fun TransactionTipPreview() {
         merchantBaseUrl = "https://merchant.example.org/";,
         amountRaw = Amount.fromDouble("TESTKUDOS", 42.23),
         amountEffective = Amount.fromDouble("TESTKUDOS", 42.1337),
+        error = TalerErrorInfo(code = EXCHANGE_GENERIC_KYC_REQUIRED),
     )
     Surface {
-        TransactionTipComposable(t) {}
+        TransactionTipComposable(t, true) {}
     }
 }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]