"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useBroadcast = void 0;
const react_1 = require("react");
const logs_1 = require("@ledgerhq/logs");
const live_env_1 = require("@ledgerhq/live-env");
const index_1 = require("../account/index");
const index_2 = require("../bridge/index");
const promise_1 = require("../promise");
const useBroadcast = ({ account, parentAccount, broadcastConfig }) => {
    const broadcast = (0, react_1.useCallback)(async (signedOperation) => {
        if (!account)
            throw new Error("account not present");
        const mainAccount = (0, index_1.getMainAccount)(account, parentAccount);
        const bridge = (0, index_2.getAccountBridge)(account, parentAccount);
        if ((0, live_env_1.getEnv)("DISABLE_TRANSACTION_BROADCAST")) {
            return Promise.resolve(signedOperation.operation);
        }
        return (0, promise_1.execAndWaitAtLeast)(3000, async () => {
            const operation = await bridge.broadcast({
                account: mainAccount,
                signedOperation,
                broadcastConfig,
            });
            (0, logs_1.log)("transaction-summary", `✔️ broadcasted! optimistic operation: ${(0, index_1.formatOperation)(mainAccount)(operation)}`);
            return operation;
        });
    }, [account, parentAccount, broadcastConfig]);
    return broadcast;
};
exports.useBroadcast = useBroadcast;
//# sourceMappingURL=useBroadcast.js.map