UNPKG

@ledgerhq/live-common

Version:
62 lines 2.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toTransactionRaw = exports.fromTransactionRaw = exports.formatTransaction = void 0; const index_1 = require("@ledgerhq/coin-framework/currencies/index"); const index_2 = require("@ledgerhq/ledger-wallet-framework/account/index"); const formatters_1 = require("@ledgerhq/ledger-wallet-framework/formatters"); const transaction_1 = require("@ledgerhq/ledger-wallet-framework/serialization/transaction"); const bignumber_js_1 = require("bignumber.js"); const formatTransaction = ({ amount, recipient, fees, tag, useAllAmount }, account) => ` SEND ${useAllAmount ? "MAX" : (0, index_1.formatCurrencyUnit)((0, index_2.getAccountCurrency)(account).units[0], amount, { showCode: true, disableRounding: true, })} TO ${recipient} with fee=${!fees ? "?" : (0, index_1.formatCurrencyUnit)((0, index_2.getAccountCurrency)(account).units[0], fees, { showCode: true, disableRounding: true, })}${tag ? "\n tag=" + tag : ""}`; exports.formatTransaction = formatTransaction; const fromTransactionRaw = (tr) => { const common = (0, transaction_1.fromTransactionCommonRaw)(tr); const { networkInfo } = tr; return { ...common, family: tr.family, tag: tr.tag, fees: tr.fees ? new bignumber_js_1.BigNumber(tr.fees) : null, networkInfo: networkInfo && { family: networkInfo.family, serverFee: new bignumber_js_1.BigNumber(networkInfo.serverFee), }, }; }; exports.fromTransactionRaw = fromTransactionRaw; const toTransactionRaw = (t) => { const common = (0, transaction_1.toTransactionCommonRaw)(t); const { networkInfo } = t; return { ...common, family: t.family, tag: t.tag, fees: t.fees ? t.fees.toString() : null, networkInfo: networkInfo && { family: networkInfo.family, serverFee: networkInfo.serverFee.toString(), }, }; }; exports.toTransactionRaw = toTransactionRaw; exports.default = { formatTransaction: exports.formatTransaction, fromTransactionRaw: exports.fromTransactionRaw, toTransactionRaw: exports.toTransactionRaw, fromTransactionStatusRaw: transaction_1.fromTransactionStatusRawCommon, toTransactionStatusRaw: transaction_1.toTransactionStatusRawCommon, formatTransactionStatus: formatters_1.formatTransactionStatus, }; //# sourceMappingURL=transaction.js.map