Consume the provided resource-envelope API snapshot. Preserve financial snapshots during refresh, observe synchronization without importing, and fence late responses across account and connection changes.
26 lines
780 B
TypeScript
26 lines
780 B
TypeScript
import { apiQueryClient, type paths, useResourceQuery } from "@/shared/api";
|
|
|
|
type EventsEndpoint =
|
|
paths["/api/v1/brokerage-accounts/{accountId}/events"]["get"];
|
|
type BrokerageEvent = NonNullable<
|
|
EventsEndpoint["responses"][200]["content"]["application/json"]["data"]
|
|
>["events"][number];
|
|
|
|
function useBrokerageEvents(
|
|
accountId: string | undefined,
|
|
query: Omit<NonNullable<EventsEndpoint["parameters"]["query"]>, "sync"> = {},
|
|
) {
|
|
return useResourceQuery({
|
|
meta: { accessGroup: "brokerage" },
|
|
...apiQueryClient.queryOptions(
|
|
"get",
|
|
"/api/v1/brokerage-accounts/{accountId}/events",
|
|
{ params: { path: { accountId: accountId ?? "" }, query } },
|
|
),
|
|
enabled: Boolean(accountId),
|
|
staleTime: 30_000,
|
|
});
|
|
}
|
|
|
|
export { type BrokerageEvent, useBrokerageEvents };
|