refactor!: support RUB only (WealthLedger/main#55) (#168)
Frontend verify / commits (push) Skipped
Frontend verify / security (push) Successful in 11s
Frontend verify / verify (push) Failing after 9m0s

This commit was merged in pull request #168.
This commit is contained in:
2026-11-11 09:36:29 +03:00
parent e2062ce837
commit 2b94a16ae5
55 changed files with 540 additions and 1153 deletions
@@ -25,34 +25,16 @@ type AccountsPageLoadedProps = {
readRetry?: ReadRetryProps;
};
type Money = { currency: string; value: string };
function accountTotals(accounts: BrokerageAccountCard[]) {
const values = new Map<string, string[]>();
let excludedCount = 0;
function accountTotals(accounts: BrokerageAccountCard[]): null | string {
const values: string[] = [];
for (const { summary } of accounts) {
if (summary.state === "empty") continue;
if (summary.state !== "available") continue;
if (summary.state === "unavailable") {
excludedCount += 1;
continue;
}
for (const total of summary.portfolio.totalsByCurrency) {
values.set(total.currency, [
...values.get(total.currency) ?? [],
total.value,
]);
}
values.push(summary.portfolio.totals.value);
}
const totals: Money[] = Array.from(values, ([currency, amounts]) => ({
currency,
value: sumDecimals(amounts),
}));
return { excludedCount, totals };
return values.length > 0 ? sumDecimals(values) : null;
}
function sumDecimals(values: string[]) {
@@ -88,9 +70,11 @@ function sumDecimals(values: string[]) {
const AccountsPageLoaded: FC<AccountsPageLoadedProps> = (props) => {
const { t } = useTranslation();
const { excludedCount, totals } = accountTotals(props.accounts);
const primaryTotal = totals.find(total => total.currency === "RUB") ?? totals[0];
const otherTotals = totals.filter(total => total !== primaryTotal);
const total = accountTotals(props.accounts);
const excludedCount = props.accounts.filter(
account => account.summary.state === "unavailable",
).length;
return (
<Stack gap="lg">
@@ -101,25 +85,15 @@ const AccountsPageLoaded: FC<AccountsPageLoadedProps> = (props) => {
{t("accounts.currentValue")}
</Text>
{primaryTotal
{total === null
? (
<Text className={classes.primaryTotal} fw={700}>
{formatMoney(primaryTotal, { withRoundedCents: true })}
</Text>
<Text c="dimmed">{t("accounts.summaryNoTotals")}</Text>
)
: (
<Text c="dimmed">{t("accounts.summaryNoTotals")}</Text>
)}
{otherTotals.length > 0 && (
<Group gap="md" wrap="wrap">
{otherTotals.map(total => (
<Text className={classes.otherTotal} key={total.currency}>
{formatMoney(total, { withRoundedCents: true })}
<Text className={classes.primaryTotal} fw={700}>
{formatMoney({ currency: "RUB", value: total }, { withRoundedCents: true })}
</Text>
))}
</Group>
)}
)}
<Group className={classes.meta} gap="xs" wrap="wrap">
<Text c="dimmed" size="xs">