"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useFetchCurrencyFrom = void 0;
const index_1 = require("../../index");
const featureFlags_1 = require("../../../../featureFlags");
const useAPI_1 = require("../../../../hooks/useAPI");
const fetchCurrencyFrom_1 = require("../../api/v5/fetchCurrencyFrom");
const constants_1 = require("./constants");
const useFilteredProviders_1 = require("./useFilteredProviders");
function useFetchCurrencyFrom({ currencyTo, enabled } = {}) {
    const fetchAdditionalCoins = (0, featureFlags_1.useFeature)("fetchAdditionalCoins");
    const { providers, loading, error } = (0, useFilteredProviders_1.useFilteredProviders)();
    return (0, useAPI_1.useAPI)({
        queryFn: fetchCurrencyFrom_1.fetchCurrencyFrom,
        queryProps: {
            baseUrl: (0, index_1.getSwapAPIBaseURL)(),
            currencyTo,
            additionalCoinsFlag: fetchAdditionalCoins?.enabled,
            providers,
        },
        // BE caches this so less of a problem when FE fetches frequently
        staleTimeout: constants_1.FETCH_CURRENCIES_TIMEOUT_MS,
        enabled: enabled && !loading && !error,
    });
}
exports.useFetchCurrencyFrom = useFetchCurrencyFrom;
//# sourceMappingURL=useFetchCurrencyFrom.js.map