summaryrefslogtreecommitdiff
path: root/wallet/src/main/java/net/taler/wallet/transactions
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2023-04-13 12:28:15 -0300
committerTorsten Grote <t@grobox.de>2023-04-13 12:28:15 -0300
commite90570d8f6095d69813f31444f2450193ce729ea (patch)
tree35d33a75fd534b778a703ea7dfebd7e7a222615e /wallet/src/main/java/net/taler/wallet/transactions
parent1a9de46a080ca83ad2fd2e951781cee57e15fe42 (diff)
downloadtaler-android-e90570d8f6095d69813f31444f2450193ce729ea.tar.gz
taler-android-e90570d8f6095d69813f31444f2450193ce729ea.tar.bz2
taler-android-e90570d8f6095d69813f31444f2450193ce729ea.zip
[wallet] Render dummy transactions whenever we can't parse a transaction
Diffstat (limited to 'wallet/src/main/java/net/taler/wallet/transactions')
-rw-r--r--wallet/src/main/java/net/taler/wallet/transactions/TransactionDummyFragment.kt64
-rw-r--r--wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt79
2 files changed, 142 insertions, 1 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionDummyFragment.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionDummyFragment.kt
new file mode 100644
index 0000000..ad5e19c
--- /dev/null
+++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionDummyFragment.kt
@@ -0,0 +1,64 @@
+/*
+ * This file is part of GNU Taler
+ * (C) 2022 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 android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.verticalScroll
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.livedata.observeAsState
+import androidx.compose.ui.Alignment.Companion.CenterHorizontally
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.platform.ComposeView
+import androidx.compose.ui.unit.dp
+import net.taler.wallet.compose.TalerSurface
+
+class TransactionDummyFragment : TransactionDetailFragment() {
+
+ override fun onCreateView(
+ inflater: LayoutInflater,
+ container: ViewGroup?,
+ savedInstanceState: Bundle?,
+ ): View = ComposeView(requireContext()).apply {
+ setContent {
+ TalerSurface {
+ val t = transactionManager.selectedTransaction.observeAsState(null).value
+ if (t is DummyTransaction) TransactionDummyComposable(t)
+ }
+ }
+ }
+}
+
+@Composable
+fun TransactionDummyComposable(t: DummyTransaction) {
+ val scrollState = rememberScrollState()
+ Column(
+ modifier = Modifier
+ .fillMaxWidth()
+ .padding(16.dp)
+ .verticalScroll(scrollState),
+ horizontalAlignment = CenterHorizontally,
+ ) {
+ ErrorTransactionButton(error = t.error)
+ }
+}
diff --git a/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt b/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt
index a306685..29c5717 100644
--- a/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt
+++ b/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt
@@ -17,24 +17,81 @@
package net.taler.wallet.transactions
import android.content.Context
+import android.util.Log
import androidx.annotation.DrawableRes
import androidx.annotation.IdRes
import androidx.annotation.StringRes
+import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
+import kotlinx.serialization.SerializationException
import kotlinx.serialization.Transient
+import kotlinx.serialization.builtins.ListSerializer
+import kotlinx.serialization.builtins.MapSerializer
+import kotlinx.serialization.builtins.serializer
+import kotlinx.serialization.descriptors.SerialDescriptor
+import kotlinx.serialization.encoding.Decoder
+import kotlinx.serialization.encoding.Encoder
+import kotlinx.serialization.json.JsonElement
import net.taler.common.Amount
import net.taler.common.ContractMerchant
import net.taler.common.ContractProduct
import net.taler.common.Timestamp
import net.taler.wallet.R
+import net.taler.wallet.TAG
+import net.taler.wallet.backend.TalerErrorCode
import net.taler.wallet.backend.TalerErrorInfo
import net.taler.wallet.cleanExchange
import net.taler.wallet.transactions.WithdrawalDetails.ManualTransfer
import net.taler.wallet.transactions.WithdrawalDetails.TalerBankIntegrationApi
+import java.util.UUID
@Serializable
-data class Transactions(val transactions: List<Transaction>)
+data class Transactions(
+ @Serializable(with = TransactionListSerializer::class)
+ val transactions: List<Transaction>,
+)
+
+class TransactionListSerializer : KSerializer<List<Transaction>> {
+ private val serializer = ListSerializer(TransactionSerializer())
+ override val descriptor: SerialDescriptor = serializer.descriptor
+
+ override fun deserialize(decoder: Decoder): List<Transaction> {
+ return decoder.decodeSerializableValue(serializer)
+ }
+
+ override fun serialize(encoder: Encoder, value: List<Transaction>) {
+ throw NotImplementedError()
+ }
+}
+
+class TransactionSerializer : KSerializer<Transaction> {
+
+ private val serializer = Transaction.serializer()
+ override val descriptor: SerialDescriptor = serializer.descriptor
+ private val jsonSerializer = MapSerializer(String.serializer(), JsonElement.serializer())
+
+ override fun deserialize(decoder: Decoder): Transaction {
+ return try {
+ decoder.decodeSerializableValue(serializer)
+ } catch (e: SerializationException) {
+ Log.e(TAG, "Error deserializing transaction.", e)
+ DummyTransaction(
+ transactionId = UUID.randomUUID().toString(),
+ timestamp = Timestamp.now(),
+ error = TalerErrorInfo(
+ code = TalerErrorCode.UNKNOWN,
+ message = e.message,
+ extra = decoder.decodeSerializableValue(jsonSerializer)
+ ),
+ )
+ }
+ }
+
+ override fun serialize(encoder: Encoder, value: Transaction) {
+ throw NotImplementedError()
+ }
+}
@Serializable
sealed class Transaction {
@@ -420,3 +477,23 @@ class TransactionPeerPushCredit(
override val generalTitleRes = R.string.transaction_peer_push_credit
}
+
+/**
+ * This represents a transaction that we can not parse for some reason.
+ */
+class DummyTransaction(
+ override val transactionId: String,
+ override val timestamp: Timestamp,
+ override val error: TalerErrorInfo,
+) : Transaction() {
+ override val extendedStatus: ExtendedStatus = ExtendedStatus.Failed
+ override val amountRaw: Amount = Amount.zero("TESTKUDOS")
+ override val amountEffective: Amount = Amount.zero("TESTKUDOS")
+ override val icon: Int = R.drawable.ic_bug_report
+ override val detailPageNav: Int = R.id.nav_transactions_detail_dummy
+ override val amountType: AmountType = AmountType.Neutral
+ override val generalTitleRes: Int = R.string.transaction_dummy_title
+ override fun getTitle(context: Context): String {
+ return context.getString(R.string.transaction_dummy_title)
+ }
+}