uniswap-interface-uncensored/src/pages/App.js

182 lines
6.6 KiB
JavaScript
Raw Normal View History

import React, { Suspense, lazy } from 'react'
import styled from 'styled-components'
import { transparentize } from 'polished'
import { BrowserRouter, Redirect, Route, Switch } from 'react-router-dom'
import Header from '../components/Header'
import NavigationTabs from '../components/NavigationTabs'
2020-03-20 23:03:23 +03:00
import Web3ReactManager from '../components/Web3ReactManager'
import { useWeb3React } from '../hooks'
import { isAddress, getAllQueryParams } from '../utils'
2018-10-07 00:24:17 +03:00
const Swap = lazy(() => import('./Swap'))
const Send = lazy(() => import('./Send'))
const Pool = lazy(() => import('./Supply'))
const Add = lazy(() => import('./Supply/AddLiquidity'))
const Remove = lazy(() => import('./Supply/RemoveLiquidity'))
2020-03-11 17:44:39 +03:00
const Find = lazy(() => import('../components/PoolFinder'))
2019-08-07 21:58:29 +03:00
const AppWrapper = styled.div`
display: flex;
flex-flow: column;
align-items: flex-start;
height: 100vh;
`
const HeaderWrapper = styled.div`
${({ theme }) => theme.flexRowNoWrap}
width: 100%;
justify-content: space-between;
`
const BetaMessage = styled.div`
${({ theme }) => theme.flexRowNoWrap}
cursor: pointer;
max-height: 40px;
flex: 1 0 auto;
align-items: center;
position: relative;
padding: 0.5rem 1rem;
margin-bottom: 1rem;
border: 1px solid ${({ theme }) => transparentize(0.6, theme.wisteriaPurple)};
background-color: ${({ theme }) => transparentize(0.9, theme.wisteriaPurple)};
border-radius: 1rem;
font-size: 0.75rem;
line-height: 1rem;
text-align: left;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: ${({ theme }) => theme.wisteriaPurple};
`
const BodyWrapper = styled.div`
2019-08-07 21:58:29 +03:00
display: flex;
flex-direction: column;
width: 100%;
2019-08-07 21:58:29 +03:00
justify-content: flex-start;
align-items: center;
flex: 1;
overflow: auto;
`
const Body = styled.div`
max-width: 355px;
2019-08-07 21:58:29 +03:00
width: 90%;
background: ${({ theme }) => theme.panelBackground};
2020-03-06 06:57:41 +03:00
box-shadow: 0px 0px 1px rgba(0, 0, 0, 0.01), 0px 4px 8px rgba(0, 0, 0, 0.04), 0px 16px 24px rgba(0, 0, 0, 0.04),
0px 24px 32px rgba(0, 0, 0, 0.01);
border-radius: 20px;
padding: 2rem 2rem 1rem 2rem;
`
export default function App() {
const params = getAllQueryParams()
const { chainId } = useWeb3React()
return (
<>
<Suspense fallback={null}>
2019-08-07 21:58:29 +03:00
<AppWrapper>
<HeaderWrapper>
<Header />
</HeaderWrapper>
<BodyWrapper>
{chainId === 1 && (
<BetaMessage>Incorrect network. This site is intended to be used on Ethereum testnets only.</BetaMessage>
)}
2019-08-07 21:58:29 +03:00
<Body>
<Web3ReactManager>
<BrowserRouter>
<NavigationTabs />
{/* this Suspense is for route code-splitting */}
<Suspense fallback={null}>
<Switch>
2020-03-20 23:03:23 +03:00
<Route exact strict path="/" render={() => <Redirect to={{ pathname: '/swap' }} />} />
<Route exact strict path="/find" component={() => <Find params={params} />} />
<Route exact strict path="/swap" component={() => <Swap params={params} />} />
2019-08-07 21:58:29 +03:00
<Route
exact
strict
path="/swap/:tokenAddress?"
render={({ match, location }) => {
2019-08-07 21:58:29 +03:00
if (isAddress(match.params.tokenAddress)) {
return (
<Swap
location={location}
initialCurrency={isAddress(match.params.tokenAddress)}
params={params}
/>
)
2019-08-07 21:58:29 +03:00
} else {
return <Redirect to={{ pathname: '/swap' }} />
}
}}
/>
<Route exact strict path="/send" component={() => <Send params={params} />} />
2019-08-07 21:58:29 +03:00
<Route
exact
strict
path="/send/:tokenAddress?"
2020-01-02 21:13:20 +03:00
render={({ match }) => {
2019-08-07 21:58:29 +03:00
if (isAddress(match.params.tokenAddress)) {
return <Send initialCurrency={isAddress(match.params.tokenAddress)} params={params} />
2019-08-07 21:58:29 +03:00
} else {
return <Redirect to={{ pathname: '/send' }} />
}
}}
/>
<Route exaxct path={'/supply'} component={() => <Pool params={params} />} />
2019-08-07 21:58:29 +03:00
<Route
exact
strict
path={'/add/:tokens'}
component={({ match }) => {
const tokens = match.params.tokens.split('-')
let t0
let t1
if (tokens) {
t0 = tokens[0] === 'ETH' ? 'ETH' : isAddress(tokens[0])
t1 = tokens[1] === 'ETH' ? 'ETH' : isAddress(tokens[1])
}
if (t0 && t1) {
return <Add params={params} token0={t0} token1={t1} />
} else {
return <Redirect to={{ pathname: '/supply' }} />
}
}}
2019-08-07 21:58:29 +03:00
/>
<Route
exact
strict
path={'/remove/:tokens'}
component={({ match }) => {
const tokens = match.params.tokens.split('-')
let t0
let t1
if (tokens) {
t0 = tokens[0] === 'ETH' ? 'ETH' : isAddress(tokens[0])
t1 = tokens[1] === 'ETH' ? 'ETH' : isAddress(tokens[1])
}
if (t0 && t1) {
return <Remove params={params} token0={t0} token1={t1} />
} else {
return <Redirect to={{ pathname: '/supply' }} />
}
}}
/>
<Route exaxct path={'/remove'} component={() => <Remove params={params} />} />
2019-08-07 21:58:29 +03:00
</Switch>
</Suspense>
</BrowserRouter>
</Web3ReactManager>
</Body>
</BodyWrapper>
</AppWrapper>
</Suspense>
</>
)
2018-10-07 00:24:17 +03:00
}