@ledgerhq/coin-algorand
Version:
Ledger Algorand Coin integration
38 lines • 1.63 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.prepareTransaction = void 0;
const isEqual_1 = __importDefault(require("lodash/isEqual"));
const bignumber_js_1 = require("bignumber.js");
const estimateMaxSpendable_1 = require("./estimateMaxSpendable");
const getFeesForTransaction_1 = require("./getFeesForTransaction");
/**
* Calculate fees for the current transaction
* @param {AlgorandAccount} account
* @param {Transaction} transaction
*/
const prepareTransaction = async (account, transaction) => {
let recipient;
let amount;
if (transaction.mode === "send") {
recipient = transaction.recipient;
amount = transaction.useAllAmount
? await (0, estimateMaxSpendable_1.estimateMaxSpendable)({ account, transaction })
: transaction.amount;
}
else if (transaction.mode === "optIn" || transaction.mode === "claimReward") {
recipient = account.freshAddress;
amount = new bignumber_js_1.BigNumber(0);
}
else {
throw new Error(`Unsupported transaction mode '${transaction.mode}'`);
}
const fees = await (0, getFeesForTransaction_1.getEstimatedFees)(account, transaction);
const newTx = { ...transaction, fees, amount, recipient };
return (0, isEqual_1.default)(transaction, newTx) ? transaction : newTx;
};
exports.prepareTransaction = prepareTransaction;
exports.default = exports.prepareTransaction;
//# sourceMappingURL=prepareTransaction.js.map