UNPKG

@ledgerhq/ledger-cal-service

Version:
44 lines 1.87 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getNetworks = exports.getCachedNetworks = exports.NoNetworksFound = void 0; const live_network_1 = __importDefault(require("@ledgerhq/live-network")); const cache_1 = require("@ledgerhq/live-network/cache"); const common_1 = require("./common"); const OUTPUT_FILTER = "chain_id,coin,coin_type,confirmations_needed,deposit_amount,descriptors,family,has_segwit,has_tokens,hrp,icons,id,max_transaction_version,min_transaction_version,name,network_magic,network_type,token_standard,type,wallet_app_name"; class NoNetworksFound extends Error { constructor() { super(); this.name = "NoNetworkFound"; } } exports.NoNetworksFound = NoNetworksFound; exports.getCachedNetworks = (0, cache_1.makeLRUCache)(async (id, opt) => getNetworks(id, opt), id => id ?? "", (0, cache_1.hours)(1)); async function getNetworks(id = null, { env = "prod", ref = undefined }) { const { data } = await (0, live_network_1.default)({ url: `${(0, common_1.getCALDomain)(env)}/v1/networks`, params: { output: OUTPUT_FILTER, id, ref, }, }); if (data.length === 0 || (id !== null && data.length !== 1)) { throw new NoNetworksFound(); } return data.map(network => ({ id: network.id, name: network.name, coin: network.coin, chainId: network.chain_id, coinType: network.coin_type, family: network.family, networkType: network.network_type, tokenStandard: network.token_standard, appName: network.wallet_app_name, })); } exports.getNetworks = getNetworks; //# sourceMappingURL=networks.js.map