2022-07-08 18:57:47 +03:00
|
|
|
import { initializeAnalytics } from 'components/AmplitudeAnalytics'
|
2022-08-03 20:04:29 +03:00
|
|
|
import { sendAnalyticsEvent, user } from 'components/AmplitudeAnalytics'
|
|
|
|
import { CUSTOM_USER_PROPERTIES, EventName, PageName } from 'components/AmplitudeAnalytics/constants'
|
2022-07-19 00:26:29 +03:00
|
|
|
import { Trace } from 'components/AmplitudeAnalytics/Trace'
|
2021-11-18 09:01:45 +03:00
|
|
|
import Loader from 'components/Loader'
|
2022-04-19 18:12:28 +03:00
|
|
|
import TopLevelModals from 'components/TopLevelModals'
|
2022-08-04 22:02:52 +03:00
|
|
|
import { useFeatureFlagsIsLoaded } from 'featureFlags'
|
2021-07-07 17:59:31 +03:00
|
|
|
import ApeModeQueryParamReader from 'hooks/useApeModeQueryParamReader'
|
2021-11-18 09:01:45 +03:00
|
|
|
import { lazy, Suspense } from 'react'
|
2022-06-08 18:25:46 +03:00
|
|
|
import { useEffect } from 'react'
|
2022-07-27 00:10:57 +03:00
|
|
|
import { Navigate, Route, Routes, useLocation } from 'react-router-dom'
|
2022-08-03 20:04:29 +03:00
|
|
|
import { useIsDarkMode } from 'state/user/hooks'
|
2021-05-13 16:15:13 +03:00
|
|
|
import styled from 'styled-components/macro'
|
2022-08-03 20:04:29 +03:00
|
|
|
import { getBrowser } from 'utils/browser'
|
2021-09-22 02:21:28 +03:00
|
|
|
|
2022-06-10 23:36:44 +03:00
|
|
|
import { useAnalyticsReporter } from '../components/analytics'
|
2021-07-07 17:59:31 +03:00
|
|
|
import ErrorBoundary from '../components/ErrorBoundary'
|
2019-04-15 19:56:40 +03:00
|
|
|
import Header from '../components/Header'
|
2020-09-24 19:18:57 +03:00
|
|
|
import Polling from '../components/Header/Polling'
|
2020-04-23 00:22:13 +03:00
|
|
|
import Popups from '../components/Popups'
|
2022-08-05 00:30:08 +03:00
|
|
|
import { useIsExpertMode } from '../state/user/hooks'
|
2020-05-19 02:23:58 +03:00
|
|
|
import DarkModeQueryParamReader from '../theme/DarkModeQueryParamReader'
|
2021-07-07 17:59:31 +03:00
|
|
|
import AddLiquidity from './AddLiquidity'
|
2021-04-14 17:12:35 +03:00
|
|
|
import { RedirectDuplicateTokenIds } from './AddLiquidity/redirects'
|
2021-07-07 17:59:31 +03:00
|
|
|
import { RedirectDuplicateTokenIdsV2 } from './AddLiquidityV2/redirects'
|
2021-05-17 21:24:31 +03:00
|
|
|
import Earn from './Earn'
|
|
|
|
import Manage from './Earn/Manage'
|
|
|
|
import MigrateV2 from './MigrateV2'
|
|
|
|
import MigrateV2Pair from './MigrateV2/MigrateV2Pair'
|
|
|
|
import Pool from './Pool'
|
2021-07-07 17:59:31 +03:00
|
|
|
import { PositionPage } from './Pool/PositionPage'
|
2021-05-17 21:24:31 +03:00
|
|
|
import PoolV2 from './Pool/v2'
|
|
|
|
import PoolFinder from './PoolFinder'
|
|
|
|
import RemoveLiquidity from './RemoveLiquidity'
|
|
|
|
import RemoveLiquidityV3 from './RemoveLiquidity/V3'
|
2020-05-19 02:23:58 +03:00
|
|
|
import Swap from './Swap'
|
2020-09-24 19:18:57 +03:00
|
|
|
import { OpenClaimAddressModalAndRedirectToSwap, RedirectPathToSwapOnly, RedirectToSwap } from './Swap/redirects'
|
2021-11-18 09:01:45 +03:00
|
|
|
|
2022-07-27 00:10:57 +03:00
|
|
|
// lazy load vote related pages
|
2021-11-18 09:01:45 +03:00
|
|
|
const Vote = lazy(() => import('./Vote'))
|
2018-10-27 10:54:52 +03:00
|
|
|
|
2019-08-07 21:58:29 +03:00
|
|
|
const AppWrapper = styled.div`
|
|
|
|
display: flex;
|
|
|
|
flex-flow: column;
|
|
|
|
align-items: flex-start;
|
|
|
|
`
|
|
|
|
|
2019-05-30 23:42:25 +03:00
|
|
|
const BodyWrapper = styled.div`
|
2019-08-07 21:58:29 +03:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
2019-05-30 23:42:25 +03:00
|
|
|
width: 100%;
|
2021-06-22 22:51:32 +03:00
|
|
|
padding: 120px 16px 0px 16px;
|
2019-08-07 21:58:29 +03:00
|
|
|
align-items: center;
|
|
|
|
flex: 1;
|
2021-04-23 20:03:06 +03:00
|
|
|
z-index: 1;
|
|
|
|
|
2020-09-24 19:18:57 +03:00
|
|
|
${({ theme }) => theme.mediaWidth.upToSmall`
|
2021-12-16 22:44:03 +03:00
|
|
|
padding: 4rem 8px 16px 8px;
|
2020-05-06 22:34:06 +03:00
|
|
|
`};
|
2019-05-30 23:42:25 +03:00
|
|
|
`
|
2019-04-25 19:12:47 +03:00
|
|
|
|
2021-03-09 04:52:36 +03:00
|
|
|
const HeaderWrapper = styled.div`
|
|
|
|
${({ theme }) => theme.flexRowNoWrap}
|
|
|
|
width: 100%;
|
|
|
|
justify-content: space-between;
|
|
|
|
position: fixed;
|
|
|
|
top: 0;
|
|
|
|
z-index: 2;
|
|
|
|
`
|
|
|
|
|
2020-05-27 18:42:25 +03:00
|
|
|
const Marginer = styled.div`
|
|
|
|
margin-top: 5rem;
|
|
|
|
`
|
|
|
|
|
2022-07-19 00:26:29 +03:00
|
|
|
function getCurrentPageFromLocation(locationPathname: string): PageName | undefined {
|
|
|
|
switch (locationPathname) {
|
|
|
|
case '/swap':
|
|
|
|
return PageName.SWAP_PAGE
|
|
|
|
case '/vote':
|
|
|
|
return PageName.VOTE_PAGE
|
|
|
|
case '/pool':
|
|
|
|
return PageName.POOL_PAGE
|
|
|
|
default:
|
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-30 23:42:25 +03:00
|
|
|
export default function App() {
|
2022-08-02 19:57:13 +03:00
|
|
|
const isLoaded = useFeatureFlagsIsLoaded()
|
|
|
|
|
2022-07-27 00:10:57 +03:00
|
|
|
const { pathname } = useLocation()
|
|
|
|
const currentPage = getCurrentPageFromLocation(pathname)
|
2022-08-03 20:04:29 +03:00
|
|
|
const isDarkMode = useIsDarkMode()
|
2022-08-05 00:30:08 +03:00
|
|
|
const isExpertMode = useIsExpertMode()
|
2022-08-02 19:57:13 +03:00
|
|
|
|
2022-07-19 23:14:16 +03:00
|
|
|
useAnalyticsReporter()
|
2022-07-08 18:57:47 +03:00
|
|
|
initializeAnalytics()
|
2022-06-08 18:25:46 +03:00
|
|
|
|
|
|
|
useEffect(() => {
|
2022-07-24 21:31:55 +03:00
|
|
|
window.scrollTo(0, 0)
|
|
|
|
}, [pathname])
|
2022-06-08 18:25:46 +03:00
|
|
|
|
2022-08-03 20:04:29 +03:00
|
|
|
useEffect(() => {
|
|
|
|
// TODO(zzmp): add web vitals event properties to app loaded event.
|
|
|
|
sendAnalyticsEvent(EventName.APP_LOADED)
|
|
|
|
user.set(CUSTOM_USER_PROPERTIES.BROWSER, getBrowser())
|
|
|
|
user.set(CUSTOM_USER_PROPERTIES.SCREEN_RESOLUTION_HEIGHT, window.screen.height)
|
|
|
|
user.set(CUSTOM_USER_PROPERTIES.SCREEN_RESOLUTION_WIDTH, window.screen.width)
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
user.set(CUSTOM_USER_PROPERTIES.DARK_MODE, isDarkMode)
|
|
|
|
}, [isDarkMode])
|
|
|
|
|
2022-08-05 00:30:08 +03:00
|
|
|
useEffect(() => {
|
|
|
|
user.set(CUSTOM_USER_PROPERTIES.EXPERT_MODE, isExpertMode)
|
|
|
|
}, [isExpertMode])
|
|
|
|
|
2019-05-30 23:42:25 +03:00
|
|
|
return (
|
2021-05-11 19:09:01 +03:00
|
|
|
<ErrorBoundary>
|
2022-07-20 16:47:42 +03:00
|
|
|
<DarkModeQueryParamReader />
|
|
|
|
<ApeModeQueryParamReader />
|
2022-06-16 21:39:23 +03:00
|
|
|
<AppWrapper>
|
2022-07-19 00:26:29 +03:00
|
|
|
<Trace page={currentPage}>
|
|
|
|
<HeaderWrapper>
|
|
|
|
<Header />
|
|
|
|
</HeaderWrapper>
|
|
|
|
<BodyWrapper>
|
|
|
|
<Popups />
|
|
|
|
<Polling />
|
|
|
|
<TopLevelModals />
|
|
|
|
<Suspense fallback={<Loader />}>
|
2022-08-02 19:57:13 +03:00
|
|
|
{isLoaded ? (
|
|
|
|
<Routes>
|
|
|
|
<Route path="vote/*" element={<Vote />} />
|
|
|
|
<Route path="create-proposal" element={<Navigate to="/vote/create-proposal" replace />} />
|
|
|
|
<Route path="claim" element={<OpenClaimAddressModalAndRedirectToSwap />} />
|
|
|
|
<Route path="uni" element={<Earn />} />
|
|
|
|
<Route path="uni/:currencyIdA/:currencyIdB" element={<Manage />} />
|
|
|
|
|
|
|
|
<Route path="send" element={<RedirectPathToSwapOnly />} />
|
|
|
|
<Route path="swap/:outputCurrency" element={<RedirectToSwap />} />
|
|
|
|
<Route path="swap" element={<Swap />} />
|
|
|
|
|
|
|
|
<Route path="pool/v2/find" element={<PoolFinder />} />
|
|
|
|
<Route path="pool/v2" element={<PoolV2 />} />
|
|
|
|
<Route path="pool" element={<Pool />} />
|
|
|
|
<Route path="pool/:tokenId" element={<PositionPage />} />
|
|
|
|
|
|
|
|
<Route path="add/v2" element={<RedirectDuplicateTokenIdsV2 />}>
|
|
|
|
<Route path=":currencyIdA" />
|
|
|
|
<Route path=":currencyIdA/:currencyIdB" />
|
|
|
|
</Route>
|
|
|
|
<Route path="add" element={<RedirectDuplicateTokenIds />}>
|
|
|
|
{/* this is workaround since react-router-dom v6 doesn't support optional parameters any more */}
|
|
|
|
<Route path=":currencyIdA" />
|
|
|
|
<Route path=":currencyIdA/:currencyIdB" />
|
|
|
|
<Route path=":currencyIdA/:currencyIdB/:feeAmount" />
|
|
|
|
</Route>
|
|
|
|
|
|
|
|
<Route path="increase" element={<AddLiquidity />}>
|
|
|
|
<Route path=":currencyIdA" />
|
|
|
|
<Route path=":currencyIdA/:currencyIdB" />
|
|
|
|
<Route path=":currencyIdA/:currencyIdB/:feeAmount" />
|
|
|
|
<Route path=":currencyIdA/:currencyIdB/:feeAmount/:tokenId" />
|
|
|
|
</Route>
|
|
|
|
|
|
|
|
<Route path="remove/v2/:currencyIdA/:currencyIdB" element={<RemoveLiquidity />} />
|
|
|
|
<Route path="remove/:tokenId" element={<RemoveLiquidityV3 />} />
|
|
|
|
|
|
|
|
<Route path="migrate/v2" element={<MigrateV2 />} />
|
|
|
|
<Route path="migrate/v2/:address" element={<MigrateV2Pair />} />
|
|
|
|
|
|
|
|
<Route path="*" element={<RedirectPathToSwapOnly />} />
|
|
|
|
</Routes>
|
|
|
|
) : (
|
|
|
|
<Loader />
|
|
|
|
)}
|
2022-07-19 00:26:29 +03:00
|
|
|
</Suspense>
|
|
|
|
<Marginer />
|
|
|
|
</BodyWrapper>
|
|
|
|
</Trace>
|
2022-06-16 21:39:23 +03:00
|
|
|
</AppWrapper>
|
2021-05-11 19:09:01 +03:00
|
|
|
</ErrorBoundary>
|
2019-05-30 23:42:25 +03:00
|
|
|
)
|
2018-10-07 00:24:17 +03:00
|
|
|
}
|