UNPKG

@ledgerhq/coin-stacks

Version:
64 lines 2.62 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.fromTransactionRaw = exports.formatTransaction = void 0; const bignumber_js_1 = __importDefault(require("bignumber.js")); const api_types_1 = require("../network/api.types"); const index_1 = require("@ledgerhq/coin-framework/account/index"); const index_2 = require("@ledgerhq/coin-framework/currencies/index"); const formatters_1 = require("@ledgerhq/coin-framework/formatters"); const serialization_1 = require("@ledgerhq/coin-framework/serialization"); const formatTransaction = ({ recipient, useAllAmount, amount }, account) => ` SEND ${useAllAmount ? "MAX" : amount.isZero() ? "" : " " + (0, index_2.formatCurrencyUnit)((0, index_1.getAccountCurrency)(account).units[0], amount, { showCode: true, disableRounding: true, })} TO ${recipient}`; exports.formatTransaction = formatTransaction; const fromTransactionRaw = (tr) => { const common = (0, serialization_1.fromTransactionCommonRaw)(tr); // validate if network is valid if (!api_types_1.StacksNetwork[tr.network]) { throw new Error(`network ${tr.network} not valid`); } return { ...common, family: tr.family, nonce: tr.nonce !== undefined ? new bignumber_js_1.default(tr.nonce) : undefined, fee: tr.fee !== undefined ? new bignumber_js_1.default(tr.fee) : undefined, amount: new bignumber_js_1.default(tr.amount), network: tr.network, anchorMode: tr.anchorMode, memo: tr.memo, }; }; exports.fromTransactionRaw = fromTransactionRaw; const toTransactionRaw = (t) => { const common = (0, serialization_1.toTransactionCommonRaw)(t); return { ...common, family: t.family, fee: t.fee !== undefined ? t.fee.toFixed() : undefined, nonce: t.nonce !== undefined ? t.nonce.toFixed() : undefined, amount: t.amount.toFixed(), network: t.network, anchorMode: t.anchorMode, memo: t.memo, }; }; exports.default = { formatTransaction: exports.formatTransaction, fromTransactionRaw: exports.fromTransactionRaw, toTransactionRaw, formatTransactionStatus: formatters_1.formatTransactionStatus, fromTransactionStatusRaw: serialization_1.fromTransactionStatusRawCommon, toTransactionStatusRaw: serialization_1.toTransactionStatusRawCommon, }; //# sourceMappingURL=transaction.js.map