@molecularlabs/nucleus-frontend
Version:
Nucleus BoringVault Frontend SDK
50 lines • 1.75 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 chain_utils_exports = {};
__export(chain_utils_exports, {
clearChainsCache: () => clearChainsCache,
getChainFromConfig: () => getChainFromConfig
});
module.exports = __toCommonJS(chain_utils_exports);
var import_vault_config = require("../api/vault-config");
let chainsCache = null;
async function getChainFromConfig(chainId, config) {
if (chainsCache && !config) {
const chain2 = chainsCache.get(chainId);
if (chain2) return chain2;
}
const vaultConfig = config ?? await (0, import_vault_config.fetchVaultConfigs)();
const chain = vaultConfig.chains[chainId];
if (!chain) {
throw new Error(`Chain not found for ID: ${chainId}`);
}
if (config && !chainsCache) {
chainsCache = new Map(
Object.entries(config.chains).map(([id, chain2]) => [
Number(id),
chain2
])
);
}
return chain;
}
function clearChainsCache() {
chainsCache = null;
}
//# sourceMappingURL=chain-utils.js.map