28 lines
832 B
TypeScript
28 lines
832 B
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
import { apiClient } from "../../../shared/api";
|
|
import type { paths } from "../../../shared/api/generated/schema";
|
|
|
|
export const brokerageAccountsQueryKey = ["brokerage-accounts"] as const;
|
|
|
|
export type BrokerageAccount =
|
|
paths["/api/v1/brokerage-accounts"]["get"]["responses"][200]["content"]["application/json"][number];
|
|
|
|
export function useBrokerageAccounts(accessToken: string | null) {
|
|
return useQuery({
|
|
queryKey: brokerageAccountsQueryKey,
|
|
enabled: Boolean(accessToken),
|
|
staleTime: 60_000,
|
|
retry: false,
|
|
queryFn: async () => {
|
|
const { data, error } = await apiClient.GET(
|
|
"/api/v1/brokerage-accounts",
|
|
{
|
|
headers: { Authorization: `Bearer ${accessToken}` },
|
|
},
|
|
);
|
|
if (error) throw error;
|
|
return data as BrokerageAccount[];
|
|
},
|
|
});
|
|
}
|