"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useFetchCurrencyTo = void 0;
const helpers_1 = require("@ledgerhq/coin-framework/account/helpers");
const index_1 = require("../../index");
const v5_1 = require("../../api/v5");
const useAPI_1 = require("../../../../hooks/useAPI");
const featureFlags_1 = require("../../../../featureFlags");
const useFilteredProviders_1 = require("./useFilteredProviders");
const constants_1 = require("./constants");
function useFetchCurrencyTo({ fromCurrencyAccount }) {
    const fetchAdditionalCoins = (0, featureFlags_1.useFeature)("fetchAdditionalCoins");
    const { providers, loading, error } = (0, useFilteredProviders_1.useFilteredProviders)();
    const currencyFromId = fromCurrencyAccount
        ? (0, helpers_1.getAccountCurrency)(fromCurrencyAccount).id
        : undefined;
    return (0, useAPI_1.useAPI)({
        queryFn: v5_1.fetchCurrencyTo,
        queryProps: {
            baseUrl: (0, index_1.getSwapAPIBaseURL)(),
            currencyFromId,
            providers,
            additionalCoinsFlag: fetchAdditionalCoins?.enabled,
        },
        // BE caches this so less of a problem when FE fetches frequently
        staleTimeout: constants_1.FETCH_CURRENCIES_TIMEOUT_MS,
        enabled: !!currencyFromId && !loading && !error,
    });
}
exports.useFetchCurrencyTo = useFetchCurrencyTo;
//# sourceMappingURL=useFetchCurrencyTo.js.map