"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchCurrencyAll = void 0;
const live_network_1 = __importDefault(require("@ledgerhq/live-network"));
const timeout_1 = require("../../const/timeout");
const axios_1 = __importDefault(require("axios"));
const errors_1 = require("@ledgerhq/errors");
const fetchCurrencyAll_mocks_1 = require("./__mocks__/fetchCurrencyAll.mocks");
const flattenV5CurrenciesAll_1 = require("../../utils/flattenV5CurrenciesAll");
const __1 = require("../..");
const live_env_1 = require("@ledgerhq/live-env");
async function fetchCurrencyAll({ baseUrl = (0, __1.getSwapAPIBaseURL)(), providers, additionalCoinsFlag = false, }) {
    if ((0, live_env_1.getEnv)("MOCK") || (0, live_env_1.getEnv)("PLAYWRIGHT_RUN"))
        return Promise.resolve((0, flattenV5CurrenciesAll_1.flattenV5CurrenciesAll)(fetchCurrencyAll_mocks_1.fetchCurrencyAllMock));
    const url = new URL(`${baseUrl}/currencies/all`);
    url.searchParams.append("providers-whitelist", providers.join(","));
    url.searchParams.append("additional-coins-flag", additionalCoinsFlag.toString());
    const headers = (0, __1.getSwapUserIP)();
    try {
        const { data } = await (0, live_network_1.default)({
            method: "GET",
            url: url.toString(),
            timeout: timeout_1.DEFAULT_SWAP_TIMEOUT_MS,
            ...(headers !== undefined ? { headers } : {}),
        });
        return (0, flattenV5CurrenciesAll_1.flattenV5CurrenciesAll)(data);
    }
    catch (e) {
        if (axios_1.default.isAxiosError(e)) {
            if (e.code === "ECONNABORTED") {
                // TODO: LIVE-8901 (handle request timeout)
            }
        }
        if (e instanceof errors_1.LedgerAPI4xx) {
            // TODO: LIVE-8901 (handle 4xx)
        }
        throw e;
    }
}
exports.fetchCurrencyAll = fetchCurrencyAll;
//# sourceMappingURL=fetchCurrencyAll.js.map