Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
fix(L2): add common bases to L2s (#2428)
Browse files Browse the repository at this point in the history
* add common bases to L2s

* pr feedback
  • Loading branch information
JFrankfurt authored Sep 23, 2021
1 parent 8de6bb6 commit 384f674
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 19 deletions.
34 changes: 31 additions & 3 deletions src/components/CurrencyLogo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Currency } from '@uniswap/sdk-core'
import { SupportedChainId } from 'constants/chains'
import React, { useMemo } from 'react'
import styled from 'styled-components/macro'

Expand All @@ -7,8 +8,31 @@ import useHttpLocations from '../../hooks/useHttpLocations'
import { WrappedTokenInfo } from '../../state/lists/wrappedTokenInfo'
import Logo from '../Logo'

export const getTokenLogoURL = (address: string) =>
`https://github.com/uniswap/assets/master/blockchains/ethereum/assets/${address}/logo.png`
type Network = 'ethereum' | 'arbitrum' | 'optimism'

function chainIdToNetworkName(networkId: SupportedChainId): Network {
switch (networkId) {
case SupportedChainId.MAINNET:
return 'ethereum'
case SupportedChainId.ARBITRUM_ONE:
return 'arbitrum'
case SupportedChainId.OPTIMISM:
return 'optimism'
default:
return 'ethereum'
}
}

export const getTokenLogoURL = (
address: string,
chainId: SupportedChainId = SupportedChainId.MAINNET
): string | void => {
const networkName = chainIdToNetworkName(chainId)
const networksWithUrls = [SupportedChainId.ARBITRUM_ONE, SupportedChainId.MAINNET, SupportedChainId.OPTIMISM]
if (networksWithUrls.includes(chainId)) {
return `https://github.com/Uniswap/assets/master/blockchains/${networkName}/assets/${address}/logo.png`
}
}

