@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
37 lines • 1.86 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchCurrencyFrom = void 0;
const network_1 = __importDefault(require("@ledgerhq/live-network/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, 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 (e) {
throw Error("Something went wrong in fetchCurrencyFrom call");
}
}
exports.fetchCurrencyFrom = fetchCurrencyFrom;
//# sourceMappingURL=fetchCurrencyFrom.js.map