UNPKG

@ledgerhq/live-common

Version:
36 lines 1.82 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.fetchCurrencyFrom = fetchCurrencyFrom; const live_network_1 = __importDefault(require("@ledgerhq/live-network")); const timeout_1 = require("../../const/timeout"); const flattenV5CurrenciesToAndFrom_1 = require("../../utils/flattenV5CurrenciesToAndFrom"); const fetchCurrencyFrom_mocks_1 = require("./__mocks__/fetchCurrencyFrom.mocks"); const __1 = require("../.."); const live_env_1 = require("@ledgerhq/live-env"); async function fetchCurrencyFrom({ baseUrl = (0, __1.getSwapAPIBaseURL)(), currencyTo, providers, additionalCoinsFlag = false, }) { if ((0, live_env_1.getEnv)("MOCK") || (0, live_env_1.getEnv)("PLAYWRIGHT_RUN")) return (0, flattenV5CurrenciesToAndFrom_1.flattenV5CurrenciesToAndFrom)(fetchCurrencyFrom_mocks_1.fetchCurrencyFromMock); const headers = (0, __1.getSwapUserIP)(); const url = new URL(`${baseUrl}/currencies/from`); url.searchParams.append("providers-whitelist", providers.join(",")); url.searchParams.append("additional-coins-flag", additionalCoinsFlag.toString()); if (currencyTo) { url.searchParams.append("currency-to", currencyTo); } 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, flattenV5CurrenciesToAndFrom_1.flattenV5CurrenciesToAndFrom)(data); } catch { throw Error("Something went wrong in fetchCurrencyFrom call"); } } //# sourceMappingURL=fetchCurrencyFrom.js.map