"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.listAndFilterCurrencies = exports.filterCurrencies = exports.isPlatformERC20TokenCurrency = exports.isPlatformTokenCurrency = exports.isPlatformCryptoCurrency = exports.isPlatformSupportedCurrency = void 0;
const minimatch_1 = require("minimatch");
const currencies_1 = require("../currencies");
const types_1 = require("./types");
const helpers_1 = require("../helpers");
function isPlatformSupportedCurrency(currency) {
    if ((0, currencies_1.isCryptoCurrency)(currency)) {
        return (0, helpers_1.includes)(types_1.PLATFORM_FAMILIES, currency.family);
    }
    if ((0, currencies_1.isTokenCurrency)(currency)) {
        return (0, helpers_1.includes)(types_1.PLATFORM_FAMILIES, currency.parentCurrency.family);
    }
    return false;
}
exports.isPlatformSupportedCurrency = isPlatformSupportedCurrency;
function isPlatformCryptoCurrency(currency) {
    return currency.type === types_1.PlatformCurrencyType.CryptoCurrency;
}
exports.isPlatformCryptoCurrency = isPlatformCryptoCurrency;
function isPlatformTokenCurrency(currency) {
    return currency.type === types_1.PlatformCurrencyType.TokenCurrency;
}
exports.isPlatformTokenCurrency = isPlatformTokenCurrency;
function isPlatformERC20TokenCurrency(currency) {
    return currency.standard === "ERC20";
}
exports.isPlatformERC20TokenCurrency = isPlatformERC20TokenCurrency;
function filterCurrencies(currencies, filters) {
    const filterCurrencyRegexes = filters.currencies
        ? filters.currencies.map(filter => (0, minimatch_1.makeRe)(filter))
        : null;
    return currencies.filter(currency => {
        if (!filters.includeTokens && (0, currencies_1.isTokenCurrency)(currency)) {
            return false;
        }
        if (filterCurrencyRegexes &&
            filterCurrencyRegexes.length &&
            !filterCurrencyRegexes.some(regex => currency.id.match(regex))) {
            return false;
        }
        return true;
    });
}
exports.filterCurrencies = filterCurrencies;
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 = (0, currencies_1.listCurrencies)(includeTokens);
    return filterCurrencies(allCurrencies, {
        includeTokens,
        currencies,
    });
}
exports.listAndFilterCurrencies = listAndFilterCurrencies;
//# sourceMappingURL=helpers.js.map