diff options
Diffstat (limited to 'cashier/src/main/java')
-rw-r--r-- | cashier/src/main/java/net/taler/cashier/MainViewModel.kt | 10 | ||||
-rw-r--r-- | cashier/src/main/java/net/taler/cashier/config/ConfigManager.kt | 3 |
2 files changed, 10 insertions, 3 deletions
diff --git a/cashier/src/main/java/net/taler/cashier/MainViewModel.kt b/cashier/src/main/java/net/taler/cashier/MainViewModel.kt index 1c819b9..2196e78 100644 --- a/cashier/src/main/java/net/taler/cashier/MainViewModel.kt +++ b/cashier/src/main/java/net/taler/cashier/MainViewModel.kt @@ -28,6 +28,7 @@ import io.ktor.client.plugins.contentnegotiation.ContentNegotiation import io.ktor.serialization.kotlinx.json.json import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch +import kotlinx.serialization.json.Json import net.taler.cashier.HttpHelper.makeJsonGetRequest import net.taler.cashier.config.ConfigManager import net.taler.cashier.withdraw.WithdrawManager @@ -45,8 +46,12 @@ class MainViewModel(private val app: Application) : AndroidViewModel(app) { retryOnConnectionFailure(true) } } + expectSuccess = true install(ContentNegotiation) { - json() + json(Json { + encodeDefaults = false + ignoreUnknownKeys = true + }) } } val configManager = ConfigManager(app, viewModelScope, httpClient) @@ -72,7 +77,8 @@ class MainViewModel(private val app: Application) : AndroidViewModel(app) { "debit" -> false else -> throw AmountParserException("Unexpected credit_debit_indicator: $creditDebitIndicator") } - BalanceResult.Success(SignedAmount(positive, Amount.fromJSONString(balanceAmount))) + 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)}") diff --git a/cashier/src/main/java/net/taler/cashier/config/ConfigManager.kt b/cashier/src/main/java/net/taler/cashier/config/ConfigManager.kt index 882348f..2fde37d 100644 --- a/cashier/src/main/java/net/taler/cashier/config/ConfigManager.kt +++ b/cashier/src/main/java/net/taler/cashier/config/ConfigManager.kt @@ -29,6 +29,7 @@ import androidx.security.crypto.EncryptedSharedPreferences.PrefValueEncryptionSc import androidx.security.crypto.MasterKeys import androidx.security.crypto.MasterKeys.AES256_GCM_SPEC import io.ktor.client.HttpClient +import io.ktor.client.call.body import io.ktor.client.request.get import io.ktor.client.request.header import io.ktor.http.HttpHeaders.Authorization @@ -116,7 +117,7 @@ class ConfigManager( val url = "${config.bankUrl}/config" Log.d(TAG, "Checking config: $url") val configResponse = response { - httpClient.get(url) as ConfigResponse + httpClient.get(url).body<ConfigResponse>() } if (configResponse.isFailure) { configResponse |