diff --git a/src/assets/networks.json b/src/assets/networks.json index 4761785..c4a9229 100644 --- a/src/assets/networks.json +++ b/src/assets/networks.json @@ -1,5 +1,5 @@ -[ - { +{ + "polkadot": { "name": "Polkadot", "specName": "polkadot", "addressPrefix": 0, @@ -7,6 +7,10 @@ "icon": "https://raw.githubusercontent.com/novasamatech/nova-spektr-utils/main/icons/v1/chains/Polkadot.svg", "options": ["multisig"], "nodes": [ + { + "url": "wss://rpc.ibp.network/polkadot", + "name": "IBP network node" + }, { "url": "wss://polkadot.public.curie.radiumblock.co/ws", "name": "Radium node" @@ -27,10 +31,6 @@ "url": "wss://rpc-polkadot.luckyfriday.io", "name": "LuckyFriday node" }, - { - "url": "wss://rpc.ibp.network/polkadot", - "name": "IBP network node" - }, { "url": "wss://rpc.dotters.network/polkadot", "name": "Dotters Net node" @@ -84,7 +84,7 @@ ] } }, - { + "kusama": { "name": "Kusama", "specName": "kusama", "addressPrefix": 2, @@ -92,6 +92,10 @@ "icon": "https://raw.githubusercontent.com/novasamatech/nova-spektr-utils/main/icons/v1/chains/Kusama.svg", "options": ["multisig"], "nodes": [ + { + "url": "wss://rpc.ibp.network/kusama", + "name": "IBP network node" + }, { "url": "wss://kusama-rpc.dwellir.com", "name": "Dwellir node" @@ -104,10 +108,6 @@ "url": "wss://1rpc.io/ksm", "name": "Automata 1RPC node" }, - { - "url": "wss://rpc.ibp.network/kusama", - "name": "IBP network node" - }, { "url": "wss://rpc.dotters.network/kusama", "name": "Dotters Net node" @@ -169,7 +169,7 @@ ] } }, - { + "westend": { "name": "Westend", "specName": "westend", "addressPrefix": 42, @@ -231,4 +231,4 @@ ] } } -] +} diff --git a/src/contexts/NetworkContext.tsx b/src/contexts/NetworkContext.tsx index 6bb6144..fee4cc8 100644 --- a/src/contexts/NetworkContext.tsx +++ b/src/contexts/NetworkContext.tsx @@ -7,7 +7,6 @@ import { getWsProvider } from 'polkadot-api/ws-provider/web' import { getSmProvider } from 'polkadot-api/sm-provider' import SmWorker from 'polkadot-api/smoldot/worker?worker' import { startFromWorker } from 'polkadot-api/smoldot/from-worker' -import { supportedNetworksChainIds } from '@/lib/constants' import { getChainInformation } from '@/lib/utils' import { AssetType } from '@/lib/types' @@ -46,19 +45,16 @@ const NetworkContextProvider = ({ children }: NetworkContextProps) => { switch (network) { case 'polkadot': { - const [wsProv, assetInformation] = getChainInformation('polkadot') - setAssetInfo(assetInformation) + const { assetInfo, wsEndpoint } = getChainInformation('polkadot') + setAssetInfo(assetInfo) setIsLight(false) - if (!wsProv) return - cl = createClient(getWsProvider(wsProv)) + cl = createClient(getWsProvider(wsEndpoint)) typedApi = cl.getTypedApi(dot) } break case 'polkadot-lc': { - const [, assetInformation] = getChainInformation( - supportedNetworksChainIds.polkadot, - ) - setAssetInfo(assetInformation) + const { assetInfo } = getChainInformation('polkadot') + setAssetInfo(assetInfo) setIsLight(true) const smoldot = startFromWorker(new SmWorker()) const dotRelayChain = import('polkadot-api/chains/polkadot').then( @@ -70,21 +66,17 @@ const NetworkContextProvider = ({ children }: NetworkContextProps) => { } case 'kusama': { - const [wsProv, assetInformation] = getChainInformation( - supportedNetworksChainIds.kusama, - ) - setAssetInfo(assetInformation) + const { assetInfo, wsEndpoint } = getChainInformation('kusama') + setAssetInfo(assetInfo) setIsLight(false) - if (!wsProv) return - cl = createClient(getWsProvider(wsProv)) + + cl = createClient(getWsProvider(wsEndpoint)) typedApi = cl.getTypedApi(ksm) } break case 'kusama-lc': { - const [, assetInformation] = getChainInformation( - supportedNetworksChainIds.kusama, - ) - setAssetInfo(assetInformation) + const { assetInfo } = getChainInformation('kusama') + setAssetInfo(assetInfo) setIsLight(true) const smoldot = startFromWorker(new SmWorker()) const ksmRelayChain = import('polkadot-api/chains/ksmcc3').then( diff --git a/src/lib/constants.tsx b/src/lib/constants.tsx index 5f767ee..95776c4 100644 --- a/src/lib/constants.tsx +++ b/src/lib/constants.tsx @@ -48,12 +48,6 @@ const msgs: Record = { }, } -const supportedNetworksChainIds = { - polkadot: - '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', - kusama: '0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe', -} - // Exports export { // Site specifics @@ -67,7 +61,6 @@ export { DelegeeListPolkadot, DelegeeListKusama, GithubOwner, - supportedNetworksChainIds, // Alert messsages msgs, } diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 4f58f45..021da3b 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -3,8 +3,7 @@ import { House } from 'lucide-react' import networks from '@/assets/networks.json' import { twMerge } from 'tailwind-merge' -import type { AssetType, NameUrl, NetworkType, RouterType } from './types' -import { supportedNetworksChainIds } from './constants' +import type { NetworkType, RouterType } from './types' const cn = (...inputs: ClassValue[]) => { return twMerge(clsx(inputs)) @@ -12,28 +11,12 @@ const cn = (...inputs: ClassValue[]) => { const routes: RouterType[] = [{ link: 'home', name: 'Home', icon: House }] -const getSupportedNetworkInfo = (chainId: string): NetworkType => { - const network = networks.filter((n: { chainId: string }) => { - if (n.chainId === chainId) { - return n - } - }) - return network as unknown as NetworkType +const getChainInformation = (networkName: keyof typeof networks) => { + const network: NetworkType = networks[networkName] + return { + assetInfo: network.assets[0], + wsEndpoint: network.nodes[0].url, + } } -const getChainInformation = (nw: string): [string | null, AssetType] => { - const network: NetworkType = getSupportedNetworkInfo( - nw === 'polkadot' - ? supportedNetworksChainIds.polkadot - : supportedNetworksChainIds.kusama, - ) - const ws = network?.nodes?.map((n: NameUrl) => n.url) - if (!ws) return [null, {} as AssetType] - - const randomWs = Math.floor(Math.random() * ws.length) - - // return 2 values - a random wss (or null) and asset info - return [ws[randomWs] || null, network.assets[0] || ({} as AssetType)] -} - -export { cn, routes, getSupportedNetworkInfo, getChainInformation } +export { cn, routes, getChainInformation }