@ledgerhq/coin-stellar
Version:
Ledger Stellar Coin integration
32 lines • 1.09 kB
JavaScript
import { AmountRequired, FeeNotLoaded } from "@ledgerhq/errors";
import invariant from "invariant";
import { craftTransaction } from "../logic";
import { getAmountValue } from "./logic";
/**
* @param {Account} account
* @param {Transaction} transaction
*/
export async function buildTransaction(account, transaction) {
const { recipient, networkInfo, fees, memoType, memoValue, mode, assetCode, assetIssuer } = transaction;
invariant(networkInfo && networkInfo.family === "stellar", "stellar family");
if (!fees) {
throw new FeeNotLoaded();
}
const amount = getAmountValue(account, transaction, fees);
if (!amount) {
throw new AmountRequired();
}
const { transaction: built } = await craftTransaction({ address: account.freshAddress }, {
type: mode,
recipient,
amount: BigInt(amount.toString()),
fee: BigInt(fees.toString()),
assetCode,
assetIssuer,
memoType,
memoValue,
});
return built;
}
export default buildTransaction;
//# sourceMappingURL=buildTransaction.js.map