UNPKG

@ledgerhq/coin-hedera

Version:
112 lines 4.04 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatTransaction = formatTransaction; exports.fromTransactionRaw = fromTransactionRaw; exports.toTransactionRaw = toTransactionRaw; const index_1 = require("@ledgerhq/coin-module-framework/currencies/index"); const index_2 = require("@ledgerhq/ledger-wallet-framework/account/index"); const formatters_1 = require("@ledgerhq/ledger-wallet-framework/formatters"); const serialization_1 = require("@ledgerhq/ledger-wallet-framework/serialization"); const bignumber_js_1 = __importDefault(require("bignumber.js")); const constants_1 = require("./constants"); function formatTransaction(transaction, account) { const amount = (0, index_1.formatCurrencyUnit)((0, index_2.getAccountCurrency)(account).units[0], transaction.amount, { showCode: true, disableRounding: true, }); return `SEND ${amount}\nTO ${transaction.recipient}`; } function fromTransactionRaw(tr) { const commonGeneric = (0, serialization_1.fromTransactionCommonRaw)(tr); const commonHedera = { family: tr.family, memo: tr.memo, ...(tr.maxFee && { maxFee: new bignumber_js_1.default(tr.maxFee) }), }; if (tr.mode === constants_1.HEDERA_TRANSACTION_MODES.TokenAssociate) { return { ...commonGeneric, ...commonHedera, mode: tr.mode, assetReference: tr.assetReference, assetOwner: tr.assetOwner, properties: tr.properties, }; } if (tr.mode === constants_1.HEDERA_TRANSACTION_MODES.Delegate || tr.mode === constants_1.HEDERA_TRANSACTION_MODES.Undelegate || tr.mode === constants_1.HEDERA_TRANSACTION_MODES.Redelegate) { return { ...commonGeneric, ...commonHedera, mode: tr.mode, properties: tr.properties, }; } if (tr.mode === constants_1.HEDERA_TRANSACTION_MODES.ClaimRewards) { return { ...commonGeneric, ...commonHedera, mode: tr.mode, }; } return { ...commonGeneric, ...commonHedera, mode: tr.mode, ...(tr.gasLimit && { gasLimit: new bignumber_js_1.default(tr.gasLimit) }), }; } function toTransactionRaw(t) { const commonGeneric = (0, serialization_1.toTransactionCommonRaw)(t); const commonHedera = { family: t.family, memo: t.memo, ...(t.maxFee && { maxFee: t.maxFee.toString() }), }; if (t.mode === constants_1.HEDERA_TRANSACTION_MODES.TokenAssociate) { return { ...commonGeneric, ...commonHedera, mode: t.mode, assetReference: t.assetReference, assetOwner: t.assetOwner, properties: t.properties, }; } if (t.mode === constants_1.HEDERA_TRANSACTION_MODES.Delegate || t.mode === constants_1.HEDERA_TRANSACTION_MODES.Undelegate || t.mode === constants_1.HEDERA_TRANSACTION_MODES.Redelegate) { return { ...commonGeneric, ...commonHedera, mode: t.mode, properties: t.properties, }; } if (t.mode === constants_1.HEDERA_TRANSACTION_MODES.ClaimRewards) { return { ...commonGeneric, ...commonHedera, mode: t.mode, }; } return { ...commonGeneric, ...commonHedera, mode: t.mode, ...(t.gasLimit && { gasLimit: t.gasLimit.toString() }), }; } exports.default = { formatTransaction, fromTransactionRaw, toTransactionRaw, fromTransactionStatusRaw: serialization_1.fromTransactionStatusRawCommon, toTransactionStatusRaw: serialization_1.toTransactionStatusRawCommon, formatTransactionStatus: formatters_1.formatTransactionStatus, }; //# sourceMappingURL=transaction.js.map