taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 567b7dac6cb1dfaeb9f33286c8edecdbbac8cfb7
parent f4d83b7c66eca946af7fc6a94cee5e5f107e28d1
Author: Iván Ávalos <avalos@disroot.org>
Date:   Thu, 10 Apr 2025 17:22:16 +0200

wallet-core: sort balances by scopeInfo

Diffstat:
Mpackages/taler-wallet-core/src/balance.ts | 19++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/packages/taler-wallet-core/src/balance.ts b/packages/taler-wallet-core/src/balance.ts @@ -131,6 +131,16 @@ function getBalanceKey(scopeInfo: ScopeInfo): string { } } +function getScopeSortingOrder(scopeInfo: ScopeInfo): number { + switch (scopeInfo.type) { + case ScopeType.Global: return 0; + case ScopeType.Auditor: return 1; + case ScopeType.Exchange: return 2; + default: + assertUnreachable(scopeInfo); + } +} + class BalancesStore { private exchangeScopeCache: Record<string, ScopeInfo> = {}; private balanceStore: Record<string, WalletBalance> = {}; @@ -245,7 +255,14 @@ class BalancesStore { const balanceStore = this.balanceStore; Object.keys(balanceStore) - .sort() + .sort((a, b) => { + const balanceA = balanceStore[a]; + const balanceB = balanceStore[b]; + const scopeA = getScopeSortingOrder(balanceA.scopeInfo); + const scopeB = getScopeSortingOrder(balanceB.scopeInfo); + if (scopeA !== scopeB) return (scopeA - scopeB); + return a.localeCompare(b); + }) .forEach((c) => { const v = balanceStore[c]; const flags: BalanceFlag[] = [];