"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.genericPrepareTransaction = void 0;
const alpaca_1 = require("./alpaca");
const utils_1 = require("./utils");
const bignumber_js_1 = __importDefault(require("bignumber.js"));
function bnEq(a, b) {
    return !a && !b ? true : !a || !b ? false : a.eq(b);
}
function genericPrepareTransaction(network, kind) {
    return async (account, transaction) => {
        const fees = await (0, alpaca_1.getAlpacaApi)(network, kind).estimateFees((0, utils_1.transactionToIntent)(account, transaction));
        const bnFee = (0, bignumber_js_1.default)(fees.value.toString());
        if (!bnEq(transaction.fees, bnFee)) {
            return { ...transaction, fees: bnFee };
        }
        return transaction;
    };
}
exports.genericPrepareTransaction = genericPrepareTransaction;
//# sourceMappingURL=prepareTransaction.js.map