@ledgerhq/coin-filecoin
Version:
Ledger Filecoin Coin integration
53 lines • 2 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildOptimisticOperation = void 0;
const operation_1 = require("@ledgerhq/coin-framework/operation");
const utils_1 = require("../bridge/utils");
const network_1 = require("../network");
const utils_2 = require("../common-logic/utils");
const buildOptimisticOperation = async (account, transaction, serializationRes, operationType = "OUT") => {
const type = operationType;
const subAccount = (0, utils_2.getSubAccount)(account, transaction);
// resolved at broadcast time
const txHash = "";
const { gasFeeCap, gasLimit } = transaction;
const { parsedSender, recipientToBroadcast, amountToBroadcast: finalAmount } = serializationRes;
const fee = (0, utils_1.calculateEstimatedFees)(gasFeeCap, gasLimit);
let operation;
if (subAccount) {
const recipientFilAddr = (0, network_1.convertAddressEthToFil)(transaction.recipient);
operation = {
id: (0, operation_1.encodeOperationId)(subAccount.id, txHash, "OUT"),
hash: txHash,
type,
value: finalAmount,
fee,
blockHeight: null,
blockHash: null,
accountId: subAccount.id,
senders: [parsedSender],
recipients: [recipientFilAddr],
date: new Date(),
extra: {},
};
}
else {
operation = {
id: (0, operation_1.encodeOperationId)(account.id, txHash, "OUT"),
hash: txHash,
type,
senders: [parsedSender],
recipients: [recipientToBroadcast],
accountId: account.id,
value: finalAmount.plus(fee),
fee,
blockHash: null,
blockHeight: null,
date: new Date(),
extra: {},
};
}
return operation;
};
exports.buildOptimisticOperation = buildOptimisticOperation;
//# sourceMappingURL=buildOptimisticOperation.js.map
;