@molecularlabs/nucleus-frontend
Version:
Nucleus BoringVault Frontend SDK
76 lines • 2.49 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var vault_config_exports = {};
__export(vault_config_exports, {
clearConfigCache: () => clearConfigCache,
fetchVaultConfig: () => fetchVaultConfig,
fetchVaultConfigs: () => fetchVaultConfigs,
getChainConfig: () => getChainConfig,
isChainSupported: () => isChainSupported,
toChainId: () => toChainId
});
module.exports = __toCommonJS(vault_config_exports);
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;
}
//# sourceMappingURL=vault-config.js.map