Commit 88600d3a authored by Moody Salem's avatar Moody Salem

refactor: clean up some constants

parent a1060d5f
...@@ -9,7 +9,7 @@ import { useModalOpen, useToggleModal } from 'state/application/hooks' ...@@ -9,7 +9,7 @@ import { useModalOpen, useToggleModal } from 'state/application/hooks'
import styled, { css } from 'styled-components/macro' import styled, { css } from 'styled-components/macro'
import { ExternalLink } from 'theme' import { ExternalLink } from 'theme'
import { switchToNetwork } from 'utils/switchToNetwork' import { switchToNetwork } from 'utils/switchToNetwork'
import { CHAIN_INFO, L2_CHAIN_IDS, NETWORK_LABELS, SupportedChainId, SupportedL2ChainId } from '../../constants/chains' import { CHAIN_INFO, L2_CHAIN_IDS, SupportedChainId, SupportedL2ChainId } from '../../constants/chains'
const BaseWrapper = css` const BaseWrapper = css`
position: relative; position: relative;
...@@ -181,7 +181,8 @@ export default function NetworkCard() { ...@@ -181,7 +181,8 @@ export default function NetworkCard() {
.catch(() => setImplements3085(false)) .catch(() => setImplements3085(false))
}, [library, chainId]) }, [library, chainId])
if (!chainId || chainId === SupportedChainId.MAINNET || !NETWORK_LABELS[chainId] || !library) { const info = chainId ? CHAIN_INFO[chainId] : undefined
if (!chainId || chainId === SupportedChainId.MAINNET || !info || !library) {
return null return null
} }
...@@ -229,5 +230,5 @@ export default function NetworkCard() { ...@@ -229,5 +230,5 @@ export default function NetworkCard() {
) )
} }
return <FallbackWrapper title={NETWORK_LABELS[chainId]}>{NETWORK_LABELS[chainId]}</FallbackWrapper> return <FallbackWrapper title={info.label}>{info.label}</FallbackWrapper>
} }
...@@ -5,7 +5,7 @@ import { ...@@ -5,7 +5,7 @@ import {
OptimismWrapperBackgroundDarkMode, OptimismWrapperBackgroundDarkMode,
OptimismWrapperBackgroundLightMode, OptimismWrapperBackgroundLightMode,
} from 'components/NetworkAlert/NetworkAlert' } from 'components/NetworkAlert/NetworkAlert'
import { CHAIN_INFO, L2_CHAIN_IDS, NETWORK_LABELS, SupportedChainId, SupportedL2ChainId } from 'constants/chains' import { CHAIN_INFO, L2_CHAIN_IDS, SupportedChainId, SupportedL2ChainId } from 'constants/chains'
import { useActiveWeb3React } from 'hooks/web3' import { useActiveWeb3React } from 'hooks/web3'
import { ArrowDownCircle } from 'react-feather' import { ArrowDownCircle } from 'react-feather'
import { useArbitrumAlphaAlert, useDarkModeManager } from 'state/user/hooks' import { useArbitrumAlphaAlert, useDarkModeManager } from 'state/user/hooks'
...@@ -116,11 +116,11 @@ export function AddLiquidityNetworkAlert() { ...@@ -116,11 +116,11 @@ export function AddLiquidityNetworkAlert() {
<Wrapper darkMode={darkMode} chainId={chainId} logoUrl={info.logoUrl}> <Wrapper darkMode={darkMode} chainId={chainId} logoUrl={info.logoUrl}>
<L2Icon src={info.logoUrl} /> <L2Icon src={info.logoUrl} />
<Body> <Body>
<Trans>This is an alpha release of Uniswap on the {NETWORK_LABELS[chainId]} network.</Trans> <Trans>This is an alpha release of Uniswap on the {info.label} network.</Trans>
<DesktopTextBreak /> <Trans>You must bridge L1 assets to the network to use them.</Trans> <DesktopTextBreak /> <Trans>You must bridge L1 assets to the network to use them.</Trans>
</Body> </Body>
<LinkOutToBridge href={depositUrl}> <LinkOutToBridge href={depositUrl}>
<Trans>Deposit to {NETWORK_LABELS[chainId]}</Trans> <Trans>Deposit to {info.label}</Trans>
<LinkOutCircle /> <LinkOutCircle />
</LinkOutToBridge> </LinkOutToBridge>
</Wrapper> </Wrapper>
......
...@@ -5,7 +5,7 @@ import { ...@@ -5,7 +5,7 @@ import {
OptimismWrapperBackgroundDarkMode, OptimismWrapperBackgroundDarkMode,
OptimismWrapperBackgroundLightMode, OptimismWrapperBackgroundLightMode,
} from 'components/NetworkAlert/NetworkAlert' } from 'components/NetworkAlert/NetworkAlert'
import { CHAIN_INFO, L2_CHAIN_IDS, NETWORK_LABELS, SupportedChainId, SupportedL2ChainId } from 'constants/chains' import { CHAIN_INFO, L2_CHAIN_IDS, SupportedChainId, SupportedL2ChainId } from 'constants/chains'
import { useActiveWeb3React } from 'hooks/web3' import { useActiveWeb3React } from 'hooks/web3'
import { ArrowDownCircle } from 'react-feather' import { ArrowDownCircle } from 'react-feather'
import { useArbitrumAlphaAlert, useDarkModeManager } from 'state/user/hooks' import { useArbitrumAlphaAlert, useDarkModeManager } from 'state/user/hooks'
...@@ -116,11 +116,11 @@ export function MinimalNetworkAlert() { ...@@ -116,11 +116,11 @@ export function MinimalNetworkAlert() {
<Wrapper darkMode={darkMode} chainId={chainId} logoUrl={info.logoUrl}> <Wrapper darkMode={darkMode} chainId={chainId} logoUrl={info.logoUrl}>
<L2Icon src={info.logoUrl} /> <L2Icon src={info.logoUrl} />
<Body> <Body>
<Trans>This is an alpha release of Uniswap on the {NETWORK_LABELS[chainId]} network.</Trans> <Trans>This is an alpha release of Uniswap on the {info.label} network.</Trans>
<DesktopTextBreak /> <Trans>You must bridge L1 assets to the network to use them.</Trans> <DesktopTextBreak /> <Trans>You must bridge L1 assets to the network to use them.</Trans>
</Body> </Body>
<LinkOutToBridge href={depositUrl}> <LinkOutToBridge href={depositUrl}>
<Trans>Deposit to {NETWORK_LABELS[chainId]}</Trans> <Trans>Deposit to {info.label}</Trans>
<LinkOutCircle /> <LinkOutCircle />
</LinkOutToBridge> </LinkOutToBridge>
</Wrapper> </Wrapper>
......
import { Trans } from '@lingui/macro' import { Trans } from '@lingui/macro'
import { L2_CHAIN_IDS, NETWORK_LABELS, SupportedChainId, SupportedL2ChainId } from 'constants/chains' import { L2_CHAIN_IDS, SupportedChainId, SupportedL2ChainId } from 'constants/chains'
import { useActiveWeb3React } from 'hooks/web3' import { useActiveWeb3React } from 'hooks/web3'
import { useCallback, useState } from 'react' import { useCallback, useState } from 'react'
import { ArrowDownCircle, X } from 'react-feather' import { ArrowDownCircle, X } from 'react-feather'
...@@ -139,23 +139,24 @@ export function NetworkAlert() { ...@@ -139,23 +139,24 @@ export function NetworkAlert() {
const depositUrl = [SupportedChainId.OPTIMISM, SupportedChainId.OPTIMISTIC_KOVAN].includes(chainId) const depositUrl = [SupportedChainId.OPTIMISM, SupportedChainId.OPTIMISTIC_KOVAN].includes(chainId)
? `${info.bridge}?chainId=1` ? `${info.bridge}?chainId=1`
: info.bridge : info.bridge
return ( return (
<RootWrapper chainId={chainId} darkMode={darkMode} logoUrl={info.logoUrl}> <RootWrapper chainId={chainId} darkMode={darkMode} logoUrl={info.logoUrl}>
<CloseIcon onClick={dismiss} /> <CloseIcon onClick={dismiss} />
<ContentWrapper> <ContentWrapper>
<L2Icon src={info.logoUrl} /> <L2Icon src={info.logoUrl} />
<Header> <Header>
<Trans>Uniswap on {NETWORK_LABELS[chainId]}</Trans> <Trans>Uniswap on {info.label}</Trans>
</Header> </Header>
<Body> <Body>
<Trans> <Trans>
This is an alpha release of Uniswap on the {NETWORK_LABELS[chainId]} network. You must bridge L1 assets to This is an alpha release of Uniswap on the {info.label} network. You must bridge L1 assets to the network to
the network to swap them. swap them.
</Trans> </Trans>
</Body> </Body>
</ContentWrapper> </ContentWrapper>
<LinkOutToBridge href={depositUrl}> <LinkOutToBridge href={depositUrl}>
<Trans>Deposit to {NETWORK_LABELS[chainId]}</Trans> <Trans>Deposit to {info.label}</Trans>
<LinkOutCircle /> <LinkOutCircle />
</LinkOutToBridge> </LinkOutToBridge>
</RootWrapper> </RootWrapper>
......
...@@ -4,7 +4,7 @@ import { PortisConnector } from '@web3-react/portis-connector' ...@@ -4,7 +4,7 @@ import { PortisConnector } from '@web3-react/portis-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 UNISWAP_LOGO_URL from '../assets/svg/logo.svg' import UNISWAP_LOGO_URL from '../assets/svg/logo.svg'
import { SupportedChainId } from '../constants/chains' import { ALL_SUPPORTED_CHAIN_IDS, SupportedChainId } from '../constants/chains'
import getLibrary from '../utils/getLibrary' import getLibrary from '../utils/getLibrary'
import { FortmaticConnector } from './Fortmatic' import { FortmaticConnector } from './Fortmatic'
import { NetworkConnector } from './NetworkConnector' import { NetworkConnector } from './NetworkConnector'
...@@ -18,7 +18,7 @@ if (typeof INFURA_KEY === 'undefined') { ...@@ -18,7 +18,7 @@ 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`)
} }
const NETWORK_URLS = { const NETWORK_URLS: { [key in SupportedChainId]: string } = {
[SupportedChainId.MAINNET]: `https://mainnet.infura.io/v3/${INFURA_KEY}`, [SupportedChainId.MAINNET]: `https://mainnet.infura.io/v3/${INFURA_KEY}`,
[SupportedChainId.RINKEBY]: `https://rinkeby.infura.io/v3/${INFURA_KEY}`, [SupportedChainId.RINKEBY]: `https://rinkeby.infura.io/v3/${INFURA_KEY}`,
[SupportedChainId.ROPSTEN]: `https://ropsten.infura.io/v3/${INFURA_KEY}`, [SupportedChainId.ROPSTEN]: `https://ropsten.infura.io/v3/${INFURA_KEY}`,
...@@ -30,18 +30,6 @@ const NETWORK_URLS = { ...@@ -30,18 +30,6 @@ const NETWORK_URLS = {
[SupportedChainId.ARBITRUM_RINKEBY]: `https://arbitrum-rinkeby.infura.io/v3/${INFURA_KEY}`, [SupportedChainId.ARBITRUM_RINKEBY]: `https://arbitrum-rinkeby.infura.io/v3/${INFURA_KEY}`,
} }
const SUPPORTED_CHAIN_IDS = [
SupportedChainId.MAINNET,
SupportedChainId.KOVAN,
SupportedChainId.GOERLI,
SupportedChainId.RINKEBY,
SupportedChainId.ROPSTEN,
SupportedChainId.OPTIMISM,
SupportedChainId.OPTIMISTIC_KOVAN,
SupportedChainId.ARBITRUM_ONE,
SupportedChainId.ARBITRUM_RINKEBY,
]
export const network = new NetworkConnector({ export const network = new NetworkConnector({
urls: NETWORK_URLS, urls: NETWORK_URLS,
defaultChainId: 1, defaultChainId: 1,
...@@ -53,11 +41,11 @@ export function getNetworkLibrary(): Web3Provider { ...@@ -53,11 +41,11 @@ export function getNetworkLibrary(): Web3Provider {
} }
export const injected = new InjectedConnector({ export const injected = new InjectedConnector({
supportedChainIds: SUPPORTED_CHAIN_IDS, supportedChainIds: ALL_SUPPORTED_CHAIN_IDS,
}) })
export const walletconnect = new WalletConnectConnector({ export const walletconnect = new WalletConnectConnector({
supportedChainIds: SUPPORTED_CHAIN_IDS, supportedChainIds: ALL_SUPPORTED_CHAIN_IDS,
rpc: NETWORK_URLS, rpc: NETWORK_URLS,
bridge: WALLETCONNECT_BRIDGE_URL, bridge: WALLETCONNECT_BRIDGE_URL,
qrcode: true, qrcode: true,
......
...@@ -14,6 +14,8 @@ export enum SupportedChainId { ...@@ -14,6 +14,8 @@ export enum SupportedChainId {
OPTIMISTIC_KOVAN = 69, OPTIMISTIC_KOVAN = 69,
} }
export const ALL_SUPPORTED_CHAIN_IDS: SupportedChainId[] = Object.values(SupportedChainId) as SupportedChainId[]
export type SupportedL2ChainId = export type SupportedL2ChainId =
| SupportedChainId.ARBITRUM_ONE | SupportedChainId.ARBITRUM_ONE
| SupportedChainId.ARBITRUM_RINKEBY | SupportedChainId.ARBITRUM_RINKEBY
...@@ -27,18 +29,6 @@ export type SupportedL1ChainId = ...@@ -27,18 +29,6 @@ export type SupportedL1ChainId =
| SupportedChainId.GOERLI | SupportedChainId.GOERLI
| SupportedChainId.KOVAN | SupportedChainId.KOVAN
export const NETWORK_LABELS: { [chainId in SupportedChainId | number]: string } = {
[SupportedChainId.MAINNET]: 'Mainnet',
[SupportedChainId.RINKEBY]: 'Rinkeby',
[SupportedChainId.ROPSTEN]: 'Ropsten',
[SupportedChainId.GOERLI]: 'Görli',
[SupportedChainId.KOVAN]: 'Kovan',
[SupportedChainId.ARBITRUM_ONE]: 'Arbitrum',
[SupportedChainId.ARBITRUM_RINKEBY]: 'Arbitrum Rinkeby',
[SupportedChainId.OPTIMISM]: 'Optimism',
[SupportedChainId.OPTIMISTIC_KOVAN]: 'Optimistic Kovan',
} as const
export const L1_CHAIN_IDS = [ export const L1_CHAIN_IDS = [
SupportedChainId.MAINNET, SupportedChainId.MAINNET,
SupportedChainId.ROPSTEN, SupportedChainId.ROPSTEN,
...@@ -73,7 +63,7 @@ export const CHAIN_INFO: ChainInfo = { ...@@ -73,7 +63,7 @@ export const CHAIN_INFO: ChainInfo = {
docs: 'https://offchainlabs.com/', docs: 'https://offchainlabs.com/',
explorer: 'https://explorer.arbitrum.io/', explorer: 'https://explorer.arbitrum.io/',
infoLink: 'https://info.uniswap.org/#/arbitrum', infoLink: 'https://info.uniswap.org/#/arbitrum',
label: NETWORK_LABELS[SupportedChainId.ARBITRUM_ONE], label: 'Arbitrum',
logoUrl: arbitrumLogoUrl, logoUrl: arbitrumLogoUrl,
}, },
[SupportedChainId.ARBITRUM_RINKEBY]: { [SupportedChainId.ARBITRUM_RINKEBY]: {
...@@ -81,45 +71,45 @@ export const CHAIN_INFO: ChainInfo = { ...@@ -81,45 +71,45 @@ export const CHAIN_INFO: ChainInfo = {
docs: 'https://offchainlabs.com/', docs: 'https://offchainlabs.com/',
explorer: 'https://explorer.arbitrum.io/', explorer: 'https://explorer.arbitrum.io/',
infoLink: 'https://info.uniswap.org/#/arbitrum/', infoLink: 'https://info.uniswap.org/#/arbitrum/',
label: NETWORK_LABELS[SupportedChainId.ARBITRUM_RINKEBY], label: 'Arbitrum Rinkeby',
logoUrl: arbitrumLogoUrl, logoUrl: arbitrumLogoUrl,
}, },
[SupportedChainId.MAINNET]: { [SupportedChainId.MAINNET]: {
docs: 'https://docs.uniswap.org/', docs: 'https://docs.uniswap.org/',
explorer: 'https://etherscan.io/', explorer: 'https://etherscan.io/',
infoLink: 'https://info.uniswap.org/#/', infoLink: 'https://info.uniswap.org/#/',
label: NETWORK_LABELS[SupportedChainId.MAINNET], label: 'Mainnet',
}, },
[SupportedChainId.RINKEBY]: { [SupportedChainId.RINKEBY]: {
docs: 'https://docs.uniswap.org/', docs: 'https://docs.uniswap.org/',
explorer: 'https://rinkeby.etherscan.io/', explorer: 'https://rinkeby.etherscan.io/',
infoLink: 'https://info.uniswap.org/#/', infoLink: 'https://info.uniswap.org/#/',
label: NETWORK_LABELS[SupportedChainId.RINKEBY], label: 'Rinkeby',
}, },
[SupportedChainId.ROPSTEN]: { [SupportedChainId.ROPSTEN]: {
docs: 'https://docs.uniswap.org/', docs: 'https://docs.uniswap.org/',
explorer: 'https://ropsten.etherscan.io/', explorer: 'https://ropsten.etherscan.io/',
infoLink: 'https://info.uniswap.org/#/', infoLink: 'https://info.uniswap.org/#/',
label: NETWORK_LABELS[SupportedChainId.ROPSTEN], label: 'Ropsten',
}, },
[SupportedChainId.KOVAN]: { [SupportedChainId.KOVAN]: {
docs: 'https://docs.uniswap.org/', docs: 'https://docs.uniswap.org/',
explorer: 'https://kovan.etherscan.io/', explorer: 'https://kovan.etherscan.io/',
infoLink: 'https://info.uniswap.org/#/', infoLink: 'https://info.uniswap.org/#/',
label: NETWORK_LABELS[SupportedChainId.KOVAN], label: 'Kovan',
}, },
[SupportedChainId.GOERLI]: { [SupportedChainId.GOERLI]: {
docs: 'https://docs.uniswap.org/', docs: 'https://docs.uniswap.org/',
explorer: 'https://goerli.etherscan.io/', explorer: 'https://goerli.etherscan.io/',
infoLink: 'https://info.uniswap.org/#/', infoLink: 'https://info.uniswap.org/#/',
label: NETWORK_LABELS[SupportedChainId.GOERLI], label: 'Görli',
}, },
[SupportedChainId.OPTIMISM]: { [SupportedChainId.OPTIMISM]: {
bridge: 'https://gateway.optimism.io/', bridge: 'https://gateway.optimism.io/',
docs: 'https://optimism.io/', docs: 'https://optimism.io/',
explorer: 'https://optimistic.etherscan.io/', explorer: 'https://optimistic.etherscan.io/',
infoLink: 'https://info.uniswap.org/#/optimism/', infoLink: 'https://info.uniswap.org/#/optimism/',
label: NETWORK_LABELS[SupportedChainId.OPTIMISM], label: 'Optimism',
logoUrl: optimismLogoUrl, logoUrl: optimismLogoUrl,
}, },
[SupportedChainId.OPTIMISTIC_KOVAN]: { [SupportedChainId.OPTIMISTIC_KOVAN]: {
...@@ -127,7 +117,7 @@ export const CHAIN_INFO: ChainInfo = { ...@@ -127,7 +117,7 @@ export const CHAIN_INFO: ChainInfo = {
docs: 'https://optimism.io/', docs: 'https://optimism.io/',
explorer: 'https://optimistic.etherscan.io/', explorer: 'https://optimistic.etherscan.io/',
infoLink: 'https://info.uniswap.org/#/optimism', infoLink: 'https://info.uniswap.org/#/optimism',
label: NETWORK_LABELS[SupportedChainId.OPTIMISTIC_KOVAN], label: 'Optimistic Kovan',
logoUrl: optimismLogoUrl, logoUrl: optimismLogoUrl,
}, },
} }
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