import { makeRe } from "minimatch";
import { isCryptoCurrency, isTokenCurrency, listCurrencies } from "../currencies";
import { PlatformCurrencyType, PLATFORM_FAMILIES, } from "./types";
import { includes } from "../helpers";
export function isPlatformSupportedCurrency(currency) {
    if (isCryptoCurrency(currency)) {
        return includes(PLATFORM_FAMILIES, currency.family);
    }
    if (isTokenCurrency(currency)) {
        return includes(PLATFORM_FAMILIES, currency.parentCurrency.family);
    }
    return false;
}
export function isPlatformCryptoCurrency(currency) {
    return currency.type === PlatformCurrencyType.CryptoCurrency;
}
export function isPlatformTokenCurrency(currency) {
    return currency.type === PlatformCurrencyType.TokenCurrency;
}
export function isPlatformERC20TokenCurrency(currency) {
    return currency.standard === "ERC20";
}
export function filterCurrencies(currencies, filters) {
    const filterCurrencyRegexes = filters.currencies
        ? filters.currencies.map(filter => makeRe(filter))
        : null;
    return currencies.filter(currency => {
        if (!filters.includeTokens && isTokenCurrency(currency)) {
            return false;
        }
        if (filterCurrencyRegexes &&
            filterCurrencyRegexes.length &&
            !filterCurrencyRegexes.some(regex => currency.id.match(regex))) {
            return false;
        }
        return true;
    });
}
export function listAndFilterCurrencies({ includeTokens = false, currencies, }) {
    // We removed the filtering with `isPlatformSupportedCurrency`
    // As we want to show all the currencies in the requestAccount drawer
    const allCurrencies = listCurrencies(includeTokens);
    return filterCurrencies(allCurrencies, {
        includeTokens,
        currencies,
    });
}
//# sourceMappingURL=helpers.js.map