fix: use static rpc urls (#4599)
This commit is contained in:
parent
b74fb8174d
commit
09b00c9974
@ -8,7 +8,7 @@ import { WalletConnect } from '@web3-react/walletconnect'
|
||||
import { SupportedChainId } from 'constants/chains'
|
||||
|
||||
import UNISWAP_LOGO_URL from '../assets/svg/logo.svg'
|
||||
import { RPC_URLS } from '../constants/networks'
|
||||
import { RPC_PROVIDERS, RPC_URLS } from '../constants/networks'
|
||||
|
||||
export enum ConnectionType {
|
||||
INJECTED = 'INJECTED',
|
||||
@ -29,7 +29,7 @@ function onError(error: Error) {
|
||||
}
|
||||
|
||||
const [web3Network, web3NetworkHooks] = initializeConnector<Network>(
|
||||
(actions) => new Network({ actions, urlMap: RPC_URLS, defaultChainId: 1 })
|
||||
(actions) => new Network({ actions, urlMap: RPC_PROVIDERS, defaultChainId: 1 })
|
||||
)
|
||||
export const networkConnection: Connection = {
|
||||
connector: web3Network,
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { JsonRpcProvider } from '@ethersproject/providers'
|
||||
import { StaticJsonRpcProvider } from '@ethersproject/providers'
|
||||
|
||||
import { SupportedChainId } from './chains'
|
||||
|
||||
@ -7,8 +7,6 @@ if (typeof INFURA_KEY === 'undefined') {
|
||||
throw new Error(`REACT_APP_INFURA_KEY must be a defined environment variable`)
|
||||
}
|
||||
|
||||
export const MAINNET_PROVIDER = new JsonRpcProvider(`https://mainnet.infura.io/v3/${INFURA_KEY}`)
|
||||
|
||||
/**
|
||||
* These are the network URLs used by the interface when there is not another available source of chain data
|
||||
*/
|
||||
@ -27,3 +25,19 @@ export const RPC_URLS: { [key in SupportedChainId]: string } = {
|
||||
[SupportedChainId.CELO]: `https://forno.celo.org`,
|
||||
[SupportedChainId.CELO_ALFAJORES]: `https://alfajores-forno.celo-testnet.org`,
|
||||
}
|
||||
|
||||
export const RPC_PROVIDERS: { [key in SupportedChainId]: StaticJsonRpcProvider } = {
|
||||
[SupportedChainId.MAINNET]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.MAINNET]),
|
||||
[SupportedChainId.RINKEBY]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.RINKEBY]),
|
||||
[SupportedChainId.ROPSTEN]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.ROPSTEN]),
|
||||
[SupportedChainId.GOERLI]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.GOERLI]),
|
||||
[SupportedChainId.KOVAN]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.KOVAN]),
|
||||
[SupportedChainId.OPTIMISM]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.OPTIMISM]),
|
||||
[SupportedChainId.OPTIMISTIC_KOVAN]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.OPTIMISTIC_KOVAN]),
|
||||
[SupportedChainId.ARBITRUM_ONE]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.ARBITRUM_ONE]),
|
||||
[SupportedChainId.ARBITRUM_RINKEBY]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.ARBITRUM_RINKEBY]),
|
||||
[SupportedChainId.POLYGON]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.POLYGON]),
|
||||
[SupportedChainId.POLYGON_MUMBAI]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.POLYGON_MUMBAI]),
|
||||
[SupportedChainId.CELO]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.CELO]),
|
||||
[SupportedChainId.CELO_ALFAJORES]: new StaticJsonRpcProvider(RPC_URLS[SupportedChainId.CELO_ALFAJORES]),
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { nanoid } from '@reduxjs/toolkit'
|
||||
import { TokenList } from '@uniswap/token-lists'
|
||||
import { MAINNET_PROVIDER } from 'constants/networks'
|
||||
import { SupportedChainId } from 'constants/chains'
|
||||
import { RPC_PROVIDERS } from 'constants/networks'
|
||||
import getTokenList from 'lib/hooks/useTokenList/fetchTokenList'
|
||||
import resolveENSContentHash from 'lib/utils/resolveENSContentHash'
|
||||
import { useCallback } from 'react'
|
||||
@ -16,7 +17,9 @@ export function useFetchListCallback(): (listUrl: string, sendDispatch?: boolean
|
||||
async (listUrl: string, sendDispatch = true) => {
|
||||
const requestId = nanoid()
|
||||
sendDispatch && dispatch(fetchTokenList.pending({ requestId, url: listUrl }))
|
||||
return getTokenList(listUrl, (ensName: string) => resolveENSContentHash(ensName, MAINNET_PROVIDER))
|
||||
return getTokenList(listUrl, (ensName: string) =>
|
||||
resolveENSContentHash(ensName, RPC_PROVIDERS[SupportedChainId.MAINNET])
|
||||
)
|
||||
.then((tokenList) => {
|
||||
sendDispatch && dispatch(fetchTokenList.fulfilled({ url: listUrl, tokenList, requestId }))
|
||||
return tokenList
|
||||
|
@ -59,7 +59,6 @@ export function BlockNumberProvider({ children }: { children: ReactNode }) {
|
||||
})
|
||||
|
||||
provider.on('block', onBlock)
|
||||
|
||||
return () => {
|
||||
stale = true
|
||||
provider.removeListener('block', onBlock)
|
||||
@ -69,11 +68,7 @@ export function BlockNumberProvider({ children }: { children: ReactNode }) {
|
||||
return void 0
|
||||
}, [activeChainId, provider, onBlock, setChainBlock, windowVisible])
|
||||
|
||||
const value = useMemo(
|
||||
() => ({
|
||||
value: chainId === activeChainId ? block : undefined,
|
||||
}),
|
||||
[activeChainId, block, chainId]
|
||||
)
|
||||
const blockValue = useMemo(() => (chainId === activeChainId ? block : undefined), [activeChainId, block, chainId])
|
||||
const value = useMemo(() => ({ value: blockValue }), [blockValue])
|
||||
return <BlockNumberContext.Provider value={value}>{children}</BlockNumberContext.Provider>
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
import { JsonRpcProvider } from '@ethersproject/providers'
|
||||
import { createApi, fetchBaseQuery, FetchBaseQueryError } from '@reduxjs/toolkit/query/react'
|
||||
import { Protocol } from '@uniswap/router-sdk'
|
||||
import { AlphaRouter, ChainId } from '@uniswap/smart-order-router'
|
||||
import { RPC_URLS } from 'constants/networks'
|
||||
import { RPC_PROVIDERS } from 'constants/networks'
|
||||
import { getClientSideQuote, toSupportedChainId } from 'lib/hooks/routing/clientSideSmartOrderRouter'
|
||||
import ms from 'ms.macro'
|
||||
import qs from 'qs'
|
||||
@ -22,7 +21,7 @@ function getRouter(chainId: ChainId): AlphaRouter {
|
||||
|
||||
const supportedChainId = toSupportedChainId(chainId)
|
||||
if (supportedChainId) {
|
||||
const provider = new JsonRpcProvider(RPC_URLS[supportedChainId])
|
||||
const provider = RPC_PROVIDERS[supportedChainId]
|
||||
const router = new AlphaRouter({ chainId, provider })
|
||||
routers.set(chainId, router)
|
||||
return router
|
||||
|
Loading…
Reference in New Issue
Block a user