@ledgerhq/coin-filecoin
Version:
Ledger Filecoin Coin integration
63 lines • 2.26 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const invariant_1 = __importDefault(require("invariant"));
const flatMap_1 = __importDefault(require("lodash/flatMap"));
const index_1 = require("@ledgerhq/coin-framework/account/index");
const utils_1 = require("../bridge/utils");
const options = [
{
name: "token",
alias: "t",
type: String,
desc: "use an token account children of the account",
},
];
function inferAccounts(account, opts) {
(0, invariant_1.default)(account.currency.family === "filecoin", "filecoin family");
if (!opts.token) {
const accounts = [account];
return accounts;
}
const token = opts.token;
const subAccounts = account.subAccounts || [];
if (token) {
const subAccount = subAccounts.find(t => {
const currency = (0, index_1.getAccountCurrency)(t);
return (token.toLowerCase() === currency.ticker.toLowerCase() || token.toLowerCase() === currency.id);
});
if (!subAccount) {
throw new Error("token account '" +
token +
"' not found. Available: " +
subAccounts.map(t => (0, index_1.getAccountCurrency)(t).ticker).join(", "));
}
return [subAccount];
}
return [];
}
function inferTransactions(transactions) {
return (0, flatMap_1.default)(transactions, ({ transaction, account }) => {
(0, invariant_1.default)(transaction.family === "filecoin", "filecoin family");
if (account.type === utils_1.AccountType.TokenAccount) {
const isDelisted = account.token.delisted === true;
(0, invariant_1.default)(!isDelisted, "token is delisted");
}
return {
...transaction,
family: "filecoin",
subAccountId: account.type === utils_1.AccountType.TokenAccount ? account.id : null,
};
});
}
function makeCliTools() {
return {
options,
inferAccounts,
inferTransactions,
};
}
exports.default = makeCliTools;
//# sourceMappingURL=cli.js.map