import { useSelector } from "react-redux";

import type { ReduxStateType } from "@store/types";
import { useAccounts } from "./useAccounts";
import { useWalletCapabilities } from "./useWalletCapabilities";

/**
 * To pre-fetch wallet capabilities for connected EVM accounts in the background.
 */
export const usePreFetchCapabilities = () => {
	const { accounts } = useAccounts();
	const fromChainId = useSelector(
		(state: ReduxStateType) => state.quoteParams.fromChainId,
	);

	const evmAccount = accounts.find((account) => account.chainType === "EVM");

	const chainIdToCheck = fromChainId ?? evmAccount?.chainId;

	// Pre-fetch capabilities - the hook handles caching automatically
	// We don't need the return values, just calling it triggers the fetch in the background
	useWalletCapabilities(chainIdToCheck);
};
