Commit 09b00c99 authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

fix: use static rpc urls (#4599)

parent b74fb817
...@@ -8,7 +8,7 @@ import { WalletConnect } from '@web3-react/walletconnect' ...@@ -8,7 +8,7 @@ import { WalletConnect } from '@web3-react/walletconnect'
import { SupportedChainId } from 'constants/chains' import { SupportedChainId } from 'constants/chains'
import UNISWAP_LOGO_URL from '../assets/svg/logo.svg' 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 { export enum ConnectionType {
INJECTED = 'INJECTED', INJECTED = 'INJECTED',
...@@ -29,7 +29,7 @@ function onError(error: Error) { ...@@ -29,7 +29,7 @@ function onError(error: Error) {
} }
const [web3Network, web3NetworkHooks] = initializeConnector<Network>( 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 = { export const networkConnection: Connection = {
connector: web3Network, connector: web3Network,
......
import { JsonRpcProvider } from '@ethersproject/providers' import { StaticJsonRpcProvider } from '@ethersproject/providers'
import { SupportedChainId } from './chains' import { SupportedChainId } from './chains'
...@@ -7,8 +7,6 @@ if (typeof INFURA_KEY === 'undefined') { ...@@ -7,8 +7,6 @@ if (typeof INFURA_KEY === 'undefined') {
throw new Error(`REACT_APP_INFURA_KEY must be a defined environment variable`) 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 * 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 } = { ...@@ -27,3 +25,19 @@ export const RPC_URLS: { [key in SupportedChainId]: string } = {
[SupportedChainId.CELO]: `https://forno.celo.org`, [SupportedChainId.CELO]: `https://forno.celo.org`,
[SupportedChainId.CELO_ALFAJORES]: `https://alfajores-forno.celo-testnet.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]),
}
import { nanoid } from '@reduxjs/toolkit' import { nanoid } from '@reduxjs/toolkit'
import { TokenList } from '@uniswap/token-lists' 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 getTokenList from 'lib/hooks/useTokenList/fetchTokenList'
import resolveENSContentHash from 'lib/utils/resolveENSContentHash' import resolveENSContentHash from 'lib/utils/resolveENSContentHash'
import { useCallback } from 'react' import { useCallback } from 'react'
...@@ -16,7 +17,9 @@ export function useFetchListCallback(): (listUrl: string, sendDispatch?: boolean ...@@ -16,7 +17,9 @@ export function useFetchListCallback(): (listUrl: string, sendDispatch?: boolean
async (listUrl: string, sendDispatch = true) => { async (listUrl: string, sendDispatch = true) => {
const requestId = nanoid() const requestId = nanoid()
sendDispatch && dispatch(fetchTokenList.pending({ requestId, url: listUrl })) 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) => { .then((tokenList) => {
sendDispatch && dispatch(fetchTokenList.fulfilled({ url: listUrl, tokenList, requestId })) sendDispatch && dispatch(fetchTokenList.fulfilled({ url: listUrl, tokenList, requestId }))
return tokenList return tokenList
......
...@@ -59,7 +59,6 @@ export function BlockNumberProvider({ children }: { children: ReactNode }) { ...@@ -59,7 +59,6 @@ export function BlockNumberProvider({ children }: { children: ReactNode }) {
}) })
provider.on('block', onBlock) provider.on('block', onBlock)
return () => { return () => {
stale = true stale = true
provider.removeListener('block', onBlock) provider.removeListener('block', onBlock)
...@@ -69,11 +68,7 @@ export function BlockNumberProvider({ children }: { children: ReactNode }) { ...@@ -69,11 +68,7 @@ export function BlockNumberProvider({ children }: { children: ReactNode }) {
return void 0 return void 0
}, [activeChainId, provider, onBlock, setChainBlock, windowVisible]) }, [activeChainId, provider, onBlock, setChainBlock, windowVisible])
const value = useMemo( const blockValue = useMemo(() => (chainId === activeChainId ? block : undefined), [activeChainId, block, chainId])
() => ({ const value = useMemo(() => ({ value: blockValue }), [blockValue])
value: chainId === activeChainId ? block : undefined,
}),
[activeChainId, block, chainId]
)
return <BlockNumberContext.Provider value={value}>{children}</BlockNumberContext.Provider> return <BlockNumberContext.Provider value={value}>{children}</BlockNumberContext.Provider>
} }
import { JsonRpcProvider } from '@ethersproject/providers'
import { createApi, fetchBaseQuery, FetchBaseQueryError } from '@reduxjs/toolkit/query/react' import { createApi, fetchBaseQuery, FetchBaseQueryError } from '@reduxjs/toolkit/query/react'
import { Protocol } from '@uniswap/router-sdk' import { Protocol } from '@uniswap/router-sdk'
import { AlphaRouter, ChainId } from '@uniswap/smart-order-router' 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 { getClientSideQuote, toSupportedChainId } from 'lib/hooks/routing/clientSideSmartOrderRouter'
import ms from 'ms.macro' import ms from 'ms.macro'
import qs from 'qs' import qs from 'qs'
...@@ -22,7 +21,7 @@ function getRouter(chainId: ChainId): AlphaRouter { ...@@ -22,7 +21,7 @@ function getRouter(chainId: ChainId): AlphaRouter {
const supportedChainId = toSupportedChainId(chainId) const supportedChainId = toSupportedChainId(chainId)
if (supportedChainId) { if (supportedChainId) {
const provider = new JsonRpcProvider(RPC_URLS[supportedChainId]) const provider = RPC_PROVIDERS[supportedChainId]
const router = new AlphaRouter({ chainId, provider }) const router = new AlphaRouter({ chainId, provider })
routers.set(chainId, router) routers.set(chainId, router)
return router return router
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment