diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c3d4e9343..63d58a728 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,11 +10,9 @@ Before developing locally, you'll need install the project's dependencies and cr The `.env` file specifies third-party APIs for use in e2e testing and the cosmos viewer: - `JSON_RPC_PROVIDER` must be specified for e2e tests to work. -- `INFURA_KEY` must be specified to use a network provider in the cosmos viewer. ``` JSON_RPC_PROVIDER='` -INFURA_KEY='' ``` ## Running widgets locally diff --git a/src/cosmos/ControlledSwap.fixture.tsx b/src/cosmos/ControlledSwap.fixture.tsx index 2a6660437..c1fdfe3b2 100644 --- a/src/cosmos/ControlledSwap.fixture.tsx +++ b/src/cosmos/ControlledSwap.fixture.tsx @@ -7,7 +7,7 @@ import { useCallback, useMemo, useState } from 'react' import { DAI, nativeOnChain, USDC } from '../constants/tokens' import EventFeed, { Event, HANDLERS } from './EventFeed' import useOption from './useOption' -import useProvider, { INFURA_NETWORK_URLS } from './useProvider' +import useProvider from './useProvider' function Fixture() { const [events, setEvents] = useState([]) @@ -64,7 +64,6 @@ function Fixture() { [Field.INPUT]: inputToken, [Field.OUTPUT]: outputToken, }} - jsonRpcUrlMap={INFURA_NETWORK_URLS} provider={connector} tokenList={tokens} {...eventHandlers} diff --git a/src/cosmos/Swap.fixture.tsx b/src/cosmos/Swap.fixture.tsx index fed2b1f85..37b5e0a40 100644 --- a/src/cosmos/Swap.fixture.tsx +++ b/src/cosmos/Swap.fixture.tsx @@ -17,7 +17,7 @@ import { useValue } from 'react-cosmos/fixture' import { DAI, USDC_MAINNET } from '../constants/tokens' import EventFeed, { Event, HANDLERS } from './EventFeed' import useOption from './useOption' -import useProvider, { INFURA_NETWORK_URLS } from './useProvider' +import useProvider from './useProvider' const TOKEN_WITH_NO_LOGO = { chainId: 1, @@ -103,7 +103,6 @@ function Fixture() { defaultOutputAmount={defaultOutputAmount} hideConnectionUI={hideConnectionUI} locale={locale} - jsonRpcUrlMap={INFURA_NETWORK_URLS} defaultChainId={defaultChainId} provider={connector} theme={theme} diff --git a/src/cosmos/useProvider.ts b/src/cosmos/useProvider.ts index 2e7b09a01..b4c86ffa1 100644 --- a/src/cosmos/useProvider.ts +++ b/src/cosmos/useProvider.ts @@ -2,32 +2,11 @@ import { initializeConnector } from '@web3-react/core' import { MetaMask } from '@web3-react/metamask' import { Connector } from '@web3-react/types' import { WalletConnect } from '@web3-react/walletconnect' -import { SupportedChainId } from 'constants/chains' +import { JSON_RPC_FALLBACK_ENDPOINTS } from 'constants/jsonRpcEndpoints' import { useEffect, useState } from 'react' import useOption from './useOption' -const INFURA_KEY = process.env.INFURA_KEY -if (INFURA_KEY === undefined) { - console.error(`INFURA_KEY must be a defined environment variable to use jsonRpcUrlMap in the cosmos viewer`) -} - -export const INFURA_NETWORK_URLS: { [chainId: number]: string[] } = INFURA_KEY - ? { - [SupportedChainId.MAINNET]: [`https://mainnet.infura.io/v3/${INFURA_KEY}`], - [SupportedChainId.RINKEBY]: [`https://rinkeby.infura.io/v3/${INFURA_KEY}`], - [SupportedChainId.ROPSTEN]: [`https://ropsten.infura.io/v3/${INFURA_KEY}`], - [SupportedChainId.GOERLI]: [`https://goerli.infura.io/v3/${INFURA_KEY}`], - [SupportedChainId.KOVAN]: [`https://kovan.infura.io/v3/${INFURA_KEY}`], - [SupportedChainId.OPTIMISM]: [`https://optimism-mainnet.infura.io/v3/${INFURA_KEY}`], - [SupportedChainId.OPTIMISTIC_KOVAN]: [`https://optimism-kovan.infura.io/v3/${INFURA_KEY}`], - [SupportedChainId.ARBITRUM_ONE]: [`https://arbitrum-mainnet.infura.io/v3/${INFURA_KEY}`], - [SupportedChainId.ARBITRUM_RINKEBY]: [`https://arbitrum-rinkeby.infura.io/v3/${INFURA_KEY}`], - [SupportedChainId.POLYGON]: [`https://polygon-mainnet.infura.io/v3/${INFURA_KEY}`], - [SupportedChainId.POLYGON_MUMBAI]: [`https://polygon-mumbai.infura.io/v3/${INFURA_KEY}`], - } - : {} - enum Wallet { MetaMask = 'MetaMask', WalletConnect = 'WalletConnect', @@ -38,7 +17,10 @@ const [walletConnect] = initializeConnector( new WalletConnect({ actions, options: { - rpc: INFURA_NETWORK_URLS as { [chainId: number]: string[] }, + rpc: Object.entries(JSON_RPC_FALLBACK_ENDPOINTS).reduce((rpcMap, [chainId, rpcUrls]) => ({ + ...rpcMap, + [chainId]: rpcUrls.slice(0, 1), + })), }, }) ) diff --git a/webpack.cosmos.js b/webpack.cosmos.js index 49b6dfccb..c62fefb5b 100644 --- a/webpack.cosmos.js +++ b/webpack.cosmos.js @@ -1,5 +1,4 @@ /* eslint-disable @typescript-eslint/no-var-requires */ -const { DefinePlugin } = require('webpack') const EventEmitter = require('events') const HtmlWebpackPlugin = require('html-webpack-plugin') const rollup = require('rollup') @@ -78,7 +77,6 @@ module.exports = (webpackConfig) => { }, plugins: [ new RollupPlugin({ config: rollupConfig, assetConfigs, watch: mode !== 'production' }), - new DefinePlugin({ 'process.env.INFURA_KEY': JSON.stringify(process.env.INFURA_KEY) }), new HtmlWebpackPlugin(), ], stats: 'errors-warnings',