refactor: refactor foundation
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { apiClient } from "../../../shared/api";
|
||||
import type { paths } from "../../../shared/api/generated/schema";
|
||||
import { apiQueryClient } from "@/shared/api";
|
||||
import type { paths } from "@/shared/api/generated/schema";
|
||||
|
||||
export const portfolioQueryKey = (accountId: string) =>
|
||||
const portfolioQueryKey = (accountId: string) =>
|
||||
["portfolio", accountId] as const;
|
||||
|
||||
export const portfolioQueryPolicy = {
|
||||
const portfolioQueryPolicy = {
|
||||
staleTime: 30_000,
|
||||
retry: false,
|
||||
} as const;
|
||||
@@ -21,16 +21,10 @@ export function usePortfolio(
|
||||
queryKey: portfolioQueryKey(accountId ?? ""),
|
||||
enabled: Boolean(accountId && accessToken),
|
||||
...portfolioQueryPolicy,
|
||||
queryFn: async () => {
|
||||
const { data, error } = await apiClient.GET(
|
||||
"/api/v1/brokerage-accounts/{accountId}/portfolio",
|
||||
{
|
||||
params: { path: { accountId: accountId ?? "" } },
|
||||
headers: { Authorization: `Bearer ${accessToken}` },
|
||||
},
|
||||
);
|
||||
if (error) throw error;
|
||||
return data as Portfolio;
|
||||
},
|
||||
...apiQueryClient.queryOptions(
|
||||
"get",
|
||||
"/api/v1/brokerage-accounts/{accountId}/portfolio",
|
||||
{ params: { path: { accountId: accountId ?? "" } } },
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user