UNPKG

@ledgerhq/live-common

Version:
95 lines 5.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getVotesCount = exports.clearAccount = exports.isAccountEmpty = exports.shortAddressPreview = exports.listSubAccounts = exports.isTokenAccount = exports.isAccountBalanceUnconfirmed = exports.isAccount = exports.getParentAccount = exports.getFeesUnit = exports.getFeesCurrency = exports.getAccountSpendableBalance = exports.getAccountCurrency = exports.getMainAccount = exports.flattenAccounts = exports.findTokenAccountByCurrency = exports.accountWithMandatoryTokens = void 0; const types_1 = require("@ledgerhq/coin-bitcoin/types"); const account_1 = require("@ledgerhq/coin-framework/account"); const helpers_1 = require("@ledgerhq/coin-cosmos/helpers"); const index_1 = require("@ledgerhq/coin-cosmos/types/index"); const index_2 = require("@ledgerhq/coin-tron/index"); const index_3 = require("@ledgerhq/coin-vechain/index"); const staking_1 = require("../families/tezos/staking"); // TODO: remove this export and prefer import from root file. var index_4 = require("@ledgerhq/coin-framework/account/index"); Object.defineProperty(exports, "accountWithMandatoryTokens", { enumerable: true, get: function () { return index_4.accountWithMandatoryTokens; } }); Object.defineProperty(exports, "findTokenAccountByCurrency", { enumerable: true, get: function () { return index_4.findTokenAccountByCurrency; } }); Object.defineProperty(exports, "flattenAccounts", { enumerable: true, get: function () { return index_4.flattenAccounts; } }); Object.defineProperty(exports, "getMainAccount", { enumerable: true, get: function () { return index_4.getMainAccount; } }); Object.defineProperty(exports, "getAccountCurrency", { enumerable: true, get: function () { return index_4.getAccountCurrency; } }); Object.defineProperty(exports, "getAccountSpendableBalance", { enumerable: true, get: function () { return index_4.getAccountSpendableBalance; } }); Object.defineProperty(exports, "getFeesCurrency", { enumerable: true, get: function () { return index_4.getFeesCurrency; } }); Object.defineProperty(exports, "getFeesUnit", { enumerable: true, get: function () { return index_4.getFeesUnit; } }); Object.defineProperty(exports, "getParentAccount", { enumerable: true, get: function () { return index_4.getParentAccount; } }); Object.defineProperty(exports, "isAccount", { enumerable: true, get: function () { return index_4.isAccount; } }); Object.defineProperty(exports, "isAccountBalanceUnconfirmed", { enumerable: true, get: function () { return index_4.isAccountBalanceUnconfirmed; } }); Object.defineProperty(exports, "isTokenAccount", { enumerable: true, get: function () { return index_4.isTokenAccount; } }); Object.defineProperty(exports, "listSubAccounts", { enumerable: true, get: function () { return index_4.listSubAccounts; } }); Object.defineProperty(exports, "shortAddressPreview", { enumerable: true, get: function () { return index_4.shortAddressPreview; } }); const isAccountEmpty = (a) => { if (a.type === "Account") { if ((0, index_1.isCosmosAccount)(a)) { return (0, helpers_1.isAccountEmpty)(a); } if ((0, index_2.isTronAccount)(a)) { return (0, index_2.isAccountEmpty)(a); } if (a.currency.family == "vechain") { return (0, index_3.isAccountEmpty)(a); } } return (0, account_1.isAccountEmpty)(a); }; exports.isAccountEmpty = isAccountEmpty; // in future, could be a per currency thing // clear account to a bare minimal version that can be restored via sync // will preserve the balance to avoid user panic function clearAccount(account) { // FIXME add in the coins bridge a way for a coin to define extra clean up functions to modularize this. return (0, account_1.clearAccount)(account, (account) => { if ((0, index_2.isTronAccount)(account)) { account.tronResources = { ...account.tronResources, cacheTransactionInfoById: {}, }; } if (account.currency.family === "bitcoin") { account.bitcoinResources = types_1.initialBitcoinResourcesValue; } }); } exports.clearAccount = clearAccount; const getVotesCount = (account, parentAccount) => { const mainAccount = (0, account_1.getMainAccount)(account, parentAccount); // FIXME add this back in the coin bridge. switch (mainAccount.currency.family) { case "tezos": return (0, staking_1.isAccountDelegating)(account) ? 1 : 0; case "tron": return mainAccount?.tronResources?.votes.length || 0; case "axelar": case "onomy": case "quicksilver": case "stride": case "persistence": case "stargaze": case "nyx": case "secret_network": case "sei_network": case "desmos": case "dydx": case "umee": case "binance_beacon_chain": case "osmosis": case "cosmos": case "coreum": case "mantra": case "crypto_org": case "xion": case "zenrock": case "babylon": return mainAccount?.cosmosResources?.delegations.length || 0; default: return 0; } }; exports.getVotesCount = getVotesCount; //# sourceMappingURL=helpers.js.map