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
@@ -31,16 +31,26 @@ function configureTestAuth() {
});
}
function portfolioSummary(totals: { currency: string; value: string }[]) {
function portfolioSummary(totals: { currency: string; value: string }) {
return {
bondPositionCount: 1,
cashBalances: [],
cash: { currency: "RUB", value: "0" },
fundPositionCount: 0,
stockPositionCount: 0,
structure: { currencies: [], unvaluedCategories: [] },
structure: {
categories: [],
hasNegativeValues: false,
totalValue: "0",
unvaluedCategories: [],
},
totalPositionCount: 1,
totalsByCurrency: totals,
unrealizedReturnByCurrency: [],
totals,
unrealizedReturn: {
absolute: "0",
costBasis: "0",
partial: false,
percent: null,
},
};
}
@@ -59,23 +69,18 @@ function renderPage(queryClient: QueryClient) {
}
describe("AccountsPage", () => {
it("summarizes currencies separately and reports excluded accounts", async () => {
it("summarizes account totals and reports excluded accounts", async () => {
server.use(http.get("*/api/v1/brokerage-accounts", () =>
HttpResponse.json(resource([
{
...account,
portfolioSummary: portfolioSummary([
{ currency: "RUB", value: "100.10" },
{ currency: "USD", value: "20" },
]),
portfolioSummary: portfolioSummary({ currency: "RUB", value: "100.10" }),
},
{
...account,
id: "account-2",
name: "Второй",
portfolioSummary: portfolioSummary([
{ currency: "RUB", value: "50.20" },
]),
portfolioSummary: portfolioSummary({ currency: "RUB", value: "50.20" }),
},
{
...account,
@@ -88,9 +93,9 @@ describe("AccountsPage", () => {
id: "account-4",
name: "Только деньги",
portfolioSummary: {
...portfolioSummary([{ currency: "RUB", value: "25" }]),
...portfolioSummary({ currency: "RUB", value: "25" }),
bondPositionCount: 0,
cashBalances: [{ currency: "RUB", value: "25" }],
cash: { currency: "RUB", value: "25" },
totalPositionCount: 0,
},
},
@@ -99,7 +104,7 @@ describe("AccountsPage", () => {
id: "account-5",
name: "Без сумм",
portfolioSummary: {
...portfolioSummary([]),
...portfolioSummary({ currency: "RUB", value: "0" }),
totalPositionCount: 0,
},
},
@@ -110,7 +115,6 @@ describe("AccountsPage", () => {
renderPage(client);
expect(await screen.findByText("175,30 ₽")).toBeInTheDocument();
expect(screen.getAllByText("20,00 $")).not.toHaveLength(0);
expect(screen.queryByText("Ваши инвестиции по счетам"))
.not.toBeInTheDocument();
expect(screen.getByText("5 счетов")).toBeInTheDocument();
@@ -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">