import network from "@ledgerhq/live-network";
import { mockPostSwapAccepted, mockPostSwapCancelled } from "./mock";
import { isIntegrationTestEnv } from "./utils/isIntegrationTestEnv";
import { getSwapAPIBaseURL, getSwapUserIP } from ".";
export const postSwapAccepted = async ({ provider, swapId = "", transactionId, swapAppVersion, ...rest }) => {
    if (isIntegrationTestEnv())
        return 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 = getSwapUserIP();
        const headers = {
            ...(ipHeader || {}),
            ...(swapAppVersion ? { "x-swap-app-version": swapAppVersion } : {}),
        };
        await network({
            method: "POST",
            url: `${getSwapAPIBaseURL()}/swap/accepted`,
            data: { provider, swapId, transactionId, ...rest },
            ...(Object.keys(headers).length > 0 ? { headers } : {}),
        });
    }
    catch (error) {
        console.error(error);
    }
    return null;
};
export const postSwapCancelled = async ({ provider, swapId = "", swapAppVersion, ...rest }) => {
    if (isIntegrationTestEnv())
        return 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 = getSwapUserIP();
        const headers = {
            ...(ipHeader || {}),
            ...(swapAppVersion ? { "x-swap-app-version": swapAppVersion } : {}),
        };
        await network({
            method: "POST",
            url: `${getSwapAPIBaseURL()}/swap/cancelled`,
            data: { provider, swapId, ...rest },
            ...(Object.keys(headers).length > 0 ? { headers } : {}),
        });
    }
    catch (error) {
        console.error(error);
    }
    return null;
};
//# sourceMappingURL=postSwapState.js.map