31 lines
768 B
TypeScript
31 lines
768 B
TypeScript
import {
|
|
apiQueryClient,
|
|
type paths,
|
|
useAuthenticatedQuery,
|
|
} from "@/shared/api";
|
|
|
|
const portfolioQueryPolicy = {
|
|
staleTime: 30_000,
|
|
} as const;
|
|
|
|
type Portfolio =
|
|
paths["/api/v1/brokerage-accounts/{accountId}/portfolio"]["get"]["responses"][200]["content"]["application/json"];
|
|
|
|
function portfolioQueryOptions(accountId: string | undefined) {
|
|
return apiQueryClient.queryOptions(
|
|
"get",
|
|
"/api/v1/brokerage-accounts/{accountId}/portfolio",
|
|
{ params: { path: { accountId: accountId ?? "" } } },
|
|
);
|
|
}
|
|
|
|
function usePortfolio(accountId: string | undefined) {
|
|
return useAuthenticatedQuery({
|
|
...portfolioQueryOptions(accountId),
|
|
enabled: Boolean(accountId),
|
|
...portfolioQueryPolicy,
|
|
});
|
|
}
|
|
|
|
export { type Portfolio, portfolioQueryOptions, usePortfolio };
|