import { useMemo } from "react";

import type { Token } from "@/types/index";
import {
	NATIVE_SOLANA_TOKEN_ADDRESS,
	NATIVE_TOKEN_ADDRESS,
} from "@utils/constants";

export const useTrendingTokens = ({
	tokens,
}: {
	tokens: Token[] | undefined;
}) => {
	const trendingTokens = useMemo(() => {
		if (tokens?.length) {
			return tokens?.filter((token) => {
				const tokenSymbolLower = token.symbol.toLowerCase();
				const tokenAddressLower = token.address.toLowerCase();

				return (
					token.address === NATIVE_TOKEN_ADDRESS ||
					mostUsedTokensSymbol.includes(tokenSymbolLower) ||
					mostUsedTokensAddresses.includes(tokenAddressLower)
				);
			});
		}
	}, [tokens]);

	return trendingTokens;
};

// Most used tokens to filter out
const mostUsedTokensSymbol = [
	"usdt",
	"usdc",
	// "dai",
	// "weth",
	// "wbtc",
	// "eth",
	// "usdc.e",
	// "usdt.e",
	// "dai.e",
	// "weth.e",
	// "wbtc.e",
	// "fusdt",
	// "reth",
];

// used for specific tokens - like op and arb
const mostUsedTokensAddresses = [
	"0x4200000000000000000000000000000000000042".toLowerCase(),
	"0x912ce59144191c1204e64559fe8253a0e49e6548".toLowerCase(),
	NATIVE_TOKEN_ADDRESS,
	NATIVE_SOLANA_TOKEN_ADDRESS,
];
