Frontend security / security (push) Successful in 9s
Frontend verify / verify (push) Failing after 37m50s
Frontend security / security (pull_request) Successful in 9s
Frontend verify / verify (pull_request) Failing after 42m10s
Conventional commits / commits (pull_request) Successful in 29s
Enable every plugin recommended preset and replace Biome with ESLint formatting. Preserve API contracts and JSX whitespace; verify source, tests, builds and tooling.
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import { useQueryClient } from "@tanstack/react-query";
|
|
import { useState } from "react";
|
|
|
|
import {
|
|
brokerageOperationsQueryOptions,
|
|
type OperationCategory,
|
|
useBrokerageOperations,
|
|
} from "@/entities/broker-operation";
|
|
import { apiErrorCode } from "@/shared/api";
|
|
|
|
function useInstrumentOperations(
|
|
uid: string,
|
|
filter: string,
|
|
categories: OperationCategory[],
|
|
) {
|
|
const scope = `${uid}:${filter}`;
|
|
const [pagination, setPagination] = useState<{
|
|
cursors: string[];
|
|
scope: string;
|
|
}>({ cursors: [], scope });
|
|
const cursors = pagination.scope === scope ? pagination.cursors : [];
|
|
const client = useQueryClient();
|
|
const firstPage = { categories, instrumentUid: uid, limit: 20 };
|
|
const operations = useBrokerageOperations(uid ? "all" : undefined, {
|
|
...firstPage,
|
|
cursor: cursors.at(-1),
|
|
});
|
|
const retry = (retryScreen: () => unknown) => {
|
|
if (apiErrorCode(operations.error) === "INVALID_OPERATIONS_CURSOR") {
|
|
setPagination({ cursors: [], scope });
|
|
void client.invalidateQueries({
|
|
exact: true,
|
|
queryKey: brokerageOperationsQueryOptions("all", firstPage).queryKey,
|
|
});
|
|
}
|
|
else void retryScreen();
|
|
};
|
|
return {
|
|
hasPrevious: cursors.length > 0,
|
|
onNext: () => {
|
|
if (operations.data?.nextCursor)
|
|
setPagination({
|
|
cursors: [...cursors, operations.data.nextCursor],
|
|
scope,
|
|
});
|
|
},
|
|
onPrevious: () => setPagination({ cursors: cursors.slice(0, -1), scope }),
|
|
operations,
|
|
retry,
|
|
};
|
|
}
|
|
|
|
export { useInstrumentOperations };
|