diff options
author | Iván Ávalos <avalos@disroot.org> | 2024-03-19 09:06:52 -0600 |
---|---|---|
committer | Torsten Grote <t@grobox.de> | 2024-03-27 14:26:45 -0300 |
commit | 18a8322c2cc7d2fcee712f29095b4db28098550e (patch) | |
tree | dda67fe41e232cef3ca89189d12f3e68961bedc2 | |
parent | 881eeabd3999c75c1961eacb2921b41d3a8f58bb (diff) | |
download | taler-android-18a8322c2cc7d2fcee712f29095b4db28098550e.tar.gz taler-android-18a8322c2cc7d2fcee712f29095b4db28098550e.tar.bz2 taler-android-18a8322c2cc7d2fcee712f29095b4db28098550e.zip |
[wallet] Cache currency spec per scope info
(cherry picked from commit ef2c87b0131138d412cd35c1595ecac4808fa155)
-rw-r--r-- | wallet/src/main/java/net/taler/wallet/balances/BalanceManager.kt | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/balances/BalanceManager.kt b/wallet/src/main/java/net/taler/wallet/balances/BalanceManager.kt index 4558396..4448490 100644 --- a/wallet/src/main/java/net/taler/wallet/balances/BalanceManager.kt +++ b/wallet/src/main/java/net/taler/wallet/balances/BalanceManager.kt @@ -65,7 +65,7 @@ class BalanceManager( private val mState = MutableLiveData<BalanceState>(BalanceState.None) val state: LiveData<BalanceState> = mState.distinctUntilChanged() - private var currencySpecs: Map<ScopeInfo, CurrencySpecification?>? = null + private val currencySpecs: MutableMap<ScopeInfo, CurrencySpecification?> = mutableMapOf() @UiThread fun loadBalances() { @@ -79,17 +79,16 @@ class BalanceManager( response.onSuccess { mState.postValue(BalanceState.Success(it.balances)) scope.launch { - // Get currency spec for all balances - if (currencySpecs == null) { - currencySpecs = it.balances.associate { balance -> - val spec = getCurrencySpecification(balance.scopeInfo) - balance.scopeInfo to spec + // Fetch missing currency specs for all balances + it.balances.forEach { balance -> + if (!currencySpecs.containsKey(balance.scopeInfo)) { + currencySpecs[balance.scopeInfo] = getCurrencySpecification(balance.scopeInfo) } } mState.postValue( BalanceState.Success(it.balances.map { balance -> - val spec = currencySpecs?.get(balance.scopeInfo) + val spec = currencySpecs[balance.scopeInfo] balance.copy( available = balance.available.withSpec(spec), pendingIncoming = balance.pendingIncoming.withSpec(spec), |