@ledgerhq/coin-multiversx
Version:
Ledger MultiversX Coin integration
55 lines • 1.76 kB
JavaScript
import BigNumber from "bignumber.js";
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies";
import { decodeTokenAccountId, getAccountCurrency } from "@ledgerhq/coin-framework/account";
import { isAmountSpentFromBalance } from "./logic";
function getDeviceTransactionConfig({ account, transaction, status: { estimatedFees }, }) {
const fields = [];
const { subAccountId } = transaction;
const isEsdtTransfer = subAccountId !== undefined && subAccountId !== null;
if (isEsdtTransfer) {
const { token } = decodeTokenAccountId(subAccountId);
if (token) {
fields.push({
type: "text",
label: "Token",
value: token.name,
});
fields.push({
type: "amount",
label: "Value",
});
}
}
fields.push({
type: "address",
label: "Receiver",
address: transaction.recipient,
});
if (!isEsdtTransfer) {
if (!isAmountSpentFromBalance(transaction.mode)) {
fields.push({
type: "text",
label: "Amount",
value: formatCurrencyUnit(getAccountCurrency(account).units[0], new BigNumber(0), {
showCode: true,
disableRounding: true,
}),
});
}
else {
fields.push({
type: "amount",
label: "Amount",
});
}
}
if (!estimatedFees.isZero()) {
fields.push({
type: "fees",
label: "Fee",
});
}
return fields;
}
export default getDeviceTransactionConfig;
//# sourceMappingURL=deviceTransactionConfig.js.map