summaryrefslogtreecommitdiff
path: root/wallet
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2023-02-21 15:16:51 -0300
committerTorsten Grote <t@grobox.de>2023-02-22 08:33:23 -0300
commit4559c84e445ea43957d19b2022c856c9625a5fc1 (patch)
tree3294657d18fe616bd75181fd89869ef819f07157 /wallet
parent413e27dee882aafc5ecda1153df2a81bb4b70d85 (diff)
downloadtaler-android-4559c84e445ea43957d19b2022c856c9625a5fc1.tar.gz
taler-android-4559c84e445ea43957d19b2022c856c9625a5fc1.tar.bz2
taler-android-4559c84e445ea43957d19b2022c856c9625a5fc1.zip
[wallet] navigate to withdrawal transaction detail for bank withdrawals
#7676
Diffstat (limited to 'wallet')
-rw-r--r--wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt11
-rw-r--r--wallet/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt27
-rw-r--r--wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt12
-rw-r--r--wallet/src/main/res/navigation/nav_graph.xml4
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?
@@ -109,6 +109,11 @@ data class WithdrawalDetails(
)
@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
@@ -302,6 +302,10 @@
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"
app:popUpTo="@id/nav_main" />