aboutsummaryrefslogtreecommitdiff
path: root/cashier/src
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2020-07-30 16:40:23 -0300
committerTorsten Grote <t@grobox.de>2020-07-30 16:40:23 -0300
commit8815105bf2462787885214a12af927d484226f21 (patch)
tree597076d6970e336b881d68ca6b48577b007c9730 /cashier/src
parente19ba096d57353db6b1f141da4bf170ef2d2d534 (diff)
downloadtaler-android-8815105bf2462787885214a12af927d484226f21.tar.gz
taler-android-8815105bf2462787885214a12af927d484226f21.tar.bz2
taler-android-8815105bf2462787885214a12af927d484226f21.zip
Split out common code into multiplatform Kotlin library
Diffstat (limited to 'cashier/src')
-rw-r--r--cashier/src/main/java/net/taler/cashier/MainViewModel.kt16
1 files changed, 9 insertions, 7 deletions
diff --git a/cashier/src/main/java/net/taler/cashier/MainViewModel.kt b/cashier/src/main/java/net/taler/cashier/MainViewModel.kt
index c8d9a3b..a4fd35e 100644
--- a/cashier/src/main/java/net/taler/cashier/MainViewModel.kt
+++ b/cashier/src/main/java/net/taler/cashier/MainViewModel.kt
@@ -40,6 +40,7 @@ import net.taler.common.isOnline
private val TAG = MainViewModel::class.java.simpleName
+private const val VERSION_BANK = "0:0:0"
private const val PREF_NAME = "net.taler.cashier.prefs"
private const val PREF_KEY_BANK_URL = "bankUrl"
private const val PREF_KEY_USERNAME = "username"
@@ -86,20 +87,21 @@ class MainViewModel(private val app: Application) : AndroidViewModel(app) {
fun checkAndSaveConfig(config: Config) {
mConfigResult.value = null
viewModelScope.launch(Dispatchers.IO) {
- val url = "${config.bankUrl}/accounts/${config.username}/balance"
+ val url = "${config.bankUrl}/config"
Log.d(TAG, "Checking config: $url")
val result = when (val response = makeJsonGetRequest(url, config)) {
is HttpJsonResult.Success -> {
- val balance = response.json.getString("balance")
+ val version = response.json.getString("version")
+ // TODO check if version is compatible
+ val currency = response.json.getString("currency")
try {
- val amount = SignedAmount.fromJSONString(balance)
- mCurrency.postValue(amount.amount.currency)
- prefs.edit().putString(PREF_KEY_CURRENCY, amount.amount.currency).apply()
+ mCurrency.postValue(currency)
+ prefs.edit().putString(PREF_KEY_CURRENCY, currency).apply()
// save config
saveConfig(config)
ConfigResult.Success
- } catch (e: AmountParserException) {
- ConfigResult.Error(false, "Invalid Amount: $balance")
+ } catch (e: Exception) {
+ ConfigResult.Error(false, "Invalid Config: ${response.json}")
}
}
is HttpJsonResult.Error -> {