const StyledEthereumLogo = styled.img<{ size: string }>`
width: ${({ size }) => size};
Expand Down Expand Up @@ -41,7 +65,11 @@ export default function CurrencyLogo({
if (!currency || currency.isNative) return []

if (currency.isToken) {
const defaultUrls = currency.chainId === 1 ? [getTokenLogoURL(currency.address)] : []
const defaultUrls = []
const url = getTokenLogoURL(currency.address, currency.chainId)
if (url) {
defaultUrls.push(url)
}
if (currency instanceof WrappedTokenInfo) {
return [...uriLocations, ...defaultUrls]
}
Expand Down
13 changes: 6 additions & 7 deletions src/components/SearchModal/CommonBases.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Trans } from '@lingui/macro'
import { Currency } from '@uniswap/sdk-core'
import { AutoColumn } from 'components/Column'
import CurrencyLogo from 'components/CurrencyLogo'
import QuestionHelper from 'components/QuestionHelper'
import { AutoRow } from 'components/Row'
import { COMMON_BASES } from 'constants/routing'
import { Text } from 'rebass'
import styled from 'styled-components/macro'

import { COMMON_BASES } from '../../constants/routing'
import { currencyId } from '../../utils/currencyId'
import { AutoColumn } from '../Column'
import CurrencyLogo from '../CurrencyLogo'
import QuestionHelper from '../QuestionHelper'
import { AutoRow } from '../Row'
import { currencyId } from 'utils/currencyId'

const MobileWrapper = styled(AutoColumn)`
${({ theme }) => theme.mediaWidth.upToSmall`
Expand Down
25 changes: 23 additions & 2 deletions src/constants/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { SupportedChainId } from './chains'
import {
AMPL,
DAI,
DAI_ARBITRUM_ONE,
DAI_OPTIMISM,
ETH2X_FLI,
ExtendedEther,
Expand All @@ -15,8 +16,10 @@ import {
TRIBE,
USDC,
USDT,
USDT_ARBITRUM_ONE,
USDT_OPTIMISM,
WBTC,
WBTC_ARBITRUM_ONE,
WBTC_OPTIMISM,
WETH9_EXTENDED,
} from './tokens'
Expand All @@ -38,6 +41,12 @@ export const BASES_TO_CHECK_TRADES_AGAINST: ChainTokenList = {
...WETH_ONLY,
[SupportedChainId.MAINNET]: [...WETH_ONLY[SupportedChainId.MAINNET], DAI, USDC, USDT, WBTC],
[SupportedChainId.OPTIMISM]: [...WETH_ONLY[SupportedChainId.OPTIMISM], DAI_OPTIMISM, USDT_OPTIMISM, WBTC_OPTIMISM],
[SupportedChainId.ARBITRUM_ONE]: [
...WETH_ONLY[SupportedChainId.ARBITRUM_ONE],
DAI_ARBITRUM_ONE,
USDT_ARBITRUM_ONE,
WBTC_ARBITRUM_ONE,
],
}
export const ADDITIONAL_BASES: { [chainId: number]: { [tokenAddress: string]: Token[] } } = {
[SupportedChainId.MAINNET]: {
Expand Down Expand Up @@ -84,14 +93,26 @@ export const COMMON_BASES: ChainCurrencyList = {
[SupportedChainId.KOVAN]: [ExtendedEther.onChain(SupportedChainId.KOVAN), WETH9_EXTENDED[SupportedChainId.KOVAN]],
[SupportedChainId.ARBITRUM_ONE]: [
ExtendedEther.onChain(SupportedChainId.ARBITRUM_ONE),
DAI_ARBITRUM_ONE,
USDT_ARBITRUM_ONE,
WBTC_ARBITRUM_ONE,
WETH9_EXTENDED[SupportedChainId.ARBITRUM_ONE],
],
[SupportedChainId.ARBITRUM_RINKEBY]: [
ExtendedEther.onChain(SupportedChainId.ARBITRUM_RINKEBY),
WETH9_EXTENDED[SupportedChainId.ARBITRUM_RINKEBY],
],
[SupportedChainId.OPTIMISM]: [ExtendedEther.onChain(SupportedChainId.OPTIMISM)],
[SupportedChainId.OPTIMISTIC_KOVAN]: [ExtendedEther.onChain(SupportedChainId.OPTIMISTIC_KOVAN)],
[SupportedChainId.OPTIMISM]: [
ExtendedEther.onChain(SupportedChainId.OPTIMISM),
DAI_OPTIMISM,
USDT_OPTIMISM,
WBTC_OPTIMISM,
WETH9_EXTENDED[SupportedChainId.OPTIMISM],
],
[SupportedChainId.OPTIMISTIC_KOVAN]: [
ExtendedEther.onChain(SupportedChainId.OPTIMISTIC_KOVAN),
WETH9_EXTENDED[SupportedChainId.OPTIMISTIC_KOVAN],
],
}

// used to construct the list of all pairs we consider by default in the frontend
Expand Down
35 changes: 28 additions & 7 deletions src/constants/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ export const DAI = new Token(
'DAI',
'Dai Stablecoin'
)
export const DAI_ARBITRUM_ONE = new Token(
SupportedChainId.ARBITRUM_ONE,
'0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
18,
'DAI',
'Dai stable coin'
)
export const DAI_OPTIMISM = new Token(
SupportedChainId.OPTIMISM,
'0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
18,
'DAI',
'Dai stable coin'
)
export const USDC = new Token(
SupportedChainId.MAINNET,
'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
Expand All @@ -31,20 +45,20 @@ export const USDC_ARBITRUM = new Token(
'USDC',
'USD//C'
)
export const DAI_OPTIMISM = new Token(
SupportedChainId.OPTIMISM,
'0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
18,
'DAI',
'Dai stable coin'
)
export const USDT = new Token(
SupportedChainId.MAINNET,
'0xdAC17F958D2ee523a2206206994597C13D831ec7',
6,
'USDT',
'Tether USD'
)
export const USDT_ARBITRUM_ONE = new Token(
SupportedChainId.ARBITRUM_ONE,
'0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9',
6,
'USDT',
'Tether USD'
)
export const USDT_OPTIMISM = new Token(
SupportedChainId.OPTIMISM,
'0x94b008aA00579c1307B0EF2c499aD98a8ce58e58',
Expand All @@ -59,6 +73,13 @@ export const WBTC = new Token(
'WBTC',
'Wrapped BTC'
)
export const WBTC_ARBITRUM_ONE = new Token(
SupportedChainId.ARBITRUM_ONE,
'0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f',
8,
'WBTC',
'Wrapped BTC'
)
export const WBTC_OPTIMISM = new Token(
SupportedChainId.OPTIMISM,
'0x68f180fcCe6836688e9084f035309E29Bf0A2095',
Expand Down

0 comments on commit 384f674

Please sign in to comment.