Commit af6098bf authored by Moody Salem's avatar Moody Salem Committed by GitHub

feat: allow walletconnect on testnets (#1389)

* try walletconnect multinetwork

* clean up environment variables for multinetwork

* remove irrelevant config

* move some stuff around
Co-authored-by: default avatarNoah Zinsmeister <noahwz@gmail.com>
parent fce29bb3
REACT_APP_CHAIN_ID="1" REACT_APP_INFURA_KEY="4bf032f2d38a4ed6bb975b80d6340847"
REACT_APP_NETWORK_URL="https://mainnet.infura.io/v3/4bf032f2d38a4ed6bb975b80d6340847"
REACT_APP_WALLETCONNECT_BRIDGE_URL="https://uniswap.bridge.walletconnect.org" REACT_APP_WALLETCONNECT_BRIDGE_URL="https://uniswap.bridge.walletconnect.org"
# Because we use storybook which has its own babel-loader dependency @ 8.2.2, where react-scripts uses 8.1.0 # Because we use storybook which has its own babel-loader dependency @ 8.2.2, where react-scripts uses 8.1.0
SKIP_PREFLIGHT_CHECK=true SKIP_PREFLIGHT_CHECK=true
\ No newline at end of file
REACT_APP_CHAIN_ID="1" REACT_APP_INFURA_KEY="099fc58e0de9451d80b18d7c74caa7c1"
REACT_APP_NETWORK_URL="https://mainnet.infura.io/v3/099fc58e0de9451d80b18d7c74caa7c1"
REACT_APP_PORTIS_ID="c0e2bf01-4b08-4fd5-ac7b-8e26b58cd236" REACT_APP_PORTIS_ID="c0e2bf01-4b08-4fd5-ac7b-8e26b58cd236"
REACT_APP_FORTMATIC_KEY="pk_live_F937DF033A1666BF" REACT_APP_FORTMATIC_KEY="pk_live_F937DF033A1666BF"
REACT_APP_GOOGLE_ANALYTICS_ID="UA-128182339-4" REACT_APP_GOOGLE_ANALYTICS_ID="UA-128182339-4"
...@@ -27,7 +27,7 @@ or visit [app.uniswap.org](https://app.uniswap.org). ...@@ -27,7 +27,7 @@ or visit [app.uniswap.org](https://app.uniswap.org).
### Install Dependencies ### Install Dependencies
```bash ```bash
yarn yarn install
``` ```
### Run ### Run
...@@ -36,19 +36,6 @@ yarn ...@@ -36,19 +36,6 @@ yarn
yarn start yarn start
``` ```
### Configuring the environment (optional)
To have the interface default to a different network when a wallet is not connected:
1. Make a copy of `.env` named `.env.local`
2. Change `REACT_APP_NETWORK_ID` to `"{YOUR_NETWORK_ID}"`
3. Change `REACT_APP_NETWORK_URL` to e.g. `"https://{YOUR_NETWORK_ID}.infura.io/v3/{YOUR_INFURA_KEY}"`
Note that the interface only works on testnets where both
[Uniswap V2](https://uniswap.org/docs/v2/smart-contracts/factory/) and
[multicall](https://github.com/makerdao/multicall) are deployed.
The interface will not work on other networks.
## Contributions ## Contributions
**Please open all pull requests against the `main` branch.** **Please open all pull requests against the `main` branch.**
......
import { Web3Provider } from '@ethersproject/providers' import { Web3Provider } from '@ethersproject/providers'
import { ChainId } from '@uniswap/sdk-core'
import { InjectedConnector } from '@web3-react/injected-connector' import { InjectedConnector } from '@web3-react/injected-connector'
import { WalletConnectConnector } from '@web3-react/walletconnect-connector' import { WalletConnectConnector } from '@web3-react/walletconnect-connector'
import { WalletLinkConnector } from '@web3-react/walletlink-connector' import { WalletLinkConnector } from '@web3-react/walletlink-connector'
import { PortisConnector } from '@web3-react/portis-connector' import { PortisConnector } from '@web3-react/portis-connector'
import getLibrary from '../utils/getLibrary'
import { FortmaticConnector } from './Fortmatic' import { FortmaticConnector } from './Fortmatic'
import { NetworkConnector } from './NetworkConnector' import { NetworkConnector } from './NetworkConnector'
import UNISWAP_LOGO_URL from '../assets/svg/logo.svg' import UNISWAP_LOGO_URL from '../assets/svg/logo.svg'
const NETWORK_URL = process.env.REACT_APP_NETWORK_URL const INFURA_KEY = process.env.REACT_APP_INFURA_KEY
const FORMATIC_KEY = process.env.REACT_APP_FORTMATIC_KEY const FORMATIC_KEY = process.env.REACT_APP_FORTMATIC_KEY
const PORTIS_ID = process.env.REACT_APP_PORTIS_ID const PORTIS_ID = process.env.REACT_APP_PORTIS_ID
const WALLETCONNECT_BRIDGE_URL = process.env.REACT_APP_WALLETCONNECT_BRIDGE_URL const WALLETCONNECT_BRIDGE_URL = process.env.REACT_APP_WALLETCONNECT_BRIDGE_URL
export const NETWORK_CHAIN_ID: number = parseInt(process.env.REACT_APP_CHAIN_ID ?? '1') if (typeof INFURA_KEY === 'undefined') {
throw new Error(`REACT_APP_INFURA_KEY must be a defined environment variable`)
}
if (typeof NETWORK_URL === 'undefined') { const NETWORK_URLS: {
throw new Error(`REACT_APP_NETWORK_URL must be a defined environment variable`) [chainId in ChainId]: string
} = {
[ChainId.MAINNET]: `https://mainnet.infura.io/v3/${INFURA_KEY}`,
[ChainId.RINKEBY]: `https://rinkeby.infura.io/v3/${INFURA_KEY}`,
[ChainId.ROPSTEN]: `https://ropsten.infura.io/v3/${INFURA_KEY}`,
[ChainId.GÖRLI]: `https://goerli.infura.io/v3/${INFURA_KEY}`,
[ChainId.KOVAN]: `https://kovan.infura.io/v3/${INFURA_KEY}`,
} }
const SUPPORTED_CHAIN_IDS = [ChainId.MAINNET, ChainId.RINKEBY, ChainId.ROPSTEN, ChainId.KOVAN, ChainId.GÖRLI]
export const network = new NetworkConnector({ export const network = new NetworkConnector({
urls: { [NETWORK_CHAIN_ID]: NETWORK_URL }, urls: NETWORK_URLS,
defaultChainId: ChainId.MAINNET,
}) })
let networkLibrary: Web3Provider | undefined let networkLibrary: Web3Provider | undefined
export function getNetworkLibrary(): Web3Provider { export function getNetworkLibrary(): Web3Provider {
return (networkLibrary = networkLibrary ?? new Web3Provider(network.provider as any)) return (networkLibrary = networkLibrary ?? getLibrary(network.provider))
} }
export const injected = new InjectedConnector({ export const injected = new InjectedConnector({
supportedChainIds: [1, 3, 4, 5, 42], supportedChainIds: SUPPORTED_CHAIN_IDS,
}) })
// mainnet only
export const walletconnect = new WalletConnectConnector({ export const walletconnect = new WalletConnectConnector({
rpc: { 1: NETWORK_URL }, supportedChainIds: SUPPORTED_CHAIN_IDS,
infuraId: INFURA_KEY, // obviously a hack
bridge: WALLETCONNECT_BRIDGE_URL, bridge: WALLETCONNECT_BRIDGE_URL,
qrcode: true, qrcode: true,
pollingInterval: 15000, pollingInterval: 15000,
...@@ -54,7 +67,7 @@ export const portis = new PortisConnector({ ...@@ -54,7 +67,7 @@ export const portis = new PortisConnector({
// mainnet only // mainnet only
export const walletlink = new WalletLinkConnector({ export const walletlink = new WalletLinkConnector({
url: NETWORK_URL, url: NETWORK_URLS[ChainId.MAINNET],
appName: 'Uniswap', appName: 'Uniswap',
appLogoUrl: UNISWAP_LOGO_URL, appLogoUrl: UNISWAP_LOGO_URL,
}) })
...@@ -3,7 +3,7 @@ import { ChainId } from '@uniswap/sdk-core' ...@@ -3,7 +3,7 @@ import { ChainId } from '@uniswap/sdk-core'
import { TokenList } from '@uniswap/token-lists' import { TokenList } from '@uniswap/token-lists'
import { useCallback } from 'react' import { useCallback } from 'react'
import { useDispatch } from 'react-redux' import { useDispatch } from 'react-redux'
import { getNetworkLibrary, NETWORK_CHAIN_ID } from '../connectors' import { getNetworkLibrary } from '../connectors'
import { AppDispatch } from '../state' import { AppDispatch } from '../state'
import { fetchTokenList } from '../state/lists/actions' import { fetchTokenList } from '../state/lists/actions'
import getTokenList from '../utils/getTokenList' import getTokenList from '../utils/getTokenList'
...@@ -15,13 +15,12 @@ export function useFetchListCallback(): (listUrl: string, sendDispatch?: boolean ...@@ -15,13 +15,12 @@ export function useFetchListCallback(): (listUrl: string, sendDispatch?: boolean
const dispatch = useDispatch<AppDispatch>() const dispatch = useDispatch<AppDispatch>()
const ensResolver = useCallback( const ensResolver = useCallback(
(ensName: string) => { async (ensName: string) => {
if (!library || chainId !== ChainId.MAINNET) { if (!library || chainId !== ChainId.MAINNET) {
if (NETWORK_CHAIN_ID === ChainId.MAINNET) { const networkLibrary = getNetworkLibrary()
const networkLibrary = getNetworkLibrary() const network = await networkLibrary.getNetwork()
if (networkLibrary) { if (networkLibrary && network.chainId === ChainId.MAINNET) {
return resolveENSContentHash(ensName, networkLibrary) return resolveENSContentHash(ensName, networkLibrary)
}
} }
throw new Error('Could not construct mainnet ENS resolver') throw new Error('Could not construct mainnet ENS resolver')
} }
......
...@@ -4582,7 +4582,7 @@ ...@@ -4582,7 +4582,7 @@
js-sha3 "0.8.0" js-sha3 "0.8.0"
query-string "6.13.5" query-string "6.13.5"
"@walletconnect/web3-provider@^1.3.6": "@walletconnect/web3-provider@^1.4.1":
version "1.4.1" version "1.4.1"
resolved "https://registry.yarnpkg.com/@walletconnect/web3-provider/-/web3-provider-1.4.1.tgz#34f6319ab2473ab9ff0fcf1e8bc280c697fa01ff" resolved "https://registry.yarnpkg.com/@walletconnect/web3-provider/-/web3-provider-1.4.1.tgz#34f6319ab2473ab9ff0fcf1e8bc280c697fa01ff"
integrity sha512-gUoBGM5hdtcXSoLXDTG1/WTamnUNpEWfaYMIVkfVnvVFd4whIjb0iOW5ywvDOf/49wq0C2+QThZL2Wc+r+jKLA== integrity sha512-gUoBGM5hdtcXSoLXDTG1/WTamnUNpEWfaYMIVkfVnvVFd4whIjb0iOW5ywvDOf/49wq0C2+QThZL2Wc+r+jKLA==
...@@ -4646,12 +4646,12 @@ ...@@ -4646,12 +4646,12 @@
resolved "https://registry.yarnpkg.com/@web3-react/types/-/types-6.0.7.tgz#34a6204224467eedc6123abaf55fbb6baeb2809f" resolved "https://registry.yarnpkg.com/@web3-react/types/-/types-6.0.7.tgz#34a6204224467eedc6123abaf55fbb6baeb2809f"
integrity sha512-ofGmfDhxmNT1/P/MgVa8IKSkCStFiyvXe+U5tyZurKdrtTDFU+wJ/LxClPDtFerWpczNFPUSrKcuhfPX1sI6+A== integrity sha512-ofGmfDhxmNT1/P/MgVa8IKSkCStFiyvXe+U5tyZurKdrtTDFU+wJ/LxClPDtFerWpczNFPUSrKcuhfPX1sI6+A==
"@web3-react/walletconnect-connector@^6.1.1": "@web3-react/walletconnect-connector@^6.2.0":
version "6.1.9" version "6.2.0"
resolved "https://registry.yarnpkg.com/@web3-react/walletconnect-connector/-/walletconnect-connector-6.1.9.tgz#3459ccf2a2ac7ae8f155645d29a517712afeb731" resolved "https://registry.yarnpkg.com/@web3-react/walletconnect-connector/-/walletconnect-connector-6.2.0.tgz#5451f332a25b94cf7e615a20cc7d22a27532629d"
integrity sha512-gPtcFFRAnRgqhmBjhH+dtuG3cx23X+JOX+mRO1D7dN+8yxLZhLhjOZlJFECH5hkC20KMM/sk+rq2yy6Vqp76PQ== integrity sha512-F6xYwI3MKiSdKa0248y2wBW0kTDddc2/IGn4CjMSYe0DJFggtxFsAAGHQTRmvwDcLlgQwtemJJ0cTA82MOVfEg==
dependencies: dependencies:
"@walletconnect/web3-provider" "^1.3.6" "@walletconnect/web3-provider" "^1.4.1"
"@web3-react/abstract-connector" "^6.0.7" "@web3-react/abstract-connector" "^6.0.7"
"@web3-react/types" "^6.0.7" "@web3-react/types" "^6.0.7"
tiny-invariant "^1.0.6" tiny-invariant "^1.0.6"
......
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