commit 5ae3ab2fca31a1dd593d94879ebbd6671188f4b8
parent 00393136136e6c4b51f88f4c37a93a91a08b87e4
Author: Iván Ávalos <avalos@disroot.org>
Date: Sun, 15 Feb 2026 09:53:05 +0100
[wallet] move performance stats to SettingsManager
Diffstat:
4 files changed, 40 insertions(+), 39 deletions(-)
diff --git a/wallet/src/main/java/net/taler/wallet/main/MainViewModel.kt b/wallet/src/main/java/net/taler/wallet/main/MainViewModel.kt
@@ -59,8 +59,6 @@ import androidx.core.net.toUri
import net.taler.wallet.BuildConfig
import net.taler.wallet.NetworkManager
import net.taler.wallet.donau.DonauManager
-import net.taler.wallet.settings.PerformanceTable
-import net.taler.wallet.settings.TestingGetPerformanceStatsResponse
const val TAG = "taler-wallet"
const val OBSERVABILITY_LIMIT = 100
@@ -140,9 +138,6 @@ class MainViewModel(
private val mObservabilityLog = MutableStateFlow<List<ObservabilityEvent>>(emptyList())
val observabilityLog: StateFlow<List<ObservabilityEvent>> = mObservabilityLog
- private val mPerformanceTable = MutableStateFlow<PerformanceTable?>(null)
- val performanceTable: StateFlow<PerformanceTable?> = mPerformanceTable
-
private val mScanCodeEvent = MutableLiveData<Event<Boolean>>()
val scanCodeEvent: LiveData<Event<Boolean>> = mScanCodeEvent
@@ -309,19 +304,6 @@ class MainViewModel(
}
}
- fun runIntegrationTest(onError: (error: TalerErrorInfo) -> Unit) {
- viewModelScope.launch {
- api.request<Unit>("runIntegrationTestV2") {
- put("amountToWithdraw", "KUDOS:42")
- put("amountToSpend", "KUDOS:23")
- put("corebankApiBaseUrl", "https://bank.demo.taler.net/")
- put("exchangeBaseUrl", "https://exchange.demo.taler.net/")
- put("merchantBaseUrl", "https://backend.demo.taler.net/instances/sandbox/")
- put("merchantAuthToken", "secret-token:sandbox")
- }.onError(onError)
- }
- }
-
fun applyDevExperiment(uri: String, onError: (error: TalerErrorInfo) -> Unit) {
viewModelScope.launch {
api.request<Unit>("applyDevExperiment") {
@@ -329,22 +311,6 @@ class MainViewModel(
}.onError(onError)
}
}
-
- fun loadPerformanceStats(limit: Int? = 10) {
- viewModelScope.launch {
- api.request(
- "testingGetPerformanceStats",
- TestingGetPerformanceStatsResponse.serializer(),
- ) {
- limit?.let { put("limit", limit) }
- this
- }.onError { error ->
- Log.e(TAG, "got testingGetPerformanceStats error result $error")
- }.onSuccess { res ->
- mPerformanceTable.value = res.stats
- }
- }
- }
}
enum class ScanQrContext {
diff --git a/wallet/src/main/java/net/taler/wallet/settings/PerformanceFragment.kt b/wallet/src/main/java/net/taler/wallet/settings/PerformanceFragment.kt
@@ -70,7 +70,7 @@ class PerformanceFragment: Fragment() {
) = ComposeView(requireContext()).apply {
setContent {
TalerSurface {
- val stats by model.performanceTable.collectAsStateLifecycleAware()
+ val stats by model.settingsManager.performanceTable.collectAsStateLifecycleAware()
if (stats == null) {
EmptyComposable()
@@ -79,7 +79,7 @@ class PerformanceFragment: Fragment() {
stats?.let {
PerformanceTableComposable(it,
- onReload = { model.loadPerformanceStats() },
+ onReload = { model.settingsManager.loadPerformanceStats() },
)
}
}
@@ -88,7 +88,7 @@ class PerformanceFragment: Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
- model.loadPerformanceStats()
+ model.settingsManager.loadPerformanceStats()
}
}
diff --git a/wallet/src/main/java/net/taler/wallet/settings/SettingsFragment.kt b/wallet/src/main/java/net/taler/wallet/settings/SettingsFragment.kt
@@ -215,7 +215,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
true
}
prefTest.setOnPreferenceClickListener {
- model.runIntegrationTest { error ->
+ settingsManager.runIntegrationTest { error ->
requireActivity().showError(error)
}
Snackbar.make(requireView(), getString(R.string.settings_test_running), LENGTH_LONG).show()
diff --git a/wallet/src/main/java/net/taler/wallet/settings/SettingsManager.kt b/wallet/src/main/java/net/taler/wallet/settings/SettingsManager.kt
@@ -23,17 +23,21 @@ import android.widget.Toast
import android.widget.Toast.LENGTH_LONG
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
-import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
+import kotlinx.serialization.json.JsonObject
import net.taler.wallet.R
+import net.taler.wallet.backend.TalerErrorInfo
import net.taler.wallet.main.ViewMode
import net.taler.wallet.backend.WalletBackendApi
import net.taler.wallet.backend.WalletResponse.Error
import net.taler.wallet.backend.WalletResponse.Success
import net.taler.wallet.balances.BalanceManager
+import net.taler.wallet.main.TAG
import org.json.JSONObject
class SettingsManager(
@@ -42,6 +46,9 @@ class SettingsManager(
private val scope: CoroutineScope,
private val balanceManager: BalanceManager,
) {
+ private val mPerformanceTable = MutableStateFlow<PerformanceTable?>(null)
+ val performanceTable: StateFlow<PerformanceTable?> = mPerformanceTable
+
fun getViewMode(c: Context) = c.userPreferencesDataStore.data.map { prefs ->
if (prefs.hasViewMode()) {
ViewMode.fromPrefs(prefs.viewMode)
@@ -246,4 +253,32 @@ class SettingsManager(
Toast.makeText(context, R.string.settings_db_clear_error, LENGTH_LONG).show()
}
+ fun runIntegrationTest(onError: (error: TalerErrorInfo) -> Unit) {
+ scope.launch {
+ api.request<Unit>("runIntegrationTestV2") {
+ put("amountToWithdraw", "KUDOS:42")
+ put("amountToSpend", "KUDOS:23")
+ put("corebankApiBaseUrl", "https://bank.demo.taler.net/")
+ put("exchangeBaseUrl", "https://exchange.demo.taler.net/")
+ put("merchantBaseUrl", "https://backend.demo.taler.net/instances/sandbox/")
+ put("merchantAuthToken", "secret-token:sandbox")
+ }.onError(onError)
+ }
+ }
+
+ fun loadPerformanceStats(limit: Int? = 10) {
+ scope.launch {
+ api.request(
+ "testingGetPerformanceStats",
+ TestingGetPerformanceStatsResponse.serializer(),
+ ) {
+ limit?.let { put("limit", limit) }
+ this
+ }.onError { error ->
+ Log.e(TAG, "got testingGetPerformanceStats error result $error")
+ }.onSuccess { res ->
+ mPerformanceTable.value = res.stats
+ }
+ }
+ }
}