UNPKG

@ledgerhq/live-common

Version:
41 lines 1.8 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const live_network_1 = __importDefault(require("@ledgerhq/live-network")); const live_env_1 = require("@ledgerhq/live-env"); const mock_json_1 = __importDefault(require("./mock.json")); const api = { fetchRampCatalog: async () => { if ((0, live_env_1.getEnv)("MOCK")) { // TODO: replace this mock on playwright runs with controlled data return mock_json_1.default; } const headers = { Origin: "http://localhost:3000" }; const currencyParam = "currency=crypto"; const [buyResult, sellResult] = await Promise.allSettled([ (0, live_network_1.default)({ method: "GET", headers, url: `${(0, live_env_1.getEnv)("BUY_API_BASE")}/provider/currencies?${currencyParam}`, }), (0, live_network_1.default)({ method: "GET", headers, url: `${(0, live_env_1.getEnv)("SELL_API_BASE")}/provider/currencies?${currencyParam}`, }), ]); if (buyResult.status === "rejected" && sellResult.status === "rejected") { throw new Error("Failed to fetch ramp catalog from both buy and sell APIs"); } const buyData = buyResult.status === "fulfilled" ? buyResult.value.data : undefined; const sellData = sellResult.status === "fulfilled" ? sellResult.value.data : undefined; return { onRamp: buyData?.onRamp ?? {}, offRamp: sellData ?? {}, }; }, }; exports.default = api; //# sourceMappingURL=index.js.map