commit 8d56c1db12b80288fca092d97009ae74de36fffb
parent 4b4cf989aa0bfb5e9223ced86242cdd51be47701
Author: Iván Ávalos <avalos@disroot.org>
Date: Wed, 13 Mar 2024 12:48:44 -0600
[wallet] Cache currencySpec in loadBalances()
(cherry picked from commit cd7cd4c79b727f470bed3f8ecff0fa4790beee57)
Diffstat:
1 file changed, 11 insertions(+), 2 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
@@ -65,6 +65,8 @@ class BalanceManager(
private val mState = MutableLiveData<BalanceState>(BalanceState.None)
val state: LiveData<BalanceState> = mState.distinctUntilChanged()
+ private var currencySpecs: Map<ScopeInfo, CurrencySpecification?>? = null
+
@UiThread
fun loadBalances() {
mState.value = BalanceState.Loading
@@ -77,10 +79,17 @@ class BalanceManager(
response.onSuccess {
mState.postValue(BalanceState.Success(it.balances))
scope.launch {
- // Get currency spec for all balances)
+ // Get currency spec for all balances
+ if (currencySpecs == null) {
+ currencySpecs = it.balances.associate { balance ->
+ val spec = getCurrencySpecification(balance.scopeInfo)
+ balance.scopeInfo to spec
+ }
+ }
+
mState.postValue(
BalanceState.Success(it.balances.map { balance ->
- val spec = getCurrencySpecification(balance.scopeInfo)
+ val spec = currencySpecs?.get(balance.scopeInfo)
balance.copy(
available = balance.available.withSpec(spec),
pendingIncoming = balance.pendingIncoming.withSpec(spec),