Skip to content

Commit 7acb67f

Browse files
committed
Fix search footer currency label after failed refresh
Only use the selected footer currency for server totals when metadata confirms it, so stale totals are not shown with a new currency label after a failed target-currency search.
1 parent a652ba1 commit 7acb67f

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/pages/Search/SearchPage.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,12 @@ function SearchPage({route}: SearchPageProps) {
168168

169169
const shouldUseClientTotal = selectedTransactionsKeys.length > 0 || !metadata?.count;
170170
const selectedTransactionItems = Object.values(selectedTransactions);
171+
const footerSelectedCurrency = !selectedCurrency || shouldUseClientTotal || metadata?.currency === selectedCurrency ? selectedCurrency : undefined;
171172
const isSelectedSubtotalLoading =
172-
shouldUseClientTotal && !!selectedCurrency && selectedTransactionItems.some((transaction) => !!transaction.groupCurrency && transaction.groupCurrency !== selectedCurrency);
173-
const currency = selectedCurrency ?? metadata?.currency ?? selectedTransactionItems.at(0)?.groupCurrency ?? selectedTransactionItems.at(0)?.currency;
173+
shouldUseClientTotal &&
174+
!!footerSelectedCurrency &&
175+
selectedTransactionItems.some((transaction) => !!transaction.groupCurrency && transaction.groupCurrency !== footerSelectedCurrency);
176+
const currency = footerSelectedCurrency ?? metadata?.currency ?? selectedTransactionItems.at(0)?.groupCurrency ?? selectedTransactionItems.at(0)?.currency;
174177
const numberOfExpense = shouldUseClientTotal
175178
? selectedTransactionsKeys.reduce((count, key) => {
176179
const item = selectedTransactions[key];
@@ -182,7 +185,7 @@ function SearchPage({route}: SearchPageProps) {
182185
: metadata?.count;
183186
const total = shouldUseClientTotal
184187
? selectedTransactionItems.reduce((acc, transaction) => {
185-
const shouldUseGroupAmount = !selectedCurrency || transaction.groupCurrency === selectedCurrency;
188+
const shouldUseGroupAmount = !footerSelectedCurrency || transaction.groupCurrency === footerSelectedCurrency;
186189
return acc - (shouldUseGroupAmount ? (transaction.groupAmount ?? -Math.abs(transaction.amount)) : -Math.abs(transaction.amount));
187190
}, 0)
188191
: metadata?.total;

0 commit comments

Comments
 (0)