import { type UseQueryOptions, useQuery } from "@tanstack/react-query";
import { validateTransaction } from "../utils/validateSolanaTransaction";
import { useConfig } from "./useConfig";

export const useValidateSolanaTransaction = ({
	signature,
	query,
}: {
	signature: string;
	query?: Omit<
		UseQueryOptions<Awaited<ReturnType<typeof validateTransaction>>>,
		"queryKey" | "queryFn"
	>;
}) => {
	const { rpcs } = useConfig();

	return useQuery({
		queryKey: ["validateSolanaTransaction", rpcs?.solana, signature],
		queryFn: () => validateTransaction(signature, rpcs?.solana),
		...query,
		enabled: Boolean(rpcs?.solana && query?.enabled),
	});
};
