import { useSelector } from "react-redux";
import type { Chain } from "../store/globalSlice";
import type { ReduxStateType } from "../store/types";

type MappedChain<T> = {
	[key: number]: T;
};

export const useMappedChainData = () => {
	const supportedChains = useSelector(
		(state: ReduxStateType) => state.global.supportedChains,
	);
	const mappedData: MappedChain<Chain> = {};

	if (supportedChains?.length) {
		for (const chain of supportedChains) {
			mappedData[chain.chainId] = chain;
		}

		return mappedData;
	}
};
