aboutsummaryrefslogtreecommitdiff
path: root/cashier/src
diff options
context:
space:
mode:
Diffstat (limited to 'cashier/src')
-rw-r--r--cashier/src/main/java/net/taler/cashier/BalanceFragment.kt1
-rw-r--r--cashier/src/main/java/net/taler/cashier/MainViewModel.kt20
-rw-r--r--cashier/src/main/java/net/taler/cashier/SignedAmount.kt30
3 files changed, 43 insertions, 8 deletions
diff --git a/cashier/src/main/java/net/taler/cashier/BalanceFragment.kt b/cashier/src/main/java/net/taler/cashier/BalanceFragment.kt
index 5b963a0..d899e7d 100644
--- a/cashier/src/main/java/net/taler/cashier/BalanceFragment.kt
+++ b/cashier/src/main/java/net/taler/cashier/BalanceFragment.kt
@@ -33,7 +33,6 @@ import kotlinx.android.synthetic.main.fragment_balance.*
import net.taler.cashier.BalanceFragmentDirections.Companion.actionBalanceFragmentToTransactionFragment
import net.taler.cashier.withdraw.LastTransaction
import net.taler.cashier.withdraw.WithdrawStatus
-import net.taler.common.SignedAmount
import net.taler.common.exhaustive
import net.taler.common.fadeIn
import net.taler.common.fadeOut
diff --git a/cashier/src/main/java/net/taler/cashier/MainViewModel.kt b/cashier/src/main/java/net/taler/cashier/MainViewModel.kt
index a0796df..a25467b 100644
--- a/cashier/src/main/java/net/taler/cashier/MainViewModel.kt
+++ b/cashier/src/main/java/net/taler/cashier/MainViewModel.kt
@@ -34,9 +34,9 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import net.taler.cashier.HttpHelper.makeJsonGetRequest
import net.taler.cashier.withdraw.WithdrawManager
-import net.taler.common.SignedAmount
import net.taler.common.getIncompatibleStringOrNull
import net.taler.common.isOnline
+import net.taler.lib.common.Amount
import net.taler.lib.common.AmountParserException
import net.taler.lib.common.Version
@@ -94,8 +94,7 @@ class MainViewModel(private val app: Application) : AndroidViewModel(app) {
val result = when (val response = makeJsonGetRequest(url, config)) {
is HttpJsonResult.Success -> {
// check if bank's version is compatible with app
- // TODO use real version response when fixed in bank
- val version = "0:0:0" // response.json.getString("version")
+ val version = response.json.getString("version")
val versionIncompatible = VERSION_BANK.getIncompatibleStringOrNull(app, version)
if (versionIncompatible != null) {
ConfigResult.Error(false, versionIncompatible)
@@ -141,11 +140,18 @@ class MainViewModel(private val app: Application) : AndroidViewModel(app) {
Log.d(TAG, "Checking balance at $url")
val result = when (val response = makeJsonGetRequest(url, config)) {
is HttpJsonResult.Success -> {
- val balance = response.json.getString("balance")
try {
- BalanceResult.Success(SignedAmount.fromJSONString(balance))
- } catch (e: AmountParserException) {
- BalanceResult.Error("invalid amount: $balance")
+ val balance = response.json.getString("balance")
+ val positive = when (val creditDebitIndicator =
+ response.json.getString("credit_debit_indicator")) {
+ "credit" -> true
+ "debit" -> false
+ else -> throw AmountParserException("Unexpected credit_debit_indicator: $creditDebitIndicator")
+ }
+ BalanceResult.Success(SignedAmount(positive, Amount.fromJSONString(balance)))
+ } catch (e: Exception) {
+ Log.e(TAG, "Error parsing balance", e)
+ BalanceResult.Error("Invalid amount:\n${response.json.toString(2)}")
}
}
is HttpJsonResult.Error -> {
diff --git a/cashier/src/main/java/net/taler/cashier/SignedAmount.kt b/cashier/src/main/java/net/taler/cashier/SignedAmount.kt
new file mode 100644
index 0000000..e79acfd
--- /dev/null
+++ b/cashier/src/main/java/net/taler/cashier/SignedAmount.kt
@@ -0,0 +1,30 @@
+/*
+ * This file is part of GNU Taler
+ * (C) 2020 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.cashier
+
+import net.taler.lib.common.Amount
+
+data class SignedAmount(
+ val positive: Boolean,
+ val amount: Amount
+) {
+
+ override fun toString(): String {
+ return if (positive) "$amount" else "-$amount"
+ }
+
+}