import type { CryptoCurrency } from "@ledgerhq/ledger-wallet-framework/types";
import { isGatewayEnabled } from "../../network/gateway";
import { submit } from "../../network/gateway";

export async function broadcast(currency: CryptoCurrency, signedTx: string): Promise<string> {
  const parsed: { serialized: string; signature: string } = JSON.parse(signedTx);
  const [sig, party] = parsed.signature.split("__PARTY__");
  if (isGatewayEnabled(currency))
    return (await submit(currency, party, parsed.serialized, sig)).update_id;
  else throw new Error("Not implemented");
}
