"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.postSwapCancelled = exports.postSwapAccepted = void 0;
const live_network_1 = __importDefault(require("@ledgerhq/live-network"));
const mock_1 = require("./mock");
const isIntegrationTestEnv_1 = require("./utils/isIntegrationTestEnv");
const _1 = require(".");
const postSwapAccepted = async ({ provider, swapId = "", transactionId, swapAppVersion, ...rest }) => {
    if ((0, isIntegrationTestEnv_1.isIntegrationTestEnv)())
        return (0, mock_1.mockPostSwapAccepted)({ provider, swapId, transactionId, ...rest });
    /**
     * Since swapId is required by the endpoint, don't call it if we don't have
     * this info
     */
    if (!swapId) {
        return null;
    }
    try {
        const ipHeader = (0, _1.getSwapUserIP)();
        const headers = {
            ...(ipHeader || {}),
            ...(swapAppVersion ? { "x-swap-app-version": swapAppVersion } : {}),
        };
        await (0, live_network_1.default)({
            method: "POST",
            url: `${(0, _1.getSwapAPIBaseURL)()}/swap/accepted`,
            data: { provider, swapId, transactionId, ...rest },
            ...(Object.keys(headers).length > 0 ? { headers } : {}),
        });
    }
    catch (error) {
        console.error(error);
    }
    return null;
};
exports.postSwapAccepted = postSwapAccepted;
const postSwapCancelled = async ({ provider, swapId = "", swapAppVersion, ...rest }) => {
    if ((0, isIntegrationTestEnv_1.isIntegrationTestEnv)())
        return (0, mock_1.mockPostSwapCancelled)({ provider, swapId, ...rest });
    /**
     * Since swapId is required by the endpoint, don't call it if we don't have
     * this info
     */
    if (!swapId) {
        return null;
    }
    try {
        const ipHeader = (0, _1.getSwapUserIP)();
        const headers = {
            ...(ipHeader || {}),
            ...(swapAppVersion ? { "x-swap-app-version": swapAppVersion } : {}),
        };
        await (0, live_network_1.default)({
            method: "POST",
            url: `${(0, _1.getSwapAPIBaseURL)()}/swap/cancelled`,
            data: { provider, swapId, ...rest },
            ...(Object.keys(headers).length > 0 ? { headers } : {}),
        });
    }
    catch (error) {
        console.error(error);
    }
    return null;
};
exports.postSwapCancelled = postSwapCancelled;
//# sourceMappingURL=postSwapState.js.map