commit 79159d3d9fb0fdad385859c1aedb2d035fb46367
parent e87d6fc36aba431a6453fef1987f9c010b4ec12f
Author: Iván Ávalos <avalos@disroot.org>
Date: Mon, 26 Oct 2026 16:54:50 +0100
[wallet] adapt max deposit amount response to wallet-core
Diffstat:
3 files changed, 109 insertions(+), 23 deletions(-)
diff --git a/wallet/src/main/java/net/taler/wallet/deposit/DepositAmountComposable.kt b/wallet/src/main/java/net/taler/wallet/deposit/DepositAmountComposable.kt
@@ -253,6 +253,19 @@ fun DepositAmountComposable(
}
}
+private fun previewMaxDeposit(amount: String): GetMaxDepositAmountResponse {
+ val parsed = Amount.fromJSONString(amount)
+ val maximum = DepositMaximum(
+ instructedAmount = parsed,
+ effectiveAmount = parsed,
+ rawAmount = parsed,
+ )
+ return GetMaxDepositAmountResponse(
+ material = maximum,
+ available = maximum,
+ )
+}
+
@Preview
@Composable
fun DepositAmountComposablePreview() {
@@ -266,22 +279,10 @@ fun DepositAmountComposablePreview() {
label = "Test accoul "
),
maxDepositable = mapOf(
- "CHF" to GetMaxDepositAmountResponse(
- effectiveAmount = Amount.fromJSONString("CHF:100"),
- rawAmount = Amount.fromJSONString("CHF:100"),
- ),
- "EUR" to GetMaxDepositAmountResponse(
- effectiveAmount = Amount.fromJSONString("EUR:0"),
- rawAmount = Amount.fromJSONString("EUR:0"),
- ),
- "MXN" to GetMaxDepositAmountResponse(
- effectiveAmount = Amount.fromJSONString("MXN:1000"),
- rawAmount = Amount.fromJSONString("MXN:1000"),
- ),
- "USD" to GetMaxDepositAmountResponse(
- effectiveAmount = Amount.fromJSONString("USD:0"),
- rawAmount = Amount.fromJSONString("USD:0"),
- ),
+ "CHF" to previewMaxDeposit("CHF:100"),
+ "EUR" to previewMaxDeposit("EUR:0"),
+ "MXN" to previewMaxDeposit("MXN:1000"),
+ "USD" to previewMaxDeposit("USD:0"),
),
)
DepositAmountComposable(
diff --git a/wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt b/wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt
@@ -138,11 +138,7 @@ class DepositManager(
depositPaytoUri?.let { put("depositPaytoUri", it) }
put("currency", currency)
}.onSuccess {
- val spec = getCurrencySpec(currency)
- response = it.copy(
- effectiveAmount = it.effectiveAmount.withSpec(spec),
- rawAmount = it.rawAmount.withSpec(spec),
- )
+ response = it.withSpec(getCurrencySpec(currency))
}.onError { error ->
Log.e(TAG, "Error getMaxDepositAmount $error")
onError(error)
@@ -286,10 +282,34 @@ sealed class CheckDepositResult {
}
@Serializable
-data class GetMaxDepositAmountResponse(
+data class DepositMaximum(
+ val instructedAmount: Amount,
val effectiveAmount: Amount,
val rawAmount: Amount,
-)
+) {
+ fun withSpec(spec: CurrencySpecification?) = copy(
+ instructedAmount = instructedAmount.withSpec(spec),
+ effectiveAmount = effectiveAmount.withSpec(spec),
+ rawAmount = rawAmount.withSpec(spec),
+ )
+}
+
+@Serializable
+data class GetMaxDepositAmountResponse(
+ val material: DepositMaximum,
+ val available: DepositMaximum,
+) {
+ val effectiveAmount: Amount
+ get() = available.effectiveAmount
+
+ val rawAmount: Amount
+ get() = available.rawAmount
+
+ fun withSpec(spec: CurrencySpecification?) = copy(
+ material = material.withSpec(spec),
+ available = available.withSpec(spec),
+ )
+}
@Serializable
data class CreateDepositGroupResponse(
diff --git a/wallet/src/test/java/net/taler/wallet/deposit/DepositManagerTest.kt b/wallet/src/test/java/net/taler/wallet/deposit/DepositManagerTest.kt
@@ -0,0 +1,65 @@
+/*
+ * This file is part of GNU Taler
+ * (C) 2026 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.deposit
+
+import kotlinx.serialization.json.Json
+import net.taler.common.Amount
+import org.junit.Assert.assertEquals
+import org.junit.Test
+
+class DepositManagerTest {
+
+ private val json = Json {
+ ignoreUnknownKeys = true
+ }
+
+ @Test
+ fun maxDepositAmountUsesAvailableMaximum() {
+ val response = json.decodeFromString(
+ GetMaxDepositAmountResponse.serializer(),
+ """
+ {
+ "material": {
+ "instructedAmount": "EUR:5",
+ "effectiveAmount": "EUR:5",
+ "rawAmount": "EUR:4.90",
+ "fees": {
+ "coin": "EUR:0",
+ "wire": "EUR:0.10",
+ "refresh": "EUR:0"
+ }
+ },
+ "available": {
+ "instructedAmount": "EUR:10",
+ "effectiveAmount": "EUR:10",
+ "rawAmount": "EUR:9.80",
+ "fees": {
+ "coin": "EUR:0",
+ "wire": "EUR:0.20",
+ "refresh": "EUR:0"
+ }
+ },
+ "exchangeDiagnostics": {}
+ }
+ """.trimIndent(),
+ )
+
+ assertEquals(Amount.fromJSONString("EUR:10"), response.effectiveAmount)
+ assertEquals(Amount.fromJSONString("EUR:9.80"), response.rawAmount)
+ assertEquals(Amount.fromJSONString("EUR:10"), response.available.instructedAmount)
+ }
+}