feat: add operations page
This commit is contained in:
@@ -35,6 +35,7 @@ describe("AppRoutes", () => {
|
|||||||
["/register", "Регистрация"],
|
["/register", "Регистрация"],
|
||||||
["/accounts", "Вход"],
|
["/accounts", "Вход"],
|
||||||
["/accounts/demo", "Вход"],
|
["/accounts/demo", "Вход"],
|
||||||
|
["/accounts/demo/operations", "Вход"],
|
||||||
["/settings", "Вход"],
|
["/settings", "Вход"],
|
||||||
["/unknown", "Страница не найдена"],
|
["/unknown", "Страница не найдена"],
|
||||||
])("renders %s with its page title", async (path, title) => {
|
])("renders %s with its page title", async (path, title) => {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Navigate, Route, Routes, useLocation } from "react-router";
|
import { Navigate, Route, Routes, useLocation } from "react-router";
|
||||||
import { useAuth } from "@/features/auth";
|
import { useAuth } from "@/features/auth";
|
||||||
import { AccountPage } from "@/pages/account";
|
import { AccountPage } from "@/pages/account";
|
||||||
|
import { AccountOperationsPage } from "@/pages/account-operations";
|
||||||
import { AccountsPage } from "@/pages/accounts";
|
import { AccountsPage } from "@/pages/accounts";
|
||||||
import { LoginPage } from "@/pages/login";
|
import { LoginPage } from "@/pages/login";
|
||||||
import { NotFoundPage } from "@/pages/not-found";
|
import { NotFoundPage } from "@/pages/not-found";
|
||||||
@@ -58,6 +59,10 @@ export function AppRoutes() {
|
|||||||
>
|
>
|
||||||
<Route path="/accounts" element={<AccountsPage />} />
|
<Route path="/accounts" element={<AccountsPage />} />
|
||||||
<Route path="/accounts/:accountId" element={<AccountPage />} />
|
<Route path="/accounts/:accountId" element={<AccountPage />} />
|
||||||
|
<Route
|
||||||
|
path="/accounts/:accountId/operations"
|
||||||
|
element={<AccountOperationsPage />}
|
||||||
|
/>
|
||||||
<Route path="/settings" element={<SettingsPage />} />
|
<Route path="/settings" element={<SettingsPage />} />
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="*" element={<NotFoundPage />} />
|
<Route path="*" element={<NotFoundPage />} />
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { MantineProvider } from "@mantine/core";
|
||||||
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
|
import { renderHook, waitFor } from "@testing-library/react";
|
||||||
|
import type { ReactNode } from "react";
|
||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import {
|
||||||
|
brokerageOperationsQueryParams,
|
||||||
|
useBrokerageOperations,
|
||||||
|
} from "./useBrokerageOperations";
|
||||||
|
|
||||||
|
describe("useBrokerageOperations", () => {
|
||||||
|
it("normalizes query parameters and loads a page without retries", async () => {
|
||||||
|
expect(
|
||||||
|
brokerageOperationsQueryParams({
|
||||||
|
categories: ["tax", "income"],
|
||||||
|
cursor: "next",
|
||||||
|
}),
|
||||||
|
).toEqual({ categories: ["income", "tax"], cursor: "next" });
|
||||||
|
const client = new QueryClient();
|
||||||
|
const wrapper = ({ children }: { children: ReactNode }) => (
|
||||||
|
<MantineProvider>
|
||||||
|
<QueryClientProvider client={client}>{children}</QueryClientProvider>
|
||||||
|
</MantineProvider>
|
||||||
|
);
|
||||||
|
|
||||||
|
const { result } = renderHook(
|
||||||
|
() => useBrokerageOperations("account-1", "token", { limit: 5 }),
|
||||||
|
{ wrapper },
|
||||||
|
);
|
||||||
|
|
||||||
|
await waitFor(() => expect(result.current.isSuccess).toBe(true));
|
||||||
|
expect(result.current.data).toMatchObject({ items: [] });
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { apiQueryClient } from "@/shared/api";
|
||||||
|
import type { paths } from "@/shared/api/generated/schema";
|
||||||
|
|
||||||
|
type OperationsEndpoint =
|
||||||
|
paths["/api/v1/brokerage-accounts/{accountId}/operations"]["get"];
|
||||||
|
|
||||||
|
export type BrokerageOperation =
|
||||||
|
OperationsEndpoint["responses"][200]["content"]["application/json"]["items"][number];
|
||||||
|
type BrokerageOperationsQuery = NonNullable<
|
||||||
|
OperationsEndpoint["parameters"]["query"]
|
||||||
|
>;
|
||||||
|
export type OperationCategory = BrokerageOperation["category"];
|
||||||
|
|
||||||
|
export const operationCategories = [
|
||||||
|
"trade",
|
||||||
|
"income",
|
||||||
|
"tax",
|
||||||
|
"fee",
|
||||||
|
"transfer",
|
||||||
|
"other",
|
||||||
|
] as const satisfies readonly OperationCategory[];
|
||||||
|
|
||||||
|
export function brokerageOperationsQueryParams(
|
||||||
|
query: BrokerageOperationsQuery,
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
...(query.from ? { from: query.from } : {}),
|
||||||
|
...(query.to ? { to: query.to } : {}),
|
||||||
|
...(query.categories?.length
|
||||||
|
? { categories: [...query.categories].sort() }
|
||||||
|
: {}),
|
||||||
|
...(query.cursor ? { cursor: query.cursor } : {}),
|
||||||
|
...(query.limit ? { limit: query.limit } : {}),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useBrokerageOperations(
|
||||||
|
accountId: string | undefined,
|
||||||
|
accessToken: string | null,
|
||||||
|
query: BrokerageOperationsQuery = {},
|
||||||
|
) {
|
||||||
|
const params = brokerageOperationsQueryParams(query);
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["brokerage-operations", accountId ?? "", params] as const,
|
||||||
|
enabled: Boolean(accountId && accessToken),
|
||||||
|
staleTime: 30_000,
|
||||||
|
retry: false,
|
||||||
|
...apiQueryClient.queryOptions(
|
||||||
|
"get",
|
||||||
|
"/api/v1/brokerage-accounts/{accountId}/operations",
|
||||||
|
{ params: { path: { accountId: accountId ?? "" }, query: params } },
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
export type {
|
||||||
|
BrokerageOperation,
|
||||||
|
OperationCategory,
|
||||||
|
} from "./api/useBrokerageOperations";
|
||||||
|
export {
|
||||||
|
operationCategories,
|
||||||
|
useBrokerageOperations,
|
||||||
|
} from "./api/useBrokerageOperations";
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { AccountOperationsPage } from "./ui/AccountOperationsPage";
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
import { MantineProvider } from "@mantine/core";
|
||||||
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
|
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||||
|
import { HttpResponse, http } from "msw";
|
||||||
|
import { MemoryRouter, Route, Routes } from "react-router";
|
||||||
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
import type { BrokerageOperation } from "@/entities/broker-operation";
|
||||||
|
import { server } from "@/test/server";
|
||||||
|
import { AccountOperationsPage, OperationRow } from "./AccountOperationsPage";
|
||||||
|
|
||||||
|
vi.mock("@/features/auth", () => ({
|
||||||
|
useAuth: () => ({ accessToken: "token" }),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const operation: BrokerageOperation = {
|
||||||
|
id: "operation-1",
|
||||||
|
occurredAt: "2026-08-14T10:00:00Z",
|
||||||
|
type: "OPERATION_TYPE_BUY",
|
||||||
|
category: "trade",
|
||||||
|
description: "Покупка акций",
|
||||||
|
figi: null,
|
||||||
|
instrumentUid: null,
|
||||||
|
ticker: "SBER",
|
||||||
|
instrumentType: "share",
|
||||||
|
payment: null,
|
||||||
|
quantity: "2",
|
||||||
|
price: { currency: "RUB", value: "100" },
|
||||||
|
accruedInterest: null,
|
||||||
|
commission: { currency: "RUB", value: "1" },
|
||||||
|
};
|
||||||
|
|
||||||
|
describe("OperationRow", () => {
|
||||||
|
it("marks cashless operations without rendering operation details", () => {
|
||||||
|
render(
|
||||||
|
<MantineProvider>
|
||||||
|
<MemoryRouter>
|
||||||
|
<OperationRow operation={operation} />
|
||||||
|
</MemoryRouter>
|
||||||
|
</MantineProvider>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(screen.getByText("Без движения денег")).toBeInTheDocument();
|
||||||
|
expect(
|
||||||
|
screen.queryByRole("button", { name: "Показать детали" }),
|
||||||
|
).toBeNull();
|
||||||
|
expect(screen.queryByText("Цена: 100 ₽")).toBeNull();
|
||||||
|
expect(screen.queryByText("Количество: 2")).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("AccountOperationsPage", () => {
|
||||||
|
it("resets cursor pagination when filters change", async () => {
|
||||||
|
const searches: string[] = [];
|
||||||
|
server.use(
|
||||||
|
http.get(
|
||||||
|
"*/api/v1/brokerage-accounts/:accountId/operations",
|
||||||
|
({ request }) => {
|
||||||
|
const url = new URL(request.url);
|
||||||
|
searches.push(url.search);
|
||||||
|
return HttpResponse.json({
|
||||||
|
accountId: "account-1",
|
||||||
|
items: [operation],
|
||||||
|
nextCursor: url.searchParams.get("cursor") ? null : "next-1",
|
||||||
|
hasNext: !url.searchParams.get("cursor"),
|
||||||
|
observedAt: "2026-08-14T00:00:00Z",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
render(
|
||||||
|
<QueryClientProvider client={new QueryClient()}>
|
||||||
|
<MantineProvider>
|
||||||
|
<MemoryRouter initialEntries={["/accounts/account-1/operations"]}>
|
||||||
|
<Routes>
|
||||||
|
<Route
|
||||||
|
path="/accounts/:accountId/operations"
|
||||||
|
element={<AccountOperationsPage />}
|
||||||
|
/>
|
||||||
|
</Routes>
|
||||||
|
</MemoryRouter>
|
||||||
|
</MantineProvider>
|
||||||
|
</QueryClientProvider>,
|
||||||
|
);
|
||||||
|
|
||||||
|
fireEvent.click(await screen.findByRole("button", { name: "Далее" }));
|
||||||
|
await waitFor(() => expect(searches.at(-1)).toContain("cursor=next-1"));
|
||||||
|
fireEvent.click(screen.getByRole("checkbox", { name: "Налог" }));
|
||||||
|
await waitFor(() => expect(searches.at(-1)).toContain("categories=tax"));
|
||||||
|
expect(searches.at(-1)).not.toContain("cursor=");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders an error state", async () => {
|
||||||
|
server.use(
|
||||||
|
http.get("*/api/v1/brokerage-accounts/:accountId/operations", () =>
|
||||||
|
HttpResponse.json({ code: "TBANK_UNAVAILABLE" }, { status: 503 }),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
render(
|
||||||
|
<QueryClientProvider client={new QueryClient()}>
|
||||||
|
<MantineProvider>
|
||||||
|
<MemoryRouter initialEntries={["/accounts/account-1/operations"]}>
|
||||||
|
<Routes>
|
||||||
|
<Route
|
||||||
|
path="/accounts/:accountId/operations"
|
||||||
|
element={<AccountOperationsPage />}
|
||||||
|
/>
|
||||||
|
</Routes>
|
||||||
|
</MemoryRouter>
|
||||||
|
</MantineProvider>
|
||||||
|
</QueryClientProvider>,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
await screen.findByText("Не удалось загрузить журнал"),
|
||||||
|
).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,177 @@
|
|||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
Checkbox,
|
||||||
|
Group,
|
||||||
|
Stack,
|
||||||
|
Text,
|
||||||
|
TextInput,
|
||||||
|
Title,
|
||||||
|
} from "@mantine/core";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { Link, useParams } from "react-router";
|
||||||
|
import {
|
||||||
|
type BrokerageOperation,
|
||||||
|
type OperationCategory,
|
||||||
|
operationCategories,
|
||||||
|
useBrokerageOperations,
|
||||||
|
} from "@/entities/broker-operation";
|
||||||
|
import { formatMoney, formatSnapshotTime } from "@/entities/portfolio";
|
||||||
|
import { useAuth } from "@/features/auth";
|
||||||
|
import { StateView } from "@/shared/ui";
|
||||||
|
|
||||||
|
function dateStart(value: string) {
|
||||||
|
return value ? `${value}T00:00:00.000Z` : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function dateEnd(value: string) {
|
||||||
|
return value ? `${value}T23:59:59.999Z` : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function AccountOperationsPage() {
|
||||||
|
const { accountId } = useParams();
|
||||||
|
const { accessToken } = useAuth();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [from, setFrom] = useState("");
|
||||||
|
const [to, setTo] = useState("");
|
||||||
|
const [categories, setCategories] = useState<OperationCategory[]>([]);
|
||||||
|
const [cursors, setCursors] = useState<string[]>([]);
|
||||||
|
const cursor = cursors.at(-1);
|
||||||
|
const operations = useBrokerageOperations(accountId, accessToken, {
|
||||||
|
from: dateStart(from),
|
||||||
|
to: dateEnd(to),
|
||||||
|
...(categories.length ? { categories } : {}),
|
||||||
|
...(cursor ? { cursor } : {}),
|
||||||
|
limit: 100,
|
||||||
|
});
|
||||||
|
const reset = () => setCursors([]);
|
||||||
|
|
||||||
|
if (operations.isLoading)
|
||||||
|
return (
|
||||||
|
<StateView
|
||||||
|
loading
|
||||||
|
title={t("states.loadingTitle")}
|
||||||
|
text={t("states.loadingText")}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
if (operations.isError)
|
||||||
|
return (
|
||||||
|
<StateView
|
||||||
|
error
|
||||||
|
title={t("ledger.errorTitle")}
|
||||||
|
text={t("ledger.errorText")}
|
||||||
|
action={
|
||||||
|
<Button onClick={() => operations.refetch()}>
|
||||||
|
{t("ledger.retry")}
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
<Stack maw={960} gap="lg">
|
||||||
|
<Group justify="space-between">
|
||||||
|
<Title order={1}>{t("ledger.title")}</Title>
|
||||||
|
<Button component={Link} to={`/accounts/${accountId}`} variant="subtle">
|
||||||
|
{t("ledger.back")}
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
<Group align="end">
|
||||||
|
<TextInput
|
||||||
|
label={t("ledger.from")}
|
||||||
|
type="date"
|
||||||
|
value={from}
|
||||||
|
onChange={(event) => {
|
||||||
|
setFrom(event.currentTarget.value);
|
||||||
|
reset();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
label={t("ledger.to")}
|
||||||
|
type="date"
|
||||||
|
value={to}
|
||||||
|
onChange={(event) => {
|
||||||
|
setTo(event.currentTarget.value);
|
||||||
|
reset();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Group>
|
||||||
|
<Checkbox.Group
|
||||||
|
label={t("ledger.categories")}
|
||||||
|
value={categories}
|
||||||
|
onChange={(value) => {
|
||||||
|
setCategories(value as OperationCategory[]);
|
||||||
|
reset();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Group mt="xs">
|
||||||
|
{operationCategories.map((category) => (
|
||||||
|
<Checkbox
|
||||||
|
key={category}
|
||||||
|
value={category}
|
||||||
|
label={t(`ledger.category.${category}`)}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</Group>
|
||||||
|
</Checkbox.Group>
|
||||||
|
{operations.data.items.length ? (
|
||||||
|
operations.data.items.map((operation) => (
|
||||||
|
<OperationRow key={operation.id} operation={operation} />
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<StateView
|
||||||
|
title={t("ledger.emptyTitle")}
|
||||||
|
text={t("ledger.emptyText")}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{operations.data.hasNext || cursors.length ? (
|
||||||
|
<Group justify="space-between">
|
||||||
|
<Button
|
||||||
|
disabled={!cursors.length}
|
||||||
|
onClick={() => setCursors((value) => value.slice(0, -1))}
|
||||||
|
>
|
||||||
|
{t("ledger.previous")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
disabled={!operations.data.hasNext || !operations.data.nextCursor}
|
||||||
|
onClick={() =>
|
||||||
|
operations.data.nextCursor &&
|
||||||
|
setCursors((value) => [...value, operations.data.nextCursor])
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{t("ledger.next")}
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
) : null}
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function OperationRow({ operation }: { operation: BrokerageOperation }) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
return (
|
||||||
|
<Card withBorder>
|
||||||
|
<Group justify="space-between" align="flex-start">
|
||||||
|
<Stack gap={2}>
|
||||||
|
<Text fw={700}>{operation.description || operation.type}</Text>
|
||||||
|
<Text c="dimmed" size="sm">
|
||||||
|
{formatSnapshotTime(operation.occurredAt)} ·{" "}
|
||||||
|
{operation.ticker ??
|
||||||
|
operation.instrumentType ??
|
||||||
|
t("ledger.noInstrument")}
|
||||||
|
</Text>
|
||||||
|
</Stack>
|
||||||
|
<Stack gap={2} align="end">
|
||||||
|
<Text fw={700}>
|
||||||
|
{operation.payment
|
||||||
|
? formatMoney(operation.payment)
|
||||||
|
: t("ledger.noMoney")}
|
||||||
|
</Text>
|
||||||
|
<Text c="dimmed" size="sm">
|
||||||
|
{t(`ledger.category.${operation.category}`)}
|
||||||
|
</Text>
|
||||||
|
</Stack>
|
||||||
|
</Group>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
import { MantineProvider } from "@mantine/core";
|
import { MantineProvider } from "@mantine/core";
|
||||||
import { cleanup, render, screen } from "@testing-library/react";
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
|
import { cleanup, render, screen, waitFor } from "@testing-library/react";
|
||||||
|
import { HttpResponse, http } from "msw";
|
||||||
import { MemoryRouter } from "react-router";
|
import { MemoryRouter } from "react-router";
|
||||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||||
import type { Portfolio } from "@/entities/portfolio";
|
import type { Portfolio } from "@/entities/portfolio";
|
||||||
|
import { server } from "@/test/server";
|
||||||
import {
|
import {
|
||||||
AccountPageEmpty,
|
AccountPageEmpty,
|
||||||
AccountPageError,
|
AccountPageError,
|
||||||
@@ -12,9 +15,11 @@ import {
|
|||||||
|
|
||||||
function renderPage(ui: React.ReactNode) {
|
function renderPage(ui: React.ReactNode) {
|
||||||
return render(
|
return render(
|
||||||
<MantineProvider>
|
<QueryClientProvider client={new QueryClient()}>
|
||||||
<MemoryRouter>{ui}</MemoryRouter>
|
<MantineProvider>
|
||||||
</MantineProvider>,
|
<MemoryRouter>{ui}</MemoryRouter>
|
||||||
|
</MantineProvider>
|
||||||
|
</QueryClientProvider>,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,4 +119,26 @@ describe("AccountPage states", () => {
|
|||||||
screen.getByRole("heading", { level: 1, name: "Основной" }),
|
screen.getByRole("heading", { level: 1, name: "Основной" }),
|
||||||
).toBeInTheDocument();
|
).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("keeps the portfolio visible when recent events fail", async () => {
|
||||||
|
server.use(
|
||||||
|
http.get("*/api/v1/brokerage-accounts/:accountId/operations", () =>
|
||||||
|
HttpResponse.json({ code: "TBANK_UNAVAILABLE" }, { status: 503 }),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
renderPage(
|
||||||
|
<AccountPageLoaded
|
||||||
|
accountId="account-1"
|
||||||
|
accessToken="token"
|
||||||
|
portfolio={portfolio}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(
|
||||||
|
screen.getByText("Не удалось загрузить последние события."),
|
||||||
|
).toBeInTheDocument(),
|
||||||
|
);
|
||||||
|
expect(screen.getByText("Вторая")).toBeInTheDocument();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,10 +11,18 @@ export function AccountPage() {
|
|||||||
if (viewModel.state === "loading") return <AccountPageLoading />;
|
if (viewModel.state === "loading") return <AccountPageLoading />;
|
||||||
if (viewModel.state === "error") return <AccountPageError {...viewModel} />;
|
if (viewModel.state === "error") return <AccountPageError {...viewModel} />;
|
||||||
if (viewModel.state === "empty")
|
if (viewModel.state === "empty")
|
||||||
return <AccountPageEmpty account={viewModel.account} />;
|
return (
|
||||||
|
<AccountPageEmpty
|
||||||
|
account={viewModel.account}
|
||||||
|
accountId={viewModel.accountId}
|
||||||
|
accessToken={viewModel.accessToken}
|
||||||
|
/>
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<AccountPageLoaded
|
<AccountPageLoaded
|
||||||
account={viewModel.account}
|
account={viewModel.account}
|
||||||
|
accountId={viewModel.accountId}
|
||||||
|
accessToken={viewModel.accessToken}
|
||||||
portfolio={viewModel.portfolio}
|
portfolio={viewModel.portfolio}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Link } from "react-router";
|
import { Link } from "react-router";
|
||||||
|
import { useBrokerageOperations } from "@/entities/broker-operation";
|
||||||
import type { BrokerageAccount } from "@/entities/brokerage-account";
|
import type { BrokerageAccount } from "@/entities/brokerage-account";
|
||||||
import { accountTypeKey } from "@/entities/brokerage-account";
|
import { accountTypeKey } from "@/entities/brokerage-account";
|
||||||
import type { Portfolio } from "@/entities/portfolio";
|
import type { Portfolio } from "@/entities/portfolio";
|
||||||
@@ -80,7 +81,15 @@ export function AccountPageError({
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
export function AccountPageEmpty({ account }: { account?: BrokerageAccount }) {
|
export function AccountPageEmpty({
|
||||||
|
account,
|
||||||
|
accountId,
|
||||||
|
accessToken = null,
|
||||||
|
}: {
|
||||||
|
account?: BrokerageAccount;
|
||||||
|
accountId?: string;
|
||||||
|
accessToken?: string | null;
|
||||||
|
}) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
return (
|
return (
|
||||||
<Stack>
|
<Stack>
|
||||||
@@ -89,14 +98,19 @@ export function AccountPageEmpty({ account }: { account?: BrokerageAccount }) {
|
|||||||
title={t("portfolio.emptyTitle")}
|
title={t("portfolio.emptyTitle")}
|
||||||
text={t("portfolio.emptyText")}
|
text={t("portfolio.emptyText")}
|
||||||
/>
|
/>
|
||||||
|
<RecentOperations accountId={accountId} accessToken={accessToken} />
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
export function AccountPageLoaded({
|
export function AccountPageLoaded({
|
||||||
account,
|
account,
|
||||||
|
accountId,
|
||||||
|
accessToken,
|
||||||
portfolio,
|
portfolio,
|
||||||
}: {
|
}: {
|
||||||
account?: BrokerageAccount;
|
account?: BrokerageAccount;
|
||||||
|
accountId?: string;
|
||||||
|
accessToken?: string | null;
|
||||||
portfolio: Portfolio;
|
portfolio: Portfolio;
|
||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -148,9 +162,55 @@ export function AccountPageLoaded({
|
|||||||
</Paper>
|
</Paper>
|
||||||
))}
|
))}
|
||||||
</Section>
|
</Section>
|
||||||
|
<RecentOperations
|
||||||
|
accountId={accountId}
|
||||||
|
accessToken={accessToken ?? null}
|
||||||
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
function RecentOperations({
|
||||||
|
accountId,
|
||||||
|
accessToken,
|
||||||
|
}: {
|
||||||
|
accountId: string | undefined;
|
||||||
|
accessToken: string | null;
|
||||||
|
}) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const operations = useBrokerageOperations(accountId, accessToken, {
|
||||||
|
limit: 5,
|
||||||
|
});
|
||||||
|
return (
|
||||||
|
<Section title={t("ledger.recentTitle")}>
|
||||||
|
{operations.isLoading ? (
|
||||||
|
<Text c="dimmed">{t("ledger.recentLoading")}</Text>
|
||||||
|
) : null}
|
||||||
|
{operations.isError ? (
|
||||||
|
<Alert color="red">{t("ledger.recentError")}</Alert>
|
||||||
|
) : null}
|
||||||
|
{operations.data?.items.length === 0 ? (
|
||||||
|
<Text c="dimmed">{t("ledger.recentEmpty")}</Text>
|
||||||
|
) : null}
|
||||||
|
{operations.data?.items.map((operation) => (
|
||||||
|
<Paper className={classes.cash} key={operation.id} withBorder>
|
||||||
|
<Text>{operation.description || operation.type}</Text>
|
||||||
|
<Text fw={700}>
|
||||||
|
{operation.payment
|
||||||
|
? formatMoney(operation.payment)
|
||||||
|
: t("ledger.noMoney")}
|
||||||
|
</Text>
|
||||||
|
</Paper>
|
||||||
|
))}
|
||||||
|
<Button
|
||||||
|
component={Link}
|
||||||
|
to={`/accounts/${accountId}/operations`}
|
||||||
|
variant="subtle"
|
||||||
|
>
|
||||||
|
{t("ledger.open")}
|
||||||
|
</Button>
|
||||||
|
</Section>
|
||||||
|
);
|
||||||
|
}
|
||||||
function PositionSection({
|
function PositionSection({
|
||||||
title,
|
title,
|
||||||
positions,
|
positions,
|
||||||
|
|||||||
@@ -22,6 +22,12 @@ export function useAccountPageViewModel() {
|
|||||||
if (portfolio.isFetching || !portfolio.data)
|
if (portfolio.isFetching || !portfolio.data)
|
||||||
return { state: "loading" as const };
|
return { state: "loading" as const };
|
||||||
if (!portfolio.data.positions.length && !portfolio.data.cashBalances.length)
|
if (!portfolio.data.positions.length && !portfolio.data.cashBalances.length)
|
||||||
return { state: "empty" as const, account };
|
return { state: "empty" as const, account, accountId, accessToken };
|
||||||
return { state: "loaded" as const, account, portfolio: portfolio.data };
|
return {
|
||||||
|
state: "loaded" as const,
|
||||||
|
account,
|
||||||
|
accountId,
|
||||||
|
accessToken,
|
||||||
|
portfolio: portfolio.data,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+105
@@ -116,6 +116,22 @@ export interface paths {
|
|||||||
patch?: never;
|
patch?: never;
|
||||||
trace?: never;
|
trace?: never;
|
||||||
};
|
};
|
||||||
|
"/api/v1/brokerage-accounts/{accountId}/operations": {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
get: operations["BrokerageOperationsController_get"];
|
||||||
|
put?: never;
|
||||||
|
post?: never;
|
||||||
|
delete?: never;
|
||||||
|
options?: never;
|
||||||
|
head?: never;
|
||||||
|
patch?: never;
|
||||||
|
trace?: never;
|
||||||
|
};
|
||||||
"/api/v1/brokerage-accounts/{accountId}/portfolio": {
|
"/api/v1/brokerage-accounts/{accountId}/portfolio": {
|
||||||
parameters: {
|
parameters: {
|
||||||
query?: never;
|
query?: never;
|
||||||
@@ -185,6 +201,32 @@ export interface components {
|
|||||||
currency: string;
|
currency: string;
|
||||||
value: string;
|
value: string;
|
||||||
};
|
};
|
||||||
|
BrokerageOperationDto: {
|
||||||
|
id: string;
|
||||||
|
/** Format: date-time */
|
||||||
|
occurredAt: string;
|
||||||
|
type: string;
|
||||||
|
/** @enum {string} */
|
||||||
|
category: "trade" | "income" | "tax" | "fee" | "transfer" | "other";
|
||||||
|
description: string;
|
||||||
|
figi: string | null;
|
||||||
|
instrumentUid: string | null;
|
||||||
|
ticker: string | null;
|
||||||
|
instrumentType: string | null;
|
||||||
|
payment: components["schemas"]["MoneyDto"] | null;
|
||||||
|
quantity: string | null;
|
||||||
|
price: components["schemas"]["MoneyDto"] | null;
|
||||||
|
accruedInterest: components["schemas"]["MoneyDto"] | null;
|
||||||
|
commission: components["schemas"]["MoneyDto"] | null;
|
||||||
|
};
|
||||||
|
BrokerageOperationsPageDto: {
|
||||||
|
accountId: string;
|
||||||
|
items: components["schemas"]["BrokerageOperationDto"][];
|
||||||
|
nextCursor: string | null;
|
||||||
|
hasNext: boolean;
|
||||||
|
/** Format: date-time */
|
||||||
|
observedAt: string;
|
||||||
|
};
|
||||||
PortfolioPositionDto: {
|
PortfolioPositionDto: {
|
||||||
figi: string | null;
|
figi: string | null;
|
||||||
displayName: string;
|
displayName: string;
|
||||||
@@ -715,6 +757,69 @@ export interface operations {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
BrokerageOperationsController_get: {
|
||||||
|
parameters: {
|
||||||
|
query?: {
|
||||||
|
from?: string;
|
||||||
|
to?: string;
|
||||||
|
categories?: ("trade" | "income" | "tax" | "fee" | "transfer" | "other")[];
|
||||||
|
cursor?: string;
|
||||||
|
limit?: number;
|
||||||
|
};
|
||||||
|
header?: never;
|
||||||
|
path: {
|
||||||
|
accountId: string;
|
||||||
|
};
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody?: never;
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["BrokerageOperationsPageDto"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Invalid request */
|
||||||
|
400: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/problem+json": components["schemas"]["ProblemDetailsDto"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Authentication required */
|
||||||
|
401: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/problem+json": components["schemas"]["ProblemDetailsDto"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Resource not found */
|
||||||
|
404: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/problem+json": components["schemas"]["ProblemDetailsDto"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Internal server error */
|
||||||
|
500: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/problem+json": components["schemas"]["ProblemDetailsDto"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
PortfolioController_get: {
|
PortfolioController_get: {
|
||||||
parameters: {
|
parameters: {
|
||||||
query?: never;
|
query?: never;
|
||||||
|
|||||||
@@ -590,6 +590,137 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/api/v1/brokerage-accounts/{accountId}/operations": {
|
||||||
|
"get": {
|
||||||
|
"operationId": "BrokerageOperationsController_get",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "accountId",
|
||||||
|
"required": true,
|
||||||
|
"in": "path",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "from",
|
||||||
|
"required": false,
|
||||||
|
"in": "query",
|
||||||
|
"schema": {
|
||||||
|
"format": "date-time",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "to",
|
||||||
|
"required": false,
|
||||||
|
"in": "query",
|
||||||
|
"schema": {
|
||||||
|
"format": "date-time",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "categories",
|
||||||
|
"required": false,
|
||||||
|
"in": "query",
|
||||||
|
"schema": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"trade",
|
||||||
|
"income",
|
||||||
|
"tax",
|
||||||
|
"fee",
|
||||||
|
"transfer",
|
||||||
|
"other"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "cursor",
|
||||||
|
"required": false,
|
||||||
|
"in": "query",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "limit",
|
||||||
|
"required": false,
|
||||||
|
"in": "query",
|
||||||
|
"schema": {
|
||||||
|
"minimum": 1,
|
||||||
|
"maximum": 1000,
|
||||||
|
"default": 100,
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/BrokerageOperationsPageDto"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Invalid request",
|
||||||
|
"content": {
|
||||||
|
"application/problem+json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ProblemDetailsDto"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Authentication required",
|
||||||
|
"content": {
|
||||||
|
"application/problem+json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ProblemDetailsDto"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"404": {
|
||||||
|
"description": "Resource not found",
|
||||||
|
"content": {
|
||||||
|
"application/problem+json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ProblemDetailsDto"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal server error",
|
||||||
|
"content": {
|
||||||
|
"application/problem+json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ProblemDetailsDto"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"bearer": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"brokerage-accounts"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
"/api/v1/brokerage-accounts/{accountId}/portfolio": {
|
"/api/v1/brokerage-accounts/{accountId}/portfolio": {
|
||||||
"get": {
|
"get": {
|
||||||
"operationId": "PortfolioController_get",
|
"operationId": "PortfolioController_get",
|
||||||
@@ -829,6 +960,139 @@
|
|||||||
"value"
|
"value"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"BrokerageOperationDto": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"occurredAt": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"category": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"trade",
|
||||||
|
"income",
|
||||||
|
"tax",
|
||||||
|
"fee",
|
||||||
|
"transfer",
|
||||||
|
"other"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"figi": {
|
||||||
|
"type": "string",
|
||||||
|
"nullable": true
|
||||||
|
},
|
||||||
|
"instrumentUid": {
|
||||||
|
"type": "string",
|
||||||
|
"nullable": true
|
||||||
|
},
|
||||||
|
"ticker": {
|
||||||
|
"type": "string",
|
||||||
|
"nullable": true
|
||||||
|
},
|
||||||
|
"instrumentType": {
|
||||||
|
"type": "string",
|
||||||
|
"nullable": true
|
||||||
|
},
|
||||||
|
"payment": {
|
||||||
|
"nullable": true,
|
||||||
|
"type": "object",
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/components/schemas/MoneyDto"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"quantity": {
|
||||||
|
"type": "string",
|
||||||
|
"nullable": true
|
||||||
|
},
|
||||||
|
"price": {
|
||||||
|
"nullable": true,
|
||||||
|
"type": "object",
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/components/schemas/MoneyDto"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"accruedInterest": {
|
||||||
|
"nullable": true,
|
||||||
|
"type": "object",
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/components/schemas/MoneyDto"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"commission": {
|
||||||
|
"nullable": true,
|
||||||
|
"type": "object",
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/components/schemas/MoneyDto"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"id",
|
||||||
|
"occurredAt",
|
||||||
|
"type",
|
||||||
|
"category",
|
||||||
|
"description",
|
||||||
|
"figi",
|
||||||
|
"instrumentUid",
|
||||||
|
"ticker",
|
||||||
|
"instrumentType",
|
||||||
|
"payment",
|
||||||
|
"quantity",
|
||||||
|
"price",
|
||||||
|
"accruedInterest",
|
||||||
|
"commission"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"BrokerageOperationsPageDto": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"accountId": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"items": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/components/schemas/BrokerageOperationDto"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nextCursor": {
|
||||||
|
"type": "string",
|
||||||
|
"nullable": true
|
||||||
|
},
|
||||||
|
"hasNext": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"observedAt": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"accountId",
|
||||||
|
"items",
|
||||||
|
"nextCursor",
|
||||||
|
"hasNext",
|
||||||
|
"observedAt"
|
||||||
|
]
|
||||||
|
},
|
||||||
"PortfolioPositionDto": {
|
"PortfolioPositionDto": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|||||||
@@ -62,6 +62,35 @@ export const ru = {
|
|||||||
quantity: "Количество: {{value}}",
|
quantity: "Количество: {{value}}",
|
||||||
return: "Доход: {{value}}",
|
return: "Доход: {{value}}",
|
||||||
},
|
},
|
||||||
|
ledger: {
|
||||||
|
title: "Журнал операций",
|
||||||
|
back: "К счету",
|
||||||
|
open: "Открыть журнал",
|
||||||
|
recentTitle: "Последние события",
|
||||||
|
recentLoading: "Загрузка последних событий",
|
||||||
|
recentError: "Не удалось загрузить последние события.",
|
||||||
|
recentEmpty: "Последних событий пока нет.",
|
||||||
|
from: "С",
|
||||||
|
to: "По",
|
||||||
|
categories: "Категории",
|
||||||
|
previous: "Назад",
|
||||||
|
next: "Далее",
|
||||||
|
retry: "Повторить",
|
||||||
|
errorTitle: "Не удалось загрузить журнал",
|
||||||
|
errorText: "Попробуйте запросить операции еще раз.",
|
||||||
|
emptyTitle: "Операций нет",
|
||||||
|
emptyText: "Измените период или фильтры.",
|
||||||
|
noMoney: "Без движения денег",
|
||||||
|
noInstrument: "Без инструмента",
|
||||||
|
category: {
|
||||||
|
trade: "Сделка",
|
||||||
|
income: "Доход",
|
||||||
|
tax: "Налог",
|
||||||
|
fee: "Комиссия",
|
||||||
|
transfer: "Перевод",
|
||||||
|
other: "Прочее",
|
||||||
|
},
|
||||||
|
},
|
||||||
settings: { title: "Настройки" },
|
settings: { title: "Настройки" },
|
||||||
tbank: {
|
tbank: {
|
||||||
title: "T-Bank Invest",
|
title: "T-Bank Invest",
|
||||||
|
|||||||
@@ -36,4 +36,13 @@ export const handlers = [
|
|||||||
cashBalances: [],
|
cashBalances: [],
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
http.get("*/api/v1/brokerage-accounts/:accountId/operations", () =>
|
||||||
|
HttpResponse.json({
|
||||||
|
accountId: "account-1",
|
||||||
|
items: [],
|
||||||
|
nextCursor: null,
|
||||||
|
hasNext: false,
|
||||||
|
observedAt: "2026-08-14T00:00:00Z",
|
||||||
|
}),
|
||||||
|
),
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user