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

175 lines
5.4 KiB
TypeScript
Raw Normal View History

2020-05-14 20:18:08 +03:00
import React, { Suspense, useEffect } from 'react'
import styled from 'styled-components'
2020-05-14 20:18:08 +03:00
import ReactGA from 'react-ga'
import { BrowserRouter, Redirect, Route, RouteComponentProps, Switch } from 'react-router-dom'
import Header from '../components/Header'
import Footer from '../components/Footer'
import NavigationTabs from '../components/NavigationTabs'
2020-03-20 23:03:23 +03:00
import Web3ReactManager from '../components/Web3ReactManager'
import Popups from '../components/Popups'
import { isAddress, getAllQueryParams } from '../utils'
2018-10-07 00:24:17 +03:00
import Swap from './Swap'
import Send from './Send'
import Pool from './Pool'
import Add from './Pool/AddLiquidity'
import Remove from './Pool/RemoveLiquidity'
import Find from '../components/PoolFinder'
import Create from '../components/CreatePool'
2019-08-07 21:58:29 +03:00
const AppWrapper = styled.div`
display: flex;
flex-flow: column;
align-items: flex-start;
overflow-x: hidden;
2019-08-07 21:58:29 +03:00
height: 100vh;
`
const HeaderWrapper = styled.div`
${({ theme }) => theme.flexRowNoWrap}
width: 100%;
justify-content: space-between;
`
const BodyWrapper = styled.div`
2019-08-07 21:58:29 +03:00
display: flex;
flex-direction: column;
width: 100%;
box-sizing: border-box;
padding-top: 160px;
2019-08-07 21:58:29 +03:00
align-items: center;
flex: 1;
overflow: auto;
z-index: 10;
transition: height 0.3s ease;
& > * {
max-width: calc(420px + 4rem);
width: 90%;
}
${({ theme }) => theme.mediaWidth.upToExtraSmall`
padding-top: 16px;
padding-left: 16px;
padding-right: 16px;
`};
z-index: 1;
`
const Body = styled.div`
max-width: 420px;
width: 100%;
/* min-height: 340px; */
background: ${({ theme }) => theme.bg1};
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: 30px;
box-sizing: border-box;
padding: 1rem;
position: relative;
margin-bottom: 10rem;
`
const StyledRed = styled.div`
width: 100%;
height: 200vh;
background: ${({ theme }) => `radial-gradient(50% 50% at 50% 50%, ${theme.primary1} 0%, ${theme.bg1} 100%)`};
position: absolute;
top: 0px;
left: 0px;
opacity: 0.1;
z-index: -1;
transform: translateY(-70vh);
@media (max-width: 960px) {
height: 300px;
width: 100%;
transform: translateY(-150px);
}
`
2020-05-14 20:18:08 +03:00
// fires a GA pageview every time the route changes
function GoogleAnalyticsReporter({ location: { pathname, search } }: RouteComponentProps) {
useEffect(() => {
ReactGA.pageview(`${pathname}${search}`)
}, [pathname, search])
return null
}
export default function App() {
const params = getAllQueryParams()
return (
<>
<Suspense fallback={null}>
2020-05-07 21:01:34 +03:00
<BrowserRouter>
2020-05-14 20:18:08 +03:00
<Route component={GoogleAnalyticsReporter} />
2020-05-07 21:01:34 +03:00
<AppWrapper>
<HeaderWrapper>
<Header />
2020-05-07 21:01:34 +03:00
</HeaderWrapper>
<BodyWrapper>
<Popups />
2020-05-14 19:57:19 +03:00
<Web3ReactManager>
<Body>
<NavigationTabs />
2019-08-07 21:58:29 +03:00
{/* this Suspense is for route code-splitting */}
<Switch>
<Route exact strict path="/" render={() => <Redirect to="/swap" />} />
<Route exact strict path="/swap" component={() => <Swap params={params} />} />
<Route exact strict path="/send" component={() => <Send params={params} />} />
<Route exact strict path="/find" component={() => <Find />} />
<Route exact strict path="/create" component={() => <Create />} />
<Route exact strict path="/pool" component={() => <Pool />} />
<Route
exact
strict
path={'/add/:tokens'}
component={({ match }) => {
const tokens = match.params.tokens.split('-')
const t0 =
tokens?.[0] === 'ETH' ? 'ETH' : isAddress(tokens?.[0]) ? isAddress(tokens[0]) : undefined
const t1 =
tokens?.[1] === 'ETH' ? 'ETH' : isAddress(tokens?.[1]) ? isAddress(tokens[1]) : undefined
if (t0 && t1) {
return <Add token0={t0} token1={t1} />
} else {
return <Redirect to="/pool" />
}
}}
/>
<Route
exact
strict
path={'/remove/:tokens'}
component={({ match }) => {
const tokens = match.params.tokens.split('-')
const t0 =
tokens?.[0] === 'ETH' ? 'ETH' : isAddress(tokens?.[0]) ? isAddress(tokens[0]) : undefined
const t1 =
tokens?.[1] === 'ETH' ? 'ETH' : isAddress(tokens?.[1]) ? isAddress(tokens[1]) : undefined
if (t0 && t1) {
return <Remove token0={t0} token1={t1} />
} else {
return <Redirect to="/pool" />
}
}}
/>
<Redirect to="/" />
</Switch>
2020-05-14 19:57:19 +03:00
</Body>
</Web3ReactManager>
<Footer />
2020-05-07 21:01:34 +03:00
</BodyWrapper>
<StyledRed />
2020-05-07 21:01:34 +03:00
</AppWrapper>
</BrowserRouter>
</Suspense>
</>
)
2018-10-07 00:24:17 +03:00
}