@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
67 lines • 3.41 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.genericGetTransactionStatus = genericGetTransactionStatus;
const errors_1 = require("@ledgerhq/errors");
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const alpaca_1 = require("./alpaca");
const bridge_1 = require("./bridge");
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 bridgeApi = (0, bridge_1.getBridgeApi)(account.currency, network);
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,
type: transaction.type,
sponsored: transaction.sponsored,
};
const chainSpecificValidation = bridgeApi.getChainSpecificRules?.();
if (chainSpecificValidation) {
if (chainSpecificValidation.getTransactionStatus.throwIfPendingOperation) {
if (account.pendingOperations.length > 0) {
throw new errors_1.AccountAwaitingSendPendingOperations();
}
}
}
let intent = (0, utils_1.transactionToIntent)(account, draftTransaction, alpacaApi.computeIntentType);
intent = (0, utils_1.applyMemoToIntent)(intent, transaction);
const customFees = (0, utils_1.bigNumberToBigIntDeep)({
value: transaction.fees ?? new bignumber_js_1.default(0),
parameters: {
gasLimit: transaction.gasLimit,
customGasLimit: transaction.customGasLimit,
gasPrice: transaction.gasPrice,
maxFeePerGas: transaction.maxFeePerGas,
maxPriorityFeePerGas: transaction.maxPriorityFeePerGas,
additionalFees: transaction.additionalFees,
},
});
const { errors, warnings, estimatedFees, amount, totalSpent, totalFees } = await alpacaApi.validateIntent(intent, (0, utils_1.extractBalances)(account, bridgeApi.getAssetFromToken), customFees);
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: new bignumber_js_1.default(amount.toString()),
totalSpent: new bignumber_js_1.default(totalSpent.toString()),
};
};
}
//# sourceMappingURL=getTransactionStatus.js.map