"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.usePickDefaultCurrency = void 0;
const react_1 = require("react");
const currencies_1 = require("../../../currencies");
// Pick a default currency target if none are selected.
const usePickDefaultCurrency = (currencies, currency, setCurrency) => {
    (0, react_1.useEffect)(() => {
        // Keep the same currency target if it is still valid.
        const isCurrencyValid = currency && currencies.indexOf(currency) >= 0;
        if (!currency || !isCurrencyValid) {
            const defaultCurrency = currencies.find(currency => currency.id === "ethereum" || currency.id === "bitcoin");
            if (defaultCurrency) {
                setCurrency(defaultCurrency);
            }
            else if (currencies.length > 0) {
                (0, currencies_1.currenciesByMarketcap)(currencies).then(sortedCurrencies => {
                    setCurrency(sortedCurrencies[0]);
                });
            }
        }
    }, [currency, currencies, setCurrency]);
};
exports.usePickDefaultCurrency = usePickDefaultCurrency;
//# sourceMappingURL=usePickDefaultCurrency.js.map