gnunet-svn
[Top][All Lists]
Advanced

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

[taler-taler-android] 01/08: [wallet] navigate to withdrawal transaction


From: gnunet
Subject: [taler-taler-android] 01/08: [wallet] navigate to withdrawal transaction detail for bank withdrawals
Date: Wed, 22 Feb 2023 12:33:53 +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 4559c84e445ea43957d19b2022c856c9625a5fc1
Author: Torsten Grote <t@grobox.de>
AuthorDate: Tue Feb 21 15:16:51 2023 -0300

    [wallet] navigate to withdrawal transaction detail for bank withdrawals
    
    #7676
---
 .../wallet/transactions/TransactionManager.kt      | 11 +++++++++
 .../wallet/withdraw/PromptWithdrawFragment.kt      | 27 ++++++++++++++++++----
 .../net/taler/wallet/withdraw/WithdrawManager.kt   | 12 +++++++---
 wallet/src/main/res/navigation/nav_graph.xml       |  4 ++++
 4 files changed, 46 insertions(+), 8 deletions(-)

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 bbae22b..a65d9a6 100644
--- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt
+++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt
@@ -89,6 +89,17 @@ class TransactionManager(
         }
     }
 
+    /**
+     * Returns true if given [transactionId] was found for given [currency] 
and selected.
+     */
+    fun selectTransaction(currency: String, transactionId: String): Boolean {
+        val t = allTransactions[currency]?.find {
+            it.transactionId == transactionId
+        } ?: return false
+        selectedTransaction = t
+        return true
+    }
+
     fun deleteTransaction(transactionId: String) = scope.launch {
         api.request<Unit>("deleteTransaction") {
             put("transactionId", transactionId)
diff --git 
a/wallet/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt 
b/wallet/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt
index dbf901a..abe9562 100644
--- a/wallet/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt
@@ -23,9 +23,11 @@ import android.view.ViewGroup
 import android.widget.ArrayAdapter
 import androidx.fragment.app.Fragment
 import androidx.fragment.app.activityViewModels
+import androidx.lifecycle.lifecycleScope
 import androidx.navigation.fragment.findNavController
 import com.google.android.material.snackbar.Snackbar
 import com.google.android.material.snackbar.Snackbar.LENGTH_LONG
+import kotlinx.coroutines.launch
 import net.taler.common.Amount
 import net.taler.common.EventObserver
 import net.taler.common.fadeIn
@@ -43,6 +45,7 @@ class PromptWithdrawFragment : Fragment() {
 
     private val model: MainViewModel by activityViewModels()
     private val withdrawManager by lazy { model.withdrawManager }
+    private val transactionManager by lazy { model.transactionManager }
 
     private lateinit var ui: FragmentPromptWithdrawBinding
 
@@ -88,9 +91,18 @@ class PromptWithdrawFragment : Fragment() {
         is WithdrawStatus.Success -> {
             model.showProgressBar.value = false
             withdrawManager.withdrawStatus.value = null
-            
findNavController().navigate(R.id.action_promptWithdraw_to_nav_main)
-            model.showTransactions(status.currency)
-            Snackbar.make(requireView(), R.string.withdraw_initiated, 
LENGTH_LONG).show()
+            lifecycleScope.launch {
+                // FIXME this is hacky and blocks the UI thread, not good for 
many transactions
+                // load new transactions first and wait for result
+                transactionManager.loadTransactions().join()
+                // now select new transaction based on currency and ID
+                if (transactionManager.selectTransaction(status.currency, 
status.transactionId)) {
+                    
findNavController().navigate(R.id.action_promptWithdraw_to_nav_transactions_detail_withdrawal)
+                } else {
+                    
findNavController().navigate(R.id.action_promptWithdraw_to_nav_main)
+                }
+                Snackbar.make(requireView(), R.string.withdraw_initiated, 
LENGTH_LONG).show()
+            }
         }
         is WithdrawStatus.Error -> {
             model.showProgressBar.value = false
@@ -115,8 +127,13 @@ class PromptWithdrawFragment : Fragment() {
     }
 
     private fun onReceivedDetails(s: ReceivedDetails) {
-        showContent(s.amountRaw, s.amountEffective, s.exchangeBaseUrl, 
s.talerWithdrawUri,
-            s.ageRestrictionOptions)
+        showContent(
+            amountRaw = s.amountRaw,
+            amountEffective = s.amountEffective,
+            exchange = s.exchangeBaseUrl,
+            uri = s.talerWithdrawUri,
+            ageRestrictionOptions = s.ageRestrictionOptions,
+        )
         ui.confirmWithdrawButton.apply {
             text = getString(R.string.withdraw_button_confirm)
             setOnClickListener {
diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt 
b/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt
index 1698a10..90b8570 100644
--- a/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt
+++ b/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt
@@ -59,7 +59,7 @@ sealed class WithdrawStatus {
     ) : WithdrawStatus()
 
     object Withdrawing : WithdrawStatus()
-    data class Success(val currency: String) : WithdrawStatus()
+    data class Success(val currency: String, val transactionId: String) : 
WithdrawStatus()
     sealed class ManualTransferRequired : WithdrawStatus() {
         abstract val uri: Uri
         abstract val transactionId: String?
@@ -108,6 +108,11 @@ data class WithdrawalDetails(
     val ageRestrictionOptions: List<Int>? = null,
 )
 
+@Serializable
+data class AcceptWithdrawalResponse(
+    val transactionId: String,
+)
+
 @Serializable
 data class AcceptManualWithdrawalResponse(
     val exchangePaytoUris: List<String>,
@@ -249,14 +254,15 @@ class WithdrawManager(
         status: ReceivedDetails,
         restrictAge: Int? = null,
     ) {
-        api.request<Unit>("acceptBankIntegratedWithdrawal") {
+        api.request("acceptBankIntegratedWithdrawal", 
AcceptWithdrawalResponse.serializer()) {
             restrictAge?.let { put("restrictAge", restrictAge) }
             put("exchangeBaseUrl", status.exchangeBaseUrl)
             put("talerWithdrawUri", status.talerWithdrawUri)
         }.onError {
             handleError("acceptBankIntegratedWithdrawal", it)
         }.onSuccess {
-            withdrawStatus.value = 
WithdrawStatus.Success(status.amountRaw.currency)
+            withdrawStatus.value =
+                WithdrawStatus.Success(status.amountRaw.currency, 
it.transactionId)
         }
     }
 
diff --git a/wallet/src/main/res/navigation/nav_graph.xml 
b/wallet/src/main/res/navigation/nav_graph.xml
index ec5ec08..1fc4504 100644
--- a/wallet/src/main/res/navigation/nav_graph.xml
+++ b/wallet/src/main/res/navigation/nav_graph.xml
@@ -301,6 +301,10 @@
             
android:id="@+id/action_promptWithdraw_to_nav_exchange_manual_withdrawal_success"
             app:destination="@id/nav_exchange_manual_withdrawal_success"
             app:popUpTo="@id/nav_main" />
+        <action
+            
android:id="@+id/action_promptWithdraw_to_nav_transactions_detail_withdrawal"
+            app:destination="@id/nav_transactions_detail_withdrawal"
+            app:popUpTo="@id/nav_main" />
         <action
             android:id="@+id/action_promptWithdraw_to_errorFragment"
             app:destination="@id/errorFragment"

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