@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
51 lines • 2.68 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.genericGetTransactionStatus = void 0;
const errors_1 = require("@ledgerhq/errors");
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const alpaca_1 = require("./alpaca");
const utils_1 = require("./utils");
// => alpaca validateIntent
function genericGetTransactionStatus(network, kind) {
return async (account, transaction) => {
const alpacaApi = (0, alpaca_1.getAlpacaApi)(account.currency.id, kind);
const draftTransaction = {
mode: transaction?.mode ?? "send",
recipient: transaction.recipient,
amount: transaction.amount ?? new bignumber_js_1.default(0),
useAllAmount: !!transaction.useAllAmount,
assetReference: transaction.assetReference || "",
assetOwner: transaction.assetOwner || "",
subAccountId: transaction.subAccountId || "",
memoType: transaction.memoType || "",
memoValue: transaction.memoValue || "",
family: transaction.family,
feesStrategy: transaction.feesStrategy,
data: transaction.data,
};
if (alpacaApi.getChainSpecificRules) {
const chainSpecificValidation = alpacaApi.getChainSpecificRules();
if (chainSpecificValidation.getTransactionStatus.throwIfPendingOperation) {
if (account.pendingOperations.length > 0) {
throw new errors_1.AccountAwaitingSendPendingOperations();
}
}
}
const { errors, warnings, estimatedFees, amount, totalSpent, totalFees } = await alpacaApi.validateIntent((0, utils_1.transactionToIntent)(account, draftTransaction, alpacaApi.computeIntentType), { value: transaction.fees ? BigInt(transaction.fees.toString()) : 0n });
return {
errors,
warnings,
totalFees: typeof totalFees === "bigint" ? new bignumber_js_1.default(totalFees.toString()) : undefined,
estimatedFees: !transaction.fees || transaction.fees.isZero()
? new bignumber_js_1.default(estimatedFees.toString())
: transaction.fees,
amount: transaction.amount.eq(0) ? new bignumber_js_1.default(amount.toString()) : transaction.amount,
totalSpent: new bignumber_js_1.default(totalSpent.toString()),
};
};
}
exports.genericGetTransactionStatus = genericGetTransactionStatus;
//# sourceMappingURL=getTransactionStatus.js.map