import { makeLRUCache } from "@ledgerhq/live-network/cache";
import api from "@ledgerhq/live-countervalues/api/index";
// sort currencies by ids provided
export const sortCurrenciesByIds = (currencies, ids) => {
    const currenciesById = new Map();
    for (const c of currencies) {
        if (c.type !== "FiatCurrency") {
            currenciesById.set(c.id, c);
        }
    }
    const all = new Set();
    for (const id of ids) {
        const currency = currenciesById.get(id);
        if (currency) {
            all.add(currency);
        }
    }
    for (const cur of currencies) {
        all.add(cur);
    }
    return [...all];
};
/**
 * @deprecated live-countervalues-react context unify a single fetch of this API data, so you may want to just use `useCurrenciesByMarketcap` instead OR get the marketcapIds from that context and directly use sortByCurrenciesById function
 */
export const fetchMarketcapIds = makeLRUCache(() => api.fetchIdsSortedByMarketcap());
/**
 * @deprecated live-countervalues-react context unify a single fetch of this API data, so you may want to just use `useCurrenciesByMarketcap` instead OR get the marketcapIds from that context and directly use sortByCurrenciesById function
 */
export const currenciesByMarketcap = (currencies) => fetchMarketcapIds().then(ids => sortCurrenciesByIds(currencies, ids), () => currencies);
//# sourceMappingURL=sortByMarketcap.js.map