web3-error-helper
Version:
> 🛠️ Turn confusing Web3 errors into clear, human-friendly messages for developers and users alike.
86 lines (85 loc) • 3.94 kB
JavaScript
/**
* Chain management facade
*
* Provides a unified interface for managing blockchain networks.
* This module acts as a facade that delegates to specialized modules
* for built-in chains, custom chains, validation, and statistics.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.getChainStats = exports.isValidChainFormat = exports.isValidChain = exports.hasCustomChain = exports.getAllCustomChains = exports.getCustomChain = exports.isBuiltInChain = exports.getBuiltInChains = void 0;
exports.getAvailableChains = getAvailableChains;
exports.getChainInfo = getChainInfo;
const built_in_chain_manager_1 = require("./built-in-chain-manager");
const chain_registry_1 = require("./chain-registry");
// Re-export only what's needed from built-in-chain-manager
var built_in_chain_manager_2 = require("./built-in-chain-manager");
Object.defineProperty(exports, "getBuiltInChains", { enumerable: true, get: function () { return built_in_chain_manager_2.getBuiltInChains; } });
Object.defineProperty(exports, "isBuiltInChain", { enumerable: true, get: function () { return built_in_chain_manager_2.isBuiltInChain; } });
// Re-export only what's needed from chain-registry
var chain_registry_2 = require("./chain-registry");
Object.defineProperty(exports, "getCustomChain", { enumerable: true, get: function () { return chain_registry_2.getCustomChain; } });
Object.defineProperty(exports, "getAllCustomChains", { enumerable: true, get: function () { return chain_registry_2.getAllCustomChains; } });
Object.defineProperty(exports, "hasCustomChain", { enumerable: true, get: function () { return chain_registry_2.hasCustomChain; } });
// Re-export only what's needed from chain-validator
var chain_validator_1 = require("./chain-validator");
Object.defineProperty(exports, "isValidChain", { enumerable: true, get: function () { return chain_validator_1.isValidChain; } });
Object.defineProperty(exports, "isValidChainFormat", { enumerable: true, get: function () { return chain_validator_1.isValidChainFormat; } });
// Re-export only what's needed from chain-stats
var chain_stats_1 = require("./chain-stats");
Object.defineProperty(exports, "getChainStats", { enumerable: true, get: function () { return chain_stats_1.getChainStats; } });
/**
* Get all available blockchain networks
*
* Returns a list of all supported blockchain networks that have error mappings available.
* This includes both EVM-compatible chains and other supported networks.
*
* @returns Array of supported chain identifiers
*
* @example
* ```typescript
* const chains = getAvailableChains();
* console.log(chains); // ['ethereum', 'polygon', 'arbitrum', 'optimism', ...]
*
* // Use in a dropdown or selection UI
* chains.forEach(chain => {
* console.log(`Supported chain: ${chain}`);
* });
* ```
*/
function getAvailableChains() {
const builtInChains = (0, built_in_chain_manager_1.getBuiltInChains)();
const customChains = (0, chain_registry_1.getAllCustomChains)().map(config => config.chainId);
return [...customChains, ...builtInChains];
}
/**
* Get unified chain information
*
* @param chain - The chain identifier
* @returns Chain information object or null if not found
*
* @example
* ```typescript
* const info = getChainInfo('ethereum');
* console.log(info); // { type: 'built-in', name: 'Ethereum' }
*
* const customInfo = getChainInfo('my-custom-chain');
* console.log(customInfo); // { type: 'custom', name: 'My Custom Chain' }
* ```
*/
function getChainInfo(chain) {
// Try built-in first
const builtInInfo = (0, built_in_chain_manager_1.getBuiltInChainInfo)(chain);
if (builtInInfo) {
return builtInInfo;
}
// Try custom chains
const customChain = (0, chain_registry_1.getCustomChain)(chain);
if (customChain) {
return {
type: 'custom',
name: customChain.name,
};
}
return null;
}
;