|
1 | | -import { useEffect } from 'react' |
| 1 | +import { useEffect, useMemo } from 'react' |
2 | 2 | import { QueryClient, QueryClientProvider } from 'react-query' |
3 | 3 | import { Provider } from 'react-redux' |
4 | 4 |
|
@@ -116,45 +116,54 @@ const App = ({ |
116 | 116 |
|
117 | 117 | // Customize chains config for Gnosis and Ethereum |
118 | 118 | // using rpc urls from props |
119 | | - const CustomChainsConfig = { |
120 | | - // Keep Goerli as testnet else an error will arise at init |
121 | | - [ChainsID.Goerli]: RealtCommonsDefaultChainsConfig[ChainsID.Goerli], |
122 | | - [ChainsID.Gnosis]: { |
123 | | - ...RealtCommonsDefaultChainsConfig[ChainsID.Gnosis], |
124 | | - rpcUrl: |
125 | | - GnosisRpcUrl || RealtCommonsDefaultChainsConfig[ChainsID.Gnosis].rpcUrl, |
126 | | - }, |
127 | | - [ChainsID.Ethereum]: { |
128 | | - ...RealtCommonsDefaultChainsConfig[ChainsID.Ethereum], |
129 | | - rpcUrl: |
130 | | - EthereumRpcUrl || |
131 | | - RealtCommonsDefaultChainsConfig[ChainsID.Ethereum].rpcUrl, |
132 | | - }, |
133 | | - // TODO: add Polygon |
134 | | - } |
| 119 | + const CustomChainsConfig = useMemo( |
| 120 | + () => ({ |
| 121 | + // Keep Goerli as testnet else an error will arise at init |
| 122 | + [ChainsID.Goerli]: RealtCommonsDefaultChainsConfig[ChainsID.Goerli], |
| 123 | + [ChainsID.Gnosis]: { |
| 124 | + ...RealtCommonsDefaultChainsConfig[ChainsID.Gnosis], |
| 125 | + rpcUrl: |
| 126 | + GnosisRpcUrl || |
| 127 | + RealtCommonsDefaultChainsConfig[ChainsID.Gnosis].rpcUrl, |
| 128 | + }, |
| 129 | + [ChainsID.Ethereum]: { |
| 130 | + ...RealtCommonsDefaultChainsConfig[ChainsID.Ethereum], |
| 131 | + rpcUrl: |
| 132 | + EthereumRpcUrl || |
| 133 | + RealtCommonsDefaultChainsConfig[ChainsID.Ethereum].rpcUrl, |
| 134 | + }, |
| 135 | + // TODO: add Polygon |
| 136 | + }), |
| 137 | + [GnosisRpcUrl, EthereumRpcUrl], |
| 138 | + ) |
135 | 139 |
|
136 | | - const dashbordChains: ChainSelectConfig<RealtChains> = { |
137 | | - allowedChains: parseAllowedChain(ChainsID), |
138 | | - chainsConfig: CustomChainsConfig, |
139 | | - defaultChainId: ChainsID.Gnosis, // Explicitly setting Gnosis as the defaultChainId |
140 | | - } |
| 140 | + const dashbordChains: ChainSelectConfig<RealtChains> = useMemo( |
| 141 | + () => ({ |
| 142 | + allowedChains: parseAllowedChain(ChainsID), |
| 143 | + chainsConfig: CustomChainsConfig, |
| 144 | + defaultChainId: ChainsID.Gnosis, // Explicitly setting Gnosis as the defaultChainId |
| 145 | + }), |
| 146 | + [CustomChainsConfig], |
| 147 | + ) |
141 | 148 |
|
142 | 149 | const envName = process.env.NEXT_PUBLIC_ENV ?? 'development' |
143 | 150 | const walletConnectKey = process.env.NEXT_PUBLIC_WALLET_CONNECT_KEY ?? '' |
144 | 151 |
|
145 | | - const readOnly = getReadOnlyConnector(dashbordChains) |
146 | | - const walletConnect = getWalletConnectV2( |
147 | | - dashbordChains, |
148 | | - envName, |
149 | | - walletConnectKey, |
150 | | - false, |
151 | | - ) |
152 | | - |
153 | | - const libraryConnectors = getConnectors({ |
154 | | - readOnly: readOnly, |
155 | | - metamask: [metaMask, metaMaskHooks], |
156 | | - walletConnectV2: walletConnect, |
157 | | - } as unknown as ConnectorsAvailable) |
| 152 | + const libraryConnectors = useMemo(() => { |
| 153 | + const readOnly = getReadOnlyConnector(dashbordChains) |
| 154 | + const walletConnect = getWalletConnectV2( |
| 155 | + dashbordChains, |
| 156 | + envName, |
| 157 | + walletConnectKey, |
| 158 | + false, |
| 159 | + ) |
| 160 | + |
| 161 | + return getConnectors({ |
| 162 | + readOnly: readOnly, |
| 163 | + metamask: [metaMask, metaMaskHooks], |
| 164 | + walletConnectV2: walletConnect, |
| 165 | + } as unknown as ConnectorsAvailable) |
| 166 | + }, [dashbordChains, envName, walletConnectKey]) |
158 | 167 |
|
159 | 168 | return ( |
160 | 169 | <QueryClientProvider client={queryClient}> |
|
0 commit comments