"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSwapStepFromError = exports.convertTransportError = exports.CompleteExchangeError = void 0;
const errors_1 = require("@ledgerhq/errors");
const hw_app_exchange_1 = require("@ledgerhq/hw-app-exchange");
class CompleteExchangeError extends Error {
    step;
    title;
    constructor(step, title, message) {
        super(message);
        this.name = "CompleteExchangeError";
        this.title = title;
        this.step = step;
    }
}
exports.CompleteExchangeError = CompleteExchangeError;
function convertTransportError(step, err) {
    if (err instanceof errors_1.TransportStatusError) {
        const { errorName, errorMessage } = (0, hw_app_exchange_1.getExchangeErrorMessage)(err.statusCode, step);
        return new CompleteExchangeError(step, errorName, errorMessage);
    }
    return err;
}
exports.convertTransportError = convertTransportError;
function getSwapStepFromError(error) {
    if (error.step) {
        return error.step;
    }
    else if (error.name === "DisabledTransactionBroadcastError") {
        return "SIGN_COIN_TRANSACTION";
    }
    return "UNKNOWN_STEP";
}
exports.getSwapStepFromError = getSwapStepFromError;
//# sourceMappingURL=error.js.map