@ledgerhq/coin-canton
Version:
50 lines • 2.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toTransactionRaw = exports.fromTransactionRaw = exports.formatTransaction = void 0;
const bignumber_js_1 = require("bignumber.js");
const formatters_1 = require("@ledgerhq/coin-framework/formatters");
const transaction_1 = require("@ledgerhq/coin-framework/serialization/transaction");
const index_1 = require("@ledgerhq/coin-framework/account/index");
const index_2 = require("@ledgerhq/coin-framework/currencies/index");
const formatTransaction = ({ amount, recipient, fee, useAllAmount }, account) => `
SEND ${useAllAmount
? "MAX"
: (0, index_2.formatCurrencyUnit)((0, index_1.getAccountCurrency)(account).units[0], amount, {
showCode: true,
disableRounding: true,
})}
TO ${recipient}
with fee=${!fee
? "?"
: (0, index_2.formatCurrencyUnit)((0, index_1.getAccountCurrency)(account).units[0], fee, {
showCode: true,
disableRounding: true,
})}`;
exports.formatTransaction = formatTransaction;
const fromTransactionRaw = (tr) => {
const common = (0, transaction_1.fromTransactionCommonRaw)(tr);
return {
...common,
family: tr.family,
fee: tr.fee ? new bignumber_js_1.BigNumber(tr.fee) : null,
};
};
exports.fromTransactionRaw = fromTransactionRaw;
const toTransactionRaw = (t) => {
const common = (0, transaction_1.toTransactionCommonRaw)(t);
return {
...common,
family: t.family,
fee: t.fee ? t.fee.toString() : null,
};
};
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