UNPKG

@ledgerhq/coin-algorand

Version:
62 lines 2.17 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildOptimisticOperation = void 0; const bignumber_js_1 = __importDefault(require("bignumber.js")); const errors_1 = require("@ledgerhq/errors"); const operation_1 = require("@ledgerhq/coin-framework/operation"); const buildOptimisticOperation = (account, transaction) => { const { spendableBalance, id, freshAddress, subAccounts } = account; const senders = [freshAddress]; const recipients = [transaction.recipient]; const { subAccountId, fees } = transaction; if (!fees) { throw new errors_1.FeeNotLoaded(); } const value = subAccountId ? fees : transaction.useAllAmount ? spendableBalance : transaction.amount.plus(fees); const type = subAccountId ? "FEES" : transaction.mode === "optIn" ? "OPT_IN" : "OUT"; const op = { id: (0, operation_1.encodeOperationId)(id, "", type), hash: "", type, value, fee: fees, blockHash: null, blockHeight: null, senders, recipients, accountId: id, date: new Date(), extra: {}, }; const tokenAccount = !subAccountId ? null : subAccounts && subAccounts.find(ta => ta.id === subAccountId); if (tokenAccount && subAccountId) { op.subOperations = [ { id: `${subAccountId}--OUT`, hash: "", type: "OUT", value: transaction.useAllAmount ? tokenAccount.balance : transaction.amount, fee: new bignumber_js_1.default(0), blockHash: null, blockHeight: null, senders, recipients, accountId: subAccountId, date: new Date(), extra: {}, }, ]; } return op; }; exports.buildOptimisticOperation = buildOptimisticOperation; //# sourceMappingURL=buildOptimisticOperation.js.map