Use Query cancellation and native mutation results instead of HTTP registries, access epochs and copied scope state. Keep local auth ordering and mutation identity fences. Allow staged generated files to remain excluded from ESLint. Backend contract: WealthLedger/backend@d698ed9 BREAKING CHANGE: drop investment stateVersion/progress/resources from the client contract and use data/metadata readiness instead of rewritten query status. Cross-tab auth may require re-login.
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
import type { QueryClient } from "@tanstack/react-query";
|
|
|
|
import {
|
|
apiQueryClient,
|
|
type paths,
|
|
} from "@/shared/api";
|
|
|
|
type TbankConnectionStatus
|
|
= paths["/api/v1/tbank-connection"]["get"]["responses"][200]["content"]["application/json"];
|
|
|
|
function isInvestmentPath(path: string) {
|
|
return [
|
|
"/api/v1/brokerage-accounts",
|
|
"/api/v1/stocks",
|
|
"/api/v1/bonds",
|
|
"/api/v1/tbank-sync",
|
|
].some(root => path === root || path.startsWith(`${root}/`));
|
|
}
|
|
|
|
const tbankConnectionQueryOptions = () =>
|
|
apiQueryClient.queryOptions("get", "/api/v1/tbank-connection");
|
|
|
|
const tbankConnectionQueryKey = tbankConnectionQueryOptions().queryKey;
|
|
|
|
function commitTbankConnectionBoundary(
|
|
queryClient: QueryClient,
|
|
status: TbankConnectionStatus,
|
|
) {
|
|
queryClient.setQueryData(tbankConnectionQueryKey, status);
|
|
void queryClient.resetQueries({
|
|
predicate: ({ queryKey }) => {
|
|
const [method, path] = queryKey;
|
|
|
|
return (
|
|
method === "get"
|
|
&& typeof path === "string"
|
|
&& isInvestmentPath(path)
|
|
);
|
|
},
|
|
});
|
|
}
|
|
|
|
export {
|
|
commitTbankConnectionBoundary,
|
|
tbankConnectionQueryOptions,
|
|
type TbankConnectionStatus,
|
|
};
|