aboutsummaryrefslogtreecommitdiff
path: root/cashier/src/main
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-09-03 22:57:39 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-09-03 22:57:49 +0530
commit4572a3d5fc5ae5f3bbeaa8836fb919dcec0483e0 (patch)
tree640d7336d6d74987f4eca0d4773d768677671ab6 /cashier/src/main
parentce5a1d2476b1a344b881dd92840934925aedd394 (diff)
downloadtaler-android-4572a3d5fc5ae5f3bbeaa8836fb919dcec0483e0.tar.gz
taler-android-4572a3d5fc5ae5f3bbeaa8836fb919dcec0483e0.tar.bz2
taler-android-4572a3d5fc5ae5f3bbeaa8836fb919dcec0483e0.zip
[cashier] API change
Diffstat (limited to 'cashier/src/main')
-rw-r--r--cashier/src/main/java/net/taler/cashier/MainViewModel.kt9
1 files changed, 5 insertions, 4 deletions
diff --git a/cashier/src/main/java/net/taler/cashier/MainViewModel.kt b/cashier/src/main/java/net/taler/cashier/MainViewModel.kt
index 2fd53a3..2cce8cd 100644
--- a/cashier/src/main/java/net/taler/cashier/MainViewModel.kt
+++ b/cashier/src/main/java/net/taler/cashier/MainViewModel.kt
@@ -64,19 +64,20 @@ class MainViewModel(private val app: Application) : AndroidViewModel(app) {
fun getBalance() = viewModelScope.launch(Dispatchers.IO) {
check(configManager.hasConfig()) { "No config to get balance" }
val config = configManager.config
- val url = "${config.bankUrl}/accounts/${config.username}/balance"
+ val url = "${config.bankUrl}/accounts/${config.username}"
Log.d(TAG, "Checking balance at $url")
val result = when (val response = makeJsonGetRequest(url, config)) {
is HttpJsonResult.Success -> {
try {
- val balance = response.json.getString("amount")
+ val balanceObj = response.json.getJSONObject("balance");
+ val balanceAmount = balanceObj.getString("amount")
val positive = when (val creditDebitIndicator =
- response.json.getString("credit_debit_indicator")) {
+ balanceObj.getString("credit_debit_indicator")) {
"credit" -> true
"debit" -> false
else -> throw AmountParserException("Unexpected credit_debit_indicator: $creditDebitIndicator")
}
- BalanceResult.Success(SignedAmount(positive, Amount.fromJSONString(balance)))
+ BalanceResult.Success(SignedAmount(positive, Amount.fromJSONString(balanceAmount)))
} catch (e: Exception) {
Log.e(TAG, "Error parsing balance", e)
BalanceResult.Error("Invalid amount:\n${response.json.toString(2)}")