@ledgerhq/ledger-cal-service
Version:
Ledger CAL service client
36 lines • 1.43 kB
JavaScript
import network from "@ledgerhq/live-network";
import { hours, makeLRUCache } from "@ledgerhq/live-network/cache";
import { getCALDomain } from "./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";
export class NoNetworksFound extends Error {
constructor() {
super();
this.name = "NoNetworkFound";
}
}
export const getCachedNetworks = makeLRUCache(async (id, opt) => getNetworks(id, opt), id => id ?? "", hours(1));
export async function getNetworks(id = null, { env = "prod", ref = undefined }) {
const { data } = await network({
url: `${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,
}));
}
//# sourceMappingURL=networks.js.map