@@ -3,34 +3,53 @@ import React from "react";
3
3
import { createWeb3Modal } from "@web3modal/wagmi/react" ;
4
4
import { type Chain } from "viem" ;
5
5
import { createConfig , fallback , http , WagmiProvider , webSocket } from "wagmi" ;
6
- import { mainnet , arbitrumSepolia , arbitrum , gnosisChiado } from "wagmi/chains" ;
6
+ import { mainnet , arbitrumSepolia , arbitrum , gnosisChiado , gnosis , sepolia } from "wagmi/chains" ;
7
7
import { walletConnect } from "wagmi/connectors" ;
8
8
9
- import { ALL_CHAINS } from "consts/chains" ;
9
+ import { ALL_CHAINS , DEFAULT_CHAIN } from "consts/chains" ;
10
10
import { isProductionDeployment } from "consts/index" ;
11
11
12
12
import { lightTheme } from "styles/themes" ;
13
13
14
- const projectId = import . meta. env . WALLETCONNECT_PROJECT_ID ?? "" ;
15
- export const alchemyApiKey = import . meta . env . ALCHEMY_API_KEY ?? "" ;
14
+ const alchemyApiKey = import . meta. env . ALCHEMY_API_KEY ?? "" ;
15
+ const isProduction = isProductionDeployment ( ) ;
16
16
17
- const chains = ALL_CHAINS as [ Chain , ...Chain [ ] ] ;
17
+ // https://github.com/alchemyplatform/alchemy-sdk-js/blob/96b3f62/src/types/types.ts#L98-L119
18
+ const alchemyToViemChain = {
19
+ [ arbitrum . id ] : "arb-mainnet" ,
20
+ [ arbitrumSepolia . id ] : "arb-sepolia" ,
21
+ [ mainnet . id ] : "eth-mainnet" ,
22
+ [ sepolia . id ] : "eth-sepolia" ,
23
+ } ;
18
24
19
- type AlchemyProtocol = "https" | "wss" ;
20
- type AlchemyChain = "arb-sepolia" | "eth-mainnet" | "arb" ;
21
- const alchemyURL = ( protocol : AlchemyProtocol , chain : AlchemyChain ) =>
22
- `${ protocol } ://${ chain } .g.alchemy.com/v2/${ alchemyApiKey } ` ;
23
- const alchemyTransport = ( chain : AlchemyChain ) =>
24
- fallback ( [ webSocket ( alchemyURL ( "wss" , chain ) ) , http ( alchemyURL ( "https" , chain ) ) ] ) ;
25
-
26
- const transports = {
27
- [ isProductionDeployment ( ) ? arbitrum . id : arbitrumSepolia . id ] : isProductionDeployment ( )
28
- ? alchemyTransport ( "arb" )
29
- : alchemyTransport ( "arb-sepolia" ) ,
30
- [ mainnet . id ] : alchemyTransport ( "eth-mainnet" ) ,
31
- [ gnosisChiado . id ] : fallback ( [ webSocket ( "wss://rpc.chiadochain.net/wss" ) , http ( "https://rpc.chiadochain.net" ) ] ) ,
25
+ // https://github.com/alchemyplatform/alchemy-sdk-js/blob/96b3f62/src/util/const.ts#L16-L18
26
+ const alchemyURL = ( protocol : "https" | "wss" , chainId : number ) =>
27
+ `${ protocol } ://${ alchemyToViemChain [ chainId ] } .g.alchemy.com/v2/${ alchemyApiKey } ` ;
28
+
29
+ export const getDefaultChainRpcUrl = ( protocol : "https" | "wss" ) => {
30
+ return alchemyURL ( protocol , DEFAULT_CHAIN ) ;
32
31
} ;
33
32
33
+ export const getTransports = ( ) => {
34
+ const alchemyTransport = ( chain : Chain ) =>
35
+ fallback ( [ http ( alchemyURL ( "https" , chain . id ) ) , webSocket ( alchemyURL ( "wss" , chain . id ) ) ] ) ;
36
+ const defaultTransport = ( chain : Chain ) =>
37
+ fallback ( [ http ( chain . rpcUrls . default ?. http ?. [ 0 ] ) , webSocket ( chain . rpcUrls . default ?. webSocket ?. [ 0 ] ) ] ) ;
38
+
39
+ return {
40
+ [ isProduction ? arbitrum . id : arbitrumSepolia . id ] : isProduction
41
+ ? alchemyTransport ( arbitrum )
42
+ : alchemyTransport ( arbitrumSepolia ) ,
43
+ [ isProduction ? gnosis . id : gnosisChiado . id ] : isProduction
44
+ ? defaultTransport ( gnosis )
45
+ : defaultTransport ( gnosisChiado ) ,
46
+ [ mainnet . id ] : alchemyTransport ( mainnet ) , // Always enabled for ENS resolution
47
+ } ;
48
+ } ;
49
+
50
+ const chains = ALL_CHAINS as [ Chain , ...Chain [ ] ] ;
51
+ const transports = getTransports ( ) ;
52
+ const projectId = import . meta. env . WALLETCONNECT_PROJECT_ID ?? "" ;
34
53
const wagmiConfig = createConfig ( {
35
54
chains,
36
55
transports,
0 commit comments