@ledgerhq/coin-filecoin
Version:
Ledger Filecoin Coin integration
71 lines • 2.56 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("@ledgerhq/coin-framework/currencies/index");
const utils_1 = require("./utils");
const network_1 = require("../network");
function getDeviceTransactionConfig(input) {
const tokenTransfer = input.account.type === utils_1.AccountType.TokenAccount;
const subAccount = tokenTransfer ? input.account : null;
const fields = [];
const unit = input.parentAccount
? input.parentAccount.currency.units[0]
: (0, utils_1.getAccountUnit)(input.account);
const formatConfig = {
disableRounding: true,
alwaysShowSign: false,
showCode: false,
};
if (subAccount) {
fields.push({
type: "filecoin.recipient",
label: "To",
value: (0, utils_1.expectedToFieldForTokenTransfer)(input.transaction.recipient),
});
}
else {
const recipient = input.transaction.recipient;
if (recipient.length >= 4 && recipient.substring(0, 4) === "0xff") {
const validated = (0, network_1.validateAddress)(recipient);
if (validated.isValid) {
const value = validated.parsedAddress.toString();
fields.push({
type: "filecoin.recipient",
label: "To",
value,
});
}
}
}
fields.push({
type: "filecoin.gasLimit",
label: "Gas Limit",
value: (0, index_1.formatCurrencyUnit)(unit, input.transaction.gasLimit, formatConfig),
});
if (!subAccount) {
fields.push({
type: "filecoin.gasFeeCap",
label: "Gas Fee Cap",
value: (0, index_1.formatCurrencyUnit)(unit, input.transaction.gasFeeCap, formatConfig),
});
fields.push({
type: "filecoin.gasPremium",
label: "Gas Premium",
value: (0, index_1.formatCurrencyUnit)(unit, input.transaction.gasPremium, formatConfig),
});
fields.push({
type: "filecoin.method",
label: "Method",
value: (0, utils_1.methodToString)(input.transaction.method),
});
}
if (subAccount) {
fields.push({
type: "filecoin.method",
label: "Method",
value: (0, utils_1.methodToString)(utils_1.Methods.ERC20Transfer),
});
}
return fields;
}
exports.default = getDeviceTransactionConfig;
//# sourceMappingURL=deviceTransactionConfig.js.map