// @note: not used anywhere
import type { Token } from "../../Providers/ConfigProvider";
import { useTokenBalances } from "./useTokenBalances";

export const useTokenWithAmount = ({
	token,
	userAddress,
}: { token: Token; userAddress?: string }) => {
	const tokensWithBalances = useTokenBalances(userAddress);
	const formattedTokensWithBalances: { [chainId: number]: Token[] } = {};

	// converting tokens with balances in the id: tokens format
	if (tokensWithBalances) {
		for (const token of tokensWithBalances) {
			if (!formattedTokensWithBalances[token.chainId]) {
				formattedTokensWithBalances[token.chainId] = [];
			}
			formattedTokensWithBalances[token.chainId].push(token);
		}
	}

	const tokensInAChain = formattedTokensWithBalances?.[token?.chainId];
	const tokenWithAmount = tokensInAChain?.filter(
		(item) => item.address.toLowerCase() === token?.address?.toLowerCase(),
	)?.[0];
	return tokenWithAmount;
};
