UNPKG

@molecularlabs/nucleus-frontend

Version:
56 lines 1.45 kB
let configCache = null; async function isChainSupported(chainId) { const config = await fetchVaultConfigs(); return chainId.toString() in config.chains; } function toChainId(value) { return typeof value === "number" ? value : Number(value); } async function fetchVaultConfigs() { if (configCache) { return configCache; } try { const response = await fetch( "https://api.nucleusearn.io/prod/vault-config" ); if (!response.ok) { throw new Error(`API request failed with status ${response.status}`); } const data = await response.json(); configCache = data; return configCache; } catch (error) { console.error("Error in fetchVaultConfigs:", error); throw error; } } async function fetchVaultConfig(vaultKey) { const configs = await fetchVaultConfigs(); const vault = configs.vaults[vaultKey]; if (!vault) { throw new Error(`Vault config not found for key: ${vaultKey}`); } return vault; } async function getChainConfig(chainId) { const configs = await fetchVaultConfigs(); const key = chainId.toString(); const chain = configs.chains[key]; if (!chain) { throw new Error(`Chain config not found for ID: ${chainId}`); } return chain; } function clearConfigCache() { configCache = null; } export { clearConfigCache, fetchVaultConfig, fetchVaultConfigs, getChainConfig, isChainSupported, toChainId }; //# sourceMappingURL=vault-config.mjs.map