@ledgerhq/coin-algorand
Version:
Ledger Algorand Coin integration
58 lines • 2.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatTransaction = void 0;
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 bignumber_js_1 = require("bignumber.js");
const formatTransaction = ({ mode, subAccountId, amount, recipient, fees, useAllAmount }, mainAccount) => {
const account = (subAccountId && (mainAccount.subAccounts || []).find(a => a.id === subAccountId)) ||
mainAccount;
return `
${mode === "claimReward" ? "CLAIM REWARD" : mode === "optIn" ? "OPT_IN" : "SEND"} ${useAllAmount
? "MAX"
: (0, index_2.formatCurrencyUnit)((0, index_1.getAccountCurrency)(account).units[0], amount, {
showCode: true,
disableRounding: false,
})}
TO ${recipient}
with fees=${!fees
? "?"
: (0, index_2.formatCurrencyUnit)(mainAccount.currency.units[0], fees, {
showCode: true,
disableRounding: false,
})}`;
};
exports.formatTransaction = formatTransaction;
const fromTransactionRaw = (tr) => {
const common = (0, serialization_1.fromTransactionCommonRaw)(tr);
return {
...common,
family: tr.family,
fees: tr.fees ? new bignumber_js_1.BigNumber(tr.fees) : null,
memo: tr.memo,
mode: tr.mode,
assetId: tr.assetId,
};
};
const toTransactionRaw = (t) => {
const common = (0, serialization_1.toTransactionCommonRaw)(t);
return {
...common,
family: t.family,
fees: t.fees ? t.fees.toString() : null,
memo: t.memo,
mode: t.mode,
assetId: t.assetId,
};
};
exports.default = {
formatTransaction: exports.formatTransaction,
fromTransactionRaw,
toTransactionRaw,
fromTransactionStatusRaw: serialization_1.fromTransactionStatusRawCommon,
toTransactionStatusRaw: serialization_1.toTransactionStatusRawCommon,
formatTransactionStatus: formatters_1.formatTransactionStatus,
};
//# sourceMappingURL=transaction.js.map