refactor: simplify resource queries and layout tests
Frontend security / security (push) Successful in 10s
Frontend verify / verify (push) Successful in 5m51s

This commit was merged in pull request #40.
This commit is contained in:
2026-09-27 18:53:12 +03:00
parent 5e076470aa
commit c1b08735e3
18 changed files with 508 additions and 122 deletions
+10 -42
View File
@@ -1,5 +1,3 @@
import { useQueryClient } from "@tanstack/react-query";
import { useState } from "react";
import { useParams, useSearchParams } from "react-router";
import {
type BondPeriod,
@@ -10,12 +8,11 @@ import {
useBondPosition,
useBondQuote,
} from "@/entities/bond";
import type { OperationCategory } from "@/entities/broker-operation";
import {
brokerageOperationsQueryOptions,
type OperationCategory,
useBrokerageOperations,
} from "@/entities/broker-operation";
import { section } from "@/features/instrument-details";
section,
useInstrumentOperations,
} from "@/features/instrument-details";
import { useScreenSync } from "@/features/tbank-connection";
import { apiErrorCode } from "@/shared/api";
import { formatDate, instrumentLogoUrl } from "@/shared/lib";
@@ -38,27 +35,13 @@ function useBondPageVm() {
periods.find((value) => value === params.get("period")) ?? "month";
const filter =
filters.find((value) => value === params.get("events")) ?? "all";
const scope = `${uid}:${filter}`;
const [pagination, setPagination] = useState<{
scope: string;
cursors: string[];
}>({ scope, cursors: [] });
const cursors = pagination.scope === scope ? pagination.cursors : [];
const client = useQueryClient();
const quote = useBondQuote(uid);
const metrics = useBondMetrics(uid);
const candles = useBondCandles(uid, period);
const position = useBondPosition(uid);
const coupons = useBondCoupons(uid);
const firstPage = {
instrumentUid: uid,
categories: categories[filter],
limit: 20,
};
const operations = useBrokerageOperations(uid ? "all" : undefined, {
...firstPage,
cursor: cursors.at(-1),
});
const history = useInstrumentOperations(uid, filter, categories[filter]);
const { operations } = history;
const sync = useScreenSync(
{
screen: "bond",
@@ -75,15 +58,6 @@ function useBondPageVm() {
next.set(key, value);
setParams(next, { replace: true });
};
const retryOperations = () => {
if (apiErrorCode(operations.error) === "INVALID_OPERATIONS_CURSOR") {
setPagination({ scope, cursors: [] });
void client.invalidateQueries({
queryKey: brokerageOperationsQueryOptions("all", firstPage).queryKey,
exact: true,
});
} else void sync.retry();
};
const chartData =
candles.data?.candles.map((candle) => ({
...candle,
@@ -138,7 +112,7 @@ function useBondPageVm() {
operations: operations.data,
operationsState: {
...section(operations, sync.retry),
retry: retryOperations,
retry: () => history.retry(sync.retry),
},
eventRows:
operations.data?.items.map((item) => ({
@@ -148,15 +122,9 @@ function useBondPageVm() {
})) ?? [],
filter,
setFilter: (value: string) => setParam("events", value),
hasPrevious: cursors.length > 0,
onPrevious: () => setPagination({ scope, cursors: cursors.slice(0, -1) }),
onNext: () => {
if (operations.data?.nextCursor)
setPagination({
scope,
cursors: [...cursors, operations.data.nextCursor],
});
},
hasPrevious: history.hasPrevious,
onPrevious: history.onPrevious,
onNext: history.onNext,
};
}
type BondPageVm = ReturnType<typeof useBondPageVm>;