Files
explore/lib/web3/chains.ts
T
tom goriunovandGitHub 36930767c9 OP Superchain Explorer: MVP (#2786)
* context for storing subchain config and tx view for subchain

* address page and block page for subchain

* address aggregated page: local txs tab

* connect MultichainSelect to context

* home page placeholder

* refactor subchain select state

* envs for demo

* fix ts

* clear value for l2 review

* subchain widgets on home page

* csp policies

* sockets, duck and goose

* fix socket on subchain address page

* link builder for subchain views

* update home widget

* fix time increment

* enable tx interpretator and metadata service

* generate multichain config based on every chain app config

* Fix the multichain config to work in Docker

* multichain socket test

* rename subchain-id to subchain-slug path param

* refactoring

* update chain icons on entities

* home page: latest local txs

* latest cross-chain txs

* minor improvements

* renaming, pt. 1

* rename chain routes

* enable blockchain interaction

* add loading state to icon shield

* fix build

* fix tests

* update types package
2025-07-03 15:07:00 +02:00

73 lines
1.7 KiB
TypeScript

import { type Chain } from 'viem';
import appConfig from 'configs/app';
import multichainConfig from 'configs/multichain';
const getChainInfo = (config: typeof appConfig = appConfig) => {
return {
id: Number(config.chain.id),
name: config.chain.name ?? '',
nativeCurrency: {
decimals: config.chain.currency.decimals,
name: config.chain.currency.name ?? '',
symbol: config.chain.currency.symbol ?? '',
},
rpcUrls: {
'default': {
http: config.chain.rpcUrls,
},
},
blockExplorers: {
'default': {
name: 'Blockscout',
url: config.app.baseUrl,
},
},
testnet: config.chain.isTestnet,
};
};
export const currentChain: Chain | undefined = !appConfig.features.opSuperchain.isEnabled ? getChainInfo() : undefined;
export const parentChain: Chain | undefined = (() => {
const rollupFeature = appConfig.features.rollup;
const parentChain = rollupFeature.isEnabled && rollupFeature.parentChain;
if (!parentChain) {
return;
}
if (!parentChain.id || !parentChain.name || !parentChain.rpcUrls || !parentChain.baseUrl || !parentChain.currency) {
return;
}
return {
id: parentChain.id,
name: parentChain.name,
nativeCurrency: parentChain.currency,
rpcUrls: {
'default': {
http: parentChain.rpcUrls,
},
},
blockExplorers: {
'default': {
name: 'Blockscout',
url: parentChain.baseUrl,
},
},
testnet: parentChain.isTestnet,
};
})();
export const clusterChains: Array<Chain> | undefined = (() => {
const config = multichainConfig();
if (!config) {
return;
}
return config.chains.map(({ config }) => getChainInfo(config)).filter(Boolean);
})();