@ledgerhq/coin-tron
Version:
Ledger Tron Coin integration
71 lines • 2.89 kB
JavaScript
import { formatCurrencyUnit } from "@ledgerhq/coin-module-framework/currencies";
import { getAccountCurrency } from "@ledgerhq/ledger-wallet-framework/account";
import { formatTransactionStatus } from "@ledgerhq/ledger-wallet-framework/formatters";
import { fromTransactionCommonRaw, fromTransactionStatusRawCommon as fromTransactionStatusRaw, toTransactionCommonRaw, toTransactionStatusRawCommon as toTransactionStatusRaw, } from "@ledgerhq/ledger-wallet-framework/serialization";
import { BigNumber } from "bignumber.js";
export const fromTransactionRaw = (tr) => {
const common = fromTransactionCommonRaw(tr);
const { networkInfo } = tr;
return {
...common,
networkInfo: networkInfo && {
family: "tron",
freeNetUsed: new BigNumber(networkInfo.freeNetUsed),
freeNetLimit: new BigNumber(networkInfo.freeNetLimit),
netUsed: new BigNumber(networkInfo.netUsed),
netLimit: new BigNumber(networkInfo.netLimit),
energyUsed: new BigNumber(networkInfo.energyUsed),
energyLimit: new BigNumber(networkInfo.energyLimit),
},
family: tr.family,
mode: tr.mode,
resource: tr.resource || null,
duration: tr.duration || 3,
votes: tr.votes,
};
};
export const toTransactionRaw = (t) => {
const common = toTransactionCommonRaw(t);
const { networkInfo } = t;
return {
...common,
networkInfo: networkInfo && {
family: "tron",
freeNetUsed: networkInfo.freeNetUsed.toString(),
freeNetLimit: networkInfo.freeNetLimit.toString(),
netUsed: networkInfo.netUsed.toString(),
netLimit: networkInfo.netLimit.toString(),
energyUsed: networkInfo.energyUsed.toString(),
energyLimit: networkInfo.energyLimit.toString(),
},
family: t.family,
mode: t.mode,
resource: t.resource || null,
duration: t.duration || 3,
votes: t.votes,
};
};
export const formatTransaction = (t, mainAccount) => {
const account = (t.subAccountId && (mainAccount.subAccounts || []).find(a => a.id === t.subAccountId)) ||
mainAccount;
return `
${t.mode.toUpperCase()}${t.resource ? " " + t.resource : ""} ${t.useAllAmount
? "MAX"
: t.amount.isZero()
? ""
: " " +
formatCurrencyUnit(getAccountCurrency(account).units[0], t.amount, {
showCode: true,
disableRounding: true,
})}${!t.votes ? "" : " " + t.votes.map(v => v.voteCount + "->" + v.address).join(" ")}
TO ${t.recipient}`;
};
export default {
formatTransaction,
fromTransactionRaw,
toTransactionRaw,
fromTransactionStatusRaw,
toTransactionStatusRaw,
formatTransactionStatus,
};
//# sourceMappingURL=transaction.js.map