fix: stabilize frontend query cache contracts
This commit is contained in:
@@ -42,14 +42,13 @@ export function useBrokerageOperations(
|
||||
) {
|
||||
const params = brokerageOperationsQueryParams(query);
|
||||
return useQuery({
|
||||
queryKey: ["brokerage-operations", accountId ?? "", params] as const,
|
||||
enabled: Boolean(accountId && accessToken),
|
||||
staleTime: 30_000,
|
||||
retry: false,
|
||||
...apiQueryClient.queryOptions(
|
||||
"get",
|
||||
"/api/v1/brokerage-accounts/{accountId}/operations",
|
||||
{ params: { path: { accountId: accountId ?? "" }, query: params } },
|
||||
),
|
||||
enabled: Boolean(accountId && accessToken),
|
||||
staleTime: 30_000,
|
||||
retry: false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,17 +2,20 @@ import { useQuery } from "@tanstack/react-query";
|
||||
import { apiQueryClient } from "@/shared/api";
|
||||
import type { paths } from "@/shared/api/generated/schema";
|
||||
|
||||
export const brokerageAccountsQueryKey = ["brokerage-accounts"] as const;
|
||||
const brokerageAccountsQueryOptions = () =>
|
||||
apiQueryClient.queryOptions("get", "/api/v1/brokerage-accounts");
|
||||
|
||||
export const brokerageAccountsQueryKey =
|
||||
brokerageAccountsQueryOptions().queryKey;
|
||||
|
||||
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,
|
||||
...brokerageAccountsQueryOptions(),
|
||||
enabled: Boolean(accessToken),
|
||||
staleTime: 60_000,
|
||||
retry: false,
|
||||
...apiQueryClient.queryOptions("get", "/api/v1/brokerage-accounts"),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -12,14 +12,13 @@ export function useBrokerageEvents(
|
||||
accessToken: string | null,
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: ["brokerage-events", accountId ?? ""] as const,
|
||||
enabled: Boolean(accountId && accessToken),
|
||||
staleTime: 30_000,
|
||||
retry: false,
|
||||
...apiQueryClient.queryOptions(
|
||||
"get",
|
||||
"/api/v1/brokerage-accounts/{accountId}/events",
|
||||
{ params: { path: { accountId: accountId ?? "" } } },
|
||||
),
|
||||
enabled: Boolean(accountId && accessToken),
|
||||
staleTime: 30_000,
|
||||
retry: false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,9 +2,6 @@ import { useQuery } from "@tanstack/react-query";
|
||||
import { apiQueryClient } from "@/shared/api";
|
||||
import type { paths } from "@/shared/api/generated/schema";
|
||||
|
||||
const portfolioQueryKey = (accountId: string) =>
|
||||
["portfolio", accountId] as const;
|
||||
|
||||
const portfolioQueryPolicy = {
|
||||
staleTime: 30_000,
|
||||
retry: false,
|
||||
@@ -18,13 +15,12 @@ export function usePortfolio(
|
||||
accessToken: string | null,
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: portfolioQueryKey(accountId ?? ""),
|
||||
enabled: Boolean(accountId && accessToken),
|
||||
...portfolioQueryPolicy,
|
||||
...apiQueryClient.queryOptions(
|
||||
"get",
|
||||
"/api/v1/brokerage-accounts/{accountId}/portfolio",
|
||||
{ params: { path: { accountId: accountId ?? "" } } },
|
||||
),
|
||||
enabled: Boolean(accountId && accessToken),
|
||||
...portfolioQueryPolicy,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user