gnunet-svn
[Top][All Lists]
Advanced

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

[taler-taler-android] 01/02: [wallet] Update refunds to new API


From: gnunet
Subject: [taler-taler-android] 01/02: [wallet] Update refunds to new API
Date: Thu, 02 Nov 2023 14:12:09 +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 5a8920d9ce58622632c1ad4d8b080a31de5f6bb4
Author: Iván Ávalos <avalos@disroot.org>
AuthorDate: Tue Oct 31 16:52:11 2023 -0600

    [wallet] Update refunds to new API
---
 wallet/src/main/java/net/taler/wallet/MainActivity.kt    | 16 ++++++++++------
 .../main/java/net/taler/wallet/refund/RefundManager.kt   | 12 ++++--------
 .../net/taler/wallet/transactions/TransactionManager.kt  | 12 ++++++++++++
 wallet/src/main/res/values/strings.xml                   |  2 +-
 4 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/wallet/src/main/java/net/taler/wallet/MainActivity.kt 
b/wallet/src/main/java/net/taler/wallet/MainActivity.kt
index cfeeb31..4cbd738 100644
--- a/wallet/src/main/java/net/taler/wallet/MainActivity.kt
+++ b/wallet/src/main/java/net/taler/wallet/MainActivity.kt
@@ -22,8 +22,6 @@ import android.content.Context
 import android.content.Intent
 import android.content.Intent.ACTION_VIEW
 import android.content.IntentFilter
-import android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET
-import android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED
 import android.net.Uri
 import android.os.Bundle
 import android.util.Log
@@ -38,6 +36,7 @@ import androidx.core.os.bundleOf
 import androidx.core.view.GravityCompat.START
 import androidx.lifecycle.MutableLiveData
 import androidx.lifecycle.Observer
+import androidx.lifecycle.lifecycleScope
 import androidx.lifecycle.viewModelScope
 import androidx.navigation.NavController
 import androidx.navigation.fragment.NavHostFragment
@@ -312,10 +311,15 @@ class MainActivity : AppCompatActivity(), 
OnNavigationItemSelectedListener,
                 }
             }
             is RefundStatus.Success -> {
-                val amount = status.response.amountRefundGranted
-                model.showTransactions(amount.currency)
-                val str = getString(R.string.refund_success, amount.amountStr)
-                Snackbar.make(ui.navView, str, LENGTH_LONG).show()
+                lifecycleScope.launch {
+                    val transactionId = status.response.transactionId
+                    val transaction = 
model.transactionManager.getTransactionById(transactionId)
+                    if (transaction != null) {
+                        val currency = transaction.amountRaw.currency
+                        model.showTransactions(currency)
+                        Snackbar.make(ui.navView, 
getString(R.string.refund_success), LENGTH_LONG).show()
+                    }
+                }
             }
         }
     }
diff --git a/wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt 
b/wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt
index 29f18c7..96e939b 100644
--- a/wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt
+++ b/wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt
@@ -21,21 +21,17 @@ import androidx.lifecycle.MutableLiveData
 import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.launch
 import kotlinx.serialization.Serializable
-import net.taler.common.Amount
 import net.taler.wallet.backend.TalerErrorInfo
 import net.taler.wallet.backend.WalletBackendApi
 
 sealed class RefundStatus {
     data class Error(val error: TalerErrorInfo) : RefundStatus()
-    data class Success(val response: RefundResponse) : RefundStatus()
+    data class Success(val response: StartRefundQueryForUriResponse) : 
RefundStatus()
 }
 
 @Serializable
-data class RefundResponse(
-    val amountEffectivePaid: Amount,
-    val amountRefundGranted: Amount,
-    val amountRefundGone: Amount,
-    val pendingAtExchange: Boolean
+data class StartRefundQueryForUriResponse(
+    val transactionId: String,
 )
 
 class RefundManager(
@@ -46,7 +42,7 @@ class RefundManager(
     fun refund(refundUri: String): LiveData<RefundStatus> {
         val liveData = MutableLiveData<RefundStatus>()
         scope.launch {
-            api.request("applyRefund", RefundResponse.serializer()) {
+            api.request("startRefundQueryForUri", 
StartRefundQueryForUriResponse.serializer()) {
                 put("talerRefundUri", refundUri)
             }.onError {
                 liveData.postValue(RefundStatus.Error(it))
diff --git 
a/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt 
b/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt
index df62f31..edd2912 100644
--- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt
+++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt
@@ -124,6 +124,18 @@ class TransactionManager(
         }
     }
 
+    suspend fun getTransactionById(transactionId: String): Transaction? {
+        var transaction: Transaction? = null
+        api.request("getTransactionById", Transaction.serializer()) {
+            put("transactionId", transactionId)
+        }.onError {
+            Log.e(TAG, "Error getting transaction $it")
+        }.onSuccess { result ->
+            transaction = result
+        }
+        return transaction
+    }
+
     fun selectTransaction(transaction: Transaction) {
         mSelectedTransaction.postValue(transaction)
     }
diff --git a/wallet/src/main/res/values/strings.xml 
b/wallet/src/main/res/values/strings.xml
index 407fd72..3b05ae9 100644
--- a/wallet/src/main/res/values/strings.xml
+++ b/wallet/src/main/res/values/strings.xml
@@ -273,7 +273,7 @@ GNU Taler is immune against many types of fraud, such as 
phishing of credit card
 
     <string name="refund_title">Refund</string>
     <string name="refund_error">Error processing refund</string>
-    <string name="refund_success">Refund received: %s</string>
+    <string name="refund_success">Refund received!</string>
 
     <string name="tip_title">Reward</string>
     <string name="tip_already_accepted">This reward was already 
accepted.</string>

-- 
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]