[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-android] 12/12: [wallet] support withdraw-exchange URI
From: |
gnunet |
Subject: |
[taler-taler-android] 12/12: [wallet] support withdraw-exchange URI |
Date: |
Mon, 08 Jan 2024 21:58:45 +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 0f32834dbbea6737793a7b55190ab58fdfa0bc3d
Author: Torsten Grote <t@grobox.de>
AuthorDate: Mon Jan 8 17:26:16 2024 -0300
[wallet] support withdraw-exchange URI
---
wallet/build.gradle | 2 +-
.../src/main/java/net/taler/wallet/MainActivity.kt | 32 ++++++++++++++++++++++
.../net/taler/wallet/exchanges/ExchangeManager.kt | 18 ++++++++++++
.../net/taler/wallet/withdraw/WithdrawManager.kt | 21 ++++++++++++++
wallet/src/main/res/navigation/nav_graph.xml | 4 +++
5 files changed, 76 insertions(+), 1 deletion(-)
diff --git a/wallet/build.gradle b/wallet/build.gradle
index 5236745..23c8a0b 100644
--- a/wallet/build.gradle
+++ b/wallet/build.gradle
@@ -19,7 +19,7 @@ plugins {
id "kotlinx-serialization"
}
-def qtart_version = "0.9.4-dev.1"
+def qtart_version = "0.9.4-dev.3"
static def versionCodeEpoch() {
return (new Date().getTime() / 1000).toInteger()
diff --git a/wallet/src/main/java/net/taler/wallet/MainActivity.kt
b/wallet/src/main/java/net/taler/wallet/MainActivity.kt
index 16f0efa..868ebe3 100644
--- a/wallet/src/main/java/net/taler/wallet/MainActivity.kt
+++ b/wallet/src/main/java/net/taler/wallet/MainActivity.kt
@@ -55,6 +55,7 @@ import com.journeyapps.barcodescanner.ScanOptions
import com.journeyapps.barcodescanner.ScanOptions.QR_CODE
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
import net.taler.common.EventObserver
import net.taler.common.isOnline
import net.taler.common.showError
@@ -283,6 +284,37 @@ class MainActivity : AppCompatActivity(),
OnNavigationItemSelectedListener,
nav.navigate(R.id.action_global_promptWithdraw)
model.withdrawManager.getWithdrawalDetails(u2)
}
+
+ action.startsWith("withdraw-exchange/", ignoreCase = true) -> {
+ model.showProgressBar.value = true
+ lifecycleScope.launch(Dispatchers.IO) {
+ val response =
model.withdrawManager.prepareManualWithdrawal(u2)
+ if (response == null) withContext(Dispatchers.Main) {
+ model.showProgressBar.value = false
+ nav.navigate(R.id.errorFragment)
+ } else {
+ val exchange =
+
model.exchangeManager.findExchangeByUrl(response.exchangeBaseUrl)
+ if (exchange == null)
withContext(Dispatchers.Main) {
+ model.showProgressBar.value = false
+ showError(R.string.exchange_add_error)
+ } else {
+ model.exchangeManager.withdrawalExchange =
exchange
+ withContext(Dispatchers.Main) {
+ model.showProgressBar.value = false
+ val args = Bundle().apply {
+ if (response.amount != null) {
+ putString("amount",
response.amount.toJSONString())
+ }
+ }
+ // there's more than one entry point, so
use global action
+
nav.navigate(R.id.action_global_manual_withdrawal, args)
+ }
+ }
+ }
+ }
+ }
+
action.startsWith("refund/", ignoreCase = true) -> {
model.showProgressBar.value = true
model.refundManager.refund(u2).observe(this,
Observer(::onRefundResponse))
diff --git a/wallet/src/main/java/net/taler/wallet/exchanges/ExchangeManager.kt
b/wallet/src/main/java/net/taler/wallet/exchanges/ExchangeManager.kt
index 2048b7c..0e16d7a 100644
--- a/wallet/src/main/java/net/taler/wallet/exchanges/ExchangeManager.kt
+++ b/wallet/src/main/java/net/taler/wallet/exchanges/ExchangeManager.kt
@@ -37,6 +37,11 @@ data class ExchangeListResponse(
val exchanges: List<ExchangeItem>,
)
+@Serializable
+data class ExchangeDetailedResponse(
+ val exchange: ExchangeItem,
+)
+
class ExchangeManager(
private val api: WalletBackendApi,
private val scope: CoroutineScope,
@@ -104,6 +109,19 @@ class ExchangeManager(
return exchange
}
+ @WorkerThread
+ suspend fun findExchangeByUrl(exchangeUrl: String): ExchangeItem? {
+ var exchange: ExchangeItem? = null
+ api.request("getExchangeDetailedInfo",
ExchangeDetailedResponse.serializer()) {
+ put("exchangeBaseUrl", exchangeUrl)
+ }.onError {
+ Log.e(TAG, "Error getExchangeDetailedInfo: $it")
+ }.onSuccess {
+ exchange = it.exchange
+ }
+ return exchange
+ }
+
fun addDevExchanges() {
scope.launch {
listOf(
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 9fd1f9d..ceae7e1 100644
--- a/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt
+++ b/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt
@@ -19,6 +19,7 @@ package net.taler.wallet.withdraw
import android.net.Uri
import android.util.Log
import androidx.annotation.UiThread
+import androidx.annotation.WorkerThread
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import kotlinx.coroutines.CoroutineScope
@@ -116,6 +117,12 @@ data class WithdrawalDetailsForUri(
val possibleExchanges: List<ExchangeItem>,
)
+@Serializable
+data class WithdrawExchangeResponse(
+ val exchangeBaseUrl: String,
+ val amount: Amount? = null,
+)
+
@Serializable
data class ManualWithdrawalDetails(
val tosAccepted: Boolean,
@@ -214,6 +221,20 @@ class WithdrawManager(
}
}
+ @WorkerThread
+ suspend fun prepareManualWithdrawal(uri: String):
WithdrawExchangeResponse? {
+ withdrawStatus.postValue(WithdrawStatus.Loading(uri))
+ var response: WithdrawExchangeResponse? = null
+ api.request("prepareWithdrawExchange",
WithdrawExchangeResponse.serializer()) {
+ put("talerUri", uri)
+ }.onError {
+ handleError("prepareWithdrawExchange", it)
+ }.onSuccess {
+ response = it
+ }
+ return response
+ }
+
private fun getExchangeTos(
exchangeBaseUrl: String,
details: ManualWithdrawalDetails,
diff --git a/wallet/src/main/res/navigation/nav_graph.xml
b/wallet/src/main/res/navigation/nav_graph.xml
index 11add30..672bb77 100644
--- a/wallet/src/main/res/navigation/nav_graph.xml
+++ b/wallet/src/main/res/navigation/nav_graph.xml
@@ -376,6 +376,10 @@
android:id="@+id/action_global_promptWithdraw"
app:destination="@id/promptWithdraw" />
+ <action
+ android:id="@+id/action_global_manual_withdrawal"
+ app:destination="@id/nav_exchange_manual_withdrawal" />
+
<action
android:id="@+id/action_global_promptPayment"
app:destination="@id/promptPayment" />
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-taler-android] branch master updated (bdd47e0 -> 0f32834), gnunet, 2024/01/08
- [taler-taler-android] 04/12: [wallet] Bump qtart to v0.9.4-dev.1, gnunet, 2024/01/08
- [taler-taler-android] 06/12: [wallet] Refactor p2p payments to show tx details when ready, gnunet, 2024/01/08
- [taler-taler-android] 05/12: [wallet] Layout improvement to manual withdrawal details, gnunet, 2024/01/08
- [taler-taler-android] 08/12: [wallet] Delete unused numCoins field, gnunet, 2024/01/08
- [taler-taler-android] 01/12: [wallet] Initial implementation of DD36., gnunet, 2024/01/08
- [taler-taler-android] 07/12: [wallet] Fix empty/null account list in manual withdrawal, gnunet, 2024/01/08
- [taler-taler-android] 03/12: [wallet] Manual withdrawal: hide fee when zero and relax paddings for smaller screens, gnunet, 2024/01/08
- [taler-taler-android] 02/12: [wallet] Fixed serialization issues, gnunet, 2024/01/08
- [taler-taler-android] 12/12: [wallet] support withdraw-exchange URI,
gnunet <=
- [taler-taler-android] 11/12: [wallet] Add UX from now-deleted push/pull result screens into p2p tx details, gnunet, 2024/01/08
- [taler-taler-android] 09/12: [wallet] ScrollableTabRow nitpick, gnunet, 2024/01/08
- [taler-taler-android] 10/12: [wallet] Re-add disable back navigation, gnunet, 2024/01/08