feat: every page follows the one-currency mode

Totals, info boxes, section headers, group subtotals, shares and the
per-currency charts on the dashboard, transactions, search, accounts,
merchants, statement, budgets, categories, tags, groups, piggy banks,
reports and the category, tag, budget and merchant pages sum into one
converted amount when the mode is on; charts split by currency merge
into one lane. Inputs, reconciliation and the Foreign column stay exact.

Money moved to or from a debt, loan or mortgage no longer counts as
income or spending in the transaction list boxes; it shows as From
debts and To debts. The running balance of an incoming foreign-currency
transfer shows in the account's currency.
This commit is contained in:
hh committed 2026-10-16 18:49:16 +00:00
1 parent 94466d9be9
commit 617a4700e2
61 files changed
+1427 -798

No files matched your search

+57
View File
@@ -0,0 +1,57 @@
import { display } from "#lib/money/display.svelte.js";
import type { Flow } from "./flows.js";
const MARK = "≈";
export const isApprox = (code: string) => code.startsWith(MARK);
export const plainCode = (code: string) =>
isApprox(code) ? code.slice(MARK.length) : code;
export function displayCode(codes: Iterable<string>): string | null {
if (!display.active) {
return null;
}
for (const code of codes) {
if (code !== display.code && display.rate(code) !== null) {
return `${MARK}${display.code}`;
}
}
return null;
}
export const shownCode = (code: string, into: string | null) =>
into && display.rate(code) !== null ? into : code;
export function inDisplay(
amount: number,
code: string,
into: string | null = displayCode([code])
): { amount: number; code: string } {
const value = into ? display.convert(amount, code) : null;
return into && value !== null
? { amount: value, code: into }
: { amount, code };
}
export function displayFlows(
flows: Flow[],
into = displayCode(new Set(flows.map((flow) => flow.currency)))
): Flow[] {
if (!into) {
return flows;
}
const rates = new Map<string, number | null>();
const rateOf = (code: string) => {
if (!rates.has(code)) {
rates.set(code, display.rate(code));
}
return rates.get(code) ?? null;
};
return flows.map((flow) => {
const rate = rateOf(flow.currency);
return rate === null
? flow
: { ...flow, amount: flow.amount * rate, currency: into };
});
}
+40 -7
View File
@@ -6,6 +6,13 @@ import { formatMoney } from "#lib/format.js";
import { session } from "#lib/session.svelte.js";
import { goto } from "$app/navigation";
import { page } from "$app/state";
import {
displayCode,
displayFlows,
inDisplay,
isApprox,
plainCode,
} from "./display.js";
import {
type Dimension,
exchanges,
@@ -81,11 +88,12 @@ export function allAssetIds(accounts: Item<Account>[]): string[] {
}
export function currencyMeta(code: string) {
const found = session.currencies.find((c) => c.attributes.code === code);
const plain = plainCode(code);
const found = session.currencies.find((c) => c.attributes.code === plain);
return {
code,
code: plain,
decimals: found?.attributes.decimal_places ?? 2,
symbol: found?.attributes.symbol ?? code,
symbol: found?.attributes.symbol ?? plain,
};
}
@@ -104,10 +112,21 @@ export function money(
symbol: primary.symbol,
}
: currencyMeta(code);
return formatMoney(
const text = formatMoney(
{ amount, ...meta, decimals: decimals ?? meta.decimals },
signed
);
return isApprox(code) ? `≈${text}` : text;
}
export function displayMoney(
code: string,
amount: number,
signed = false,
decimals?: number
) {
const shown = inDisplay(amount, code);
return money(shown.code, shown.amount, signed, decimals);
}
export function modeLabel(mode: string) {
@@ -267,7 +286,8 @@ const inRange = (group: Item<TransactionGroup>, start: string, end: string) => {
export function createReport(
params: () => ReportParams,
source?: () => Item<TransactionGroup>[] | undefined
source?: () => Item<TransactionGroup>[] | undefined,
target?: () => string | null
) {
const p = $derived(params());
const kind = $derived(kindOf(p.type));
@@ -373,11 +393,18 @@ export function createReport(
: new Set<string>()
);
const flows = $derived(
const raw = $derived(
groups && accountsReady
? toFlows(groups, selectedSet, (id) => byId.get(id)?.currency_code)
: undefined
);
const into = $derived.by(() => {
if (target) {
return target();
}
return raw ? displayCode(new Set(raw.map((flow) => flow.currency))) : null;
});
const flows = $derived(raw && displayFlows(raw, into));
const swaps = $derived(
groups && accountsReady
@@ -420,7 +447,10 @@ export function createReport(
const codes = $derived.by(() => {
const primary = session.primary?.code;
const all = session.currencies.map((c) => c.attributes.code);
return primary ? [primary, ...all.filter((c) => c !== primary)] : all;
const ordered = primary
? [primary, ...all.filter((c) => c !== primary)]
: all;
return into ? [into, ...ordered] : ordered;
});
const available = $derived(totals ? modes(totals, codes) : []);
const mode = $derived.by(() => {
@@ -480,6 +510,9 @@ export function createReport(
get groups() {
return groups;
},
get into() {
return into;
},
itemName: (kindKey: string, id: string) =>
itemNames.get(`${kindKey}:${id}`),
get items() {