Skip to content

Commit

Permalink
test: rm infura from test fixtures (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzmp authored Dec 7, 2022
1 parent 10d9a62 commit 96a6e6a
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 31 deletions.
2 changes: 0 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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='<JSON_RPC_PROVIDER>`
INFURA_KEY='<INFURA_KEY>'
```

## Running widgets locally
Expand Down
3 changes: 1 addition & 2 deletions src/cosmos/ControlledSwap.fixture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event[]>([])
Expand Down Expand Up @@ -64,7 +64,6 @@ function Fixture() {
[Field.INPUT]: inputToken,
[Field.OUTPUT]: outputToken,
}}
jsonRpcUrlMap={INFURA_NETWORK_URLS}
provider={connector}
tokenList={tokens}
{...eventHandlers}
Expand Down
3 changes: 1 addition & 2 deletions src/cosmos/Swap.fixture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -103,7 +103,6 @@ function Fixture() {
defaultOutputAmount={defaultOutputAmount}
hideConnectionUI={hideConnectionUI}
locale={locale}
jsonRpcUrlMap={INFURA_NETWORK_URLS}
defaultChainId={defaultChainId}
provider={connector}
theme={theme}
Expand Down
28 changes: 5 additions & 23 deletions src/cosmos/useProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -38,7 +17,10 @@ const [walletConnect] = initializeConnector<WalletConnect>(
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),
})),
},
})
)
Expand Down
2 changes: 0 additions & 2 deletions webpack.cosmos.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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',
Expand Down

1 comment on commit 96a6e6a

@vercel
Copy link

@vercel vercel bot commented on 96a6e6a Dec 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

widgets – ./

widgets-seven-tau.vercel.app
widgets-uniswap.vercel.app
widgets-git-main-uniswap.vercel.app

Please sign in to comment.