Skip to content
This repository was archived by the owner on Nov 20, 2026. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/desktop-client/e2e/reports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ test.describe('Reports', () => {

reportsPage = await navigation.goToReportsPage();
await reportsPage.waitToLoad();
// After Settings: visiting it clears Main while the currency flag is off.
await configurationPage.initializeTestMainCurrency();
await reportsPage.addWidget('Balance forecast');
await reportsPage.goToBalanceForecastPage();
});
Expand Down Expand Up @@ -150,6 +152,8 @@ test.describe('Reports', () => {

reportsPage = await navigation.goToReportsPage();
await reportsPage.waitToLoad();
// Settings (Tracking budget type) cleared Main again.
await configurationPage.initializeTestMainCurrency();
await reportsPage.goToBalanceForecastPage();
await reportsPage.selectForecastSource('Tracking budget');

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import type { ReactNode } from 'react';
import { useTranslation } from 'react-i18next';

import { Block } from '@actual-app/components/block';
import { theme } from '@actual-app/components/theme';

import { hasForeignAccount } from '#components/reports/spreadsheets/report-currency';
import { useAccounts } from '#hooks/useAccounts';
import { useSyncedPrefs } from '#hooks/useSyncedPrefs';

function UnconvertedCurrencyNotice({
accountIds,
children,
}: {
/** Limit the check to these accounts; all accounts when omitted. */
accountIds?: string[];
children: (currencyCode: string) => ReactNode;
}) {
const [prefs] = useSyncedPrefs();
const { data: accounts = [] } = useAccounts();

const relevant = accountIds
? accounts.filter(account => accountIds.includes(account.id))
: accounts;
if (!prefs.defaultCurrencyCode || !hasForeignAccount(relevant, prefs)) {
return null;
}

return (
<Block
role="note"
style={{ padding: '0 20px 8px', color: theme.pageTextSubdued }}
>
{children(prefs.defaultCurrencyCode)}
</Block>
);
}

/**
* Formula output has no account denomination, so it is never converted to
* Main. Warn when foreign-currency accounts exist that it may mix amounts.
*/
export function FormulaCurrencyNotice() {
const { t } = useTranslation();
return (
<UnconvertedCurrencyNotice>
{currencyCode =>
t(
'Formula results are not converted to {{currencyCode}}. Formulas that combine foreign-currency account amounts are unsupported and may mix currencies.',
{ currencyCode },
)
}
</UnconvertedCurrencyNotice>
);
}

/** Monte Carlo pots read native balances from their linked accounts. */
export function MonteCarloCurrencyNotice({
accountIds,
}: {
accountIds: string[];
}) {
const { t } = useTranslation();
return (
<UnconvertedCurrencyNotice accountIds={accountIds}>
{currencyCode =>
t(
'Linked foreign-currency account balances are not converted to {{currencyCode}}. Results are unsupported for those pots.',
{ currencyCode },
)
}
</UnconvertedCurrencyNotice>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ import { computePadding } from '#components/reports/graphs/util/computePadding';
import { Header } from '#components/reports/Header';
import { LoadingIndicator } from '#components/reports/LoadingIndicator';
import { useAccounts } from '#hooks/useAccounts';
import { useBalanceForecast } from '#hooks/useBalanceForecast';
import { useDashboardWidget } from '#hooks/useDashboardWidget';
import { useFormat } from '#hooks/useFormat';
import { useLocale } from '#hooks/useLocale';
import { useMainBalanceForecast } from '#hooks/useMainBalanceForecast';
import { usePrivacyMode } from '#hooks/usePrivacyMode';
import { useRuleConditionFilters } from '#hooks/useRuleConditionFilters';
import { useSyncedPref } from '#hooks/useSyncedPref';
import { useSyncedPrefs } from '#hooks/useSyncedPrefs';
import { addNotification } from '#notifications/notificationsSlice';
import { useDispatch } from '#redux';

Expand Down Expand Up @@ -76,6 +77,7 @@ type BalanceForecastInnerProps = {
function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
const { t } = useTranslation();
const format = useFormat();
const [prefs] = useSyncedPrefs();
const privacyMode = usePrivacyMode();
const locale = useLocale();
const dispatch = useDispatch();
Expand Down Expand Up @@ -142,7 +144,9 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
isFetching,
isPlaceholderData,
isPending: isLoading,
} = useBalanceForecast({
unavailable,
hasForeignCurrency,
} = useMainBalanceForecast({
accountIds: isTrackingBudgetForecast
? undefined
: widget
Expand All @@ -158,8 +162,11 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
source,
enabled: hasMonthOptions,
});
const errorMessage =
error instanceof Error
const errorMessage = unavailable
? t(
'Balance forecast is unavailable. Check that a Main currency is set and every included account has a valid exchange rate.',
)
: error instanceof Error
? error.message
: error
? t('Failed to load forecast')
Expand Down Expand Up @@ -319,7 +326,7 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
return <LoadingIndicator />;
}

if (isLoading && !normalizedForecastData) {
if (isLoading && !normalizedForecastData && !unavailable) {
return <LoadingIndicator />;
}

Expand Down Expand Up @@ -424,6 +431,14 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
overflowY: 'auto',
}}
>
{hasForeignCurrency && (
<View style={{ paddingTop: 10 }}>
{t(
'Values in {{currencyCode}}. Foreign-currency history is an estimate at current rates.',
{ currencyCode: prefs.defaultCurrencyCode },
)}
</View>
)}
{errorMessage ? (
<div style={{ color: theme.errorText, marginBottom: 20 }}>
{errorMessage}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ import { LoadingIndicator } from '#components/reports/LoadingIndicator';
import { ReportCard } from '#components/reports/ReportCard';
import { ReportCardName } from '#components/reports/ReportCardName';
import { calculateTimeRange } from '#components/reports/reportRanges';
import { useBalanceForecast } from '#hooks/useBalanceForecast';
import { useFormat } from '#hooks/useFormat';
import { useMainBalanceForecast } from '#hooks/useMainBalanceForecast';
import { useSyncedPref } from '#hooks/useSyncedPref';
import { useSyncedPrefs } from '#hooks/useSyncedPrefs';

import {
buildBalanceForecastChartData,
Expand All @@ -54,6 +55,7 @@ export function BalanceForecastCard({
}: BalanceForecastCardProps) {
const { t } = useTranslation();
const format = useFormat();
const [prefs] = useSyncedPrefs();
const [budgetTypePref] = useSyncedPref('budgetType');
const budgetType = budgetTypePref === 'tracking' ? 'tracking' : 'envelope';
const source =
Expand Down Expand Up @@ -89,7 +91,9 @@ export function BalanceForecastCard({
isFetching,
isPlaceholderData,
isPending: isLoading,
} = useBalanceForecast({
unavailable,
hasForeignCurrency,
} = useMainBalanceForecast({
accountIds: isTrackingBudgetForecast ? undefined : selectedAccountIds,
conditions: isTrackingBudgetForecast ? undefined : meta?.conditions,
conditionsOp: isTrackingBudgetForecast ? undefined : meta?.conditionsOp,
Expand All @@ -100,8 +104,11 @@ export function BalanceForecastCard({
: meta?.accounts === undefined,
source,
});
const errorMessage =
error instanceof Error
const errorMessage = unavailable
? t(
'Balance forecast is unavailable. Check that a Main currency is set and every included account has a valid exchange rate.',
)
: error instanceof Error
? error.message
: error
? t('Failed to load forecast')
Expand Down Expand Up @@ -217,7 +224,16 @@ export function BalanceForecastCard({
)}
</View>

{isLoading && !normalizedForecastData ? (
{hasForeignCurrency && (
<Block style={{ padding: '0 20px 8px' }}>
{t(
'Values in {{currencyCode}}. Foreign-currency history is an estimate at current rates.',
{ currencyCode: prefs.defaultCurrencyCode },
)}
</Block>
)}

{isLoading && !normalizedForecastData && !unavailable ? (
<LoadingIndicator />
) : errorMessage ? (
<View style={{ height: 120, padding: 20 }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { LoadingIndicator } from '#components/reports/LoadingIndicator';
import { calculateTimeRange } from '#components/reports/reportRanges';
import { createCrossoverSpreadsheet } from '#components/reports/spreadsheets/crossover-spreadsheet';
import type { CrossoverData } from '#components/reports/spreadsheets/crossover-spreadsheet';
import type { ReportDataStatus } from '#components/reports/spreadsheets/report-currency';
import { useReport } from '#components/reports/useReport';
import { useAccounts } from '#hooks/useAccounts';
import { useCategories } from '#hooks/useCategories';
Expand All @@ -45,6 +46,7 @@ import { useFormat } from '#hooks/useFormat';
import { useLocale } from '#hooks/useLocale';
import { useNavigate } from '#hooks/useNavigate';
import type { useSpreadsheet } from '#hooks/useSpreadsheet';
import { useSyncedPrefs } from '#hooks/useSyncedPrefs';
import { addNotification } from '#notifications/notificationsSlice';
import { useDispatch } from '#redux';
import { useUpdateDashboardWidgetMutation } from '#reports/mutations';
Expand Down Expand Up @@ -75,7 +77,12 @@ function CrossoverInner({ widget }: CrossoverInnerProps) {
const locale = useLocale();
const { t } = useTranslation();
const dispatch = useDispatch();
const { data: accounts = [] } = useAccounts();
const {
data: accounts = [],
isLoading: accountsLoading,
isPlaceholderData: accountsPlaceholderData,
} = useAccounts();
const [prefs] = useSyncedPrefs();
const {
data: categories = { grouped: [], list: [] },
isPending: isCategoriesLoading,
Expand Down Expand Up @@ -331,7 +338,7 @@ function CrossoverInner({ widget }: CrossoverInnerProps) {
const params = useCallback(
async (
spreadsheet: ReturnType<typeof useSpreadsheet>,
setData: (data: CrossoverData) => void,
setData: (data: CrossoverData | ReportDataStatus) => void,
) => {
// Don't run if dates are not yet initialized
if (!start || !end) {
Expand All @@ -350,6 +357,9 @@ function CrossoverInner({ widget }: CrossoverInnerProps) {
: null,
projectionType,
expenseAdjustmentFactor,
accounts,
prefs,
accountsReady: !accountsLoading && !accountsPlaceholderData,
});
await crossoverSpreadsheet(spreadsheet, setData);
},
Expand All @@ -364,10 +374,22 @@ function CrossoverInner({ widget }: CrossoverInnerProps) {
expenseAdjustmentFactor,
expenseCategoryIds,
selectedIncomeAccountIds,
accounts,
prefs,
accountsLoading,
accountsPlaceholderData,
],
);

const data = useReport<CrossoverData>('crossover', params);
const reportData = useReport<CrossoverData | ReportDataStatus>(
'crossover',
params,
);
const data = reportData && 'graphData' in reportData ? reportData : null;
const reportUnavailable =
!!reportData &&
'status' in reportData &&
reportData.status === 'unavailable';
const [previousData, setPreviousData] = useState<CrossoverData | null>(null);

useEffect(() => {
Expand All @@ -376,7 +398,9 @@ function CrossoverInner({ widget }: CrossoverInnerProps) {
}
}, [data]);

const displayData = data ?? previousData;
// Never keep showing a stale (possibly mixed-denomination) result once the
// current calculation is unavailable.
const displayData = reportUnavailable ? null : (data ?? previousData);

// Get the default estimated return from the spreadsheet data
const historicalReturn = displayData?.historicalReturn ?? null;
Expand Down Expand Up @@ -419,6 +443,19 @@ function CrossoverInner({ widget }: CrossoverInnerProps) {
});
};

if (reportUnavailable) {
return (
<Page header={<PageHeader title={title} />}>
<View role="status" aria-live="polite" style={{ padding: 20 }}>
<Trans>
Crossover point is unavailable. Check that a Main currency is set
and every included account has a valid exchange rate.
</Trans>
</View>
</Page>
);
}

if (!allMonths || !displayData || !start || !end || isCategoriesLoading) {
return <LoadingIndicator />;
}
Expand Down Expand Up @@ -1036,6 +1073,14 @@ function CrossoverInner({ widget }: CrossoverInnerProps) {
flex: 1,
}}
>
{displayData.hasForeignCurrency && (
<View style={{ padding: '0 20px 8px' }}>
{t(
'Values in {{currencyCode}}. Foreign-currency history is an estimate at current rates.',
{ currencyCode: prefs.defaultCurrencyCode },
)}
</View>
)}
{/* Header stats */}
<View
style={{
Expand Down
Loading
Loading