Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added lazy loading to the routes #235

Open
wants to merge 1 commit into
base: isha/fix/remove-@web3-starknet-react/core
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 42 additions & 40 deletions src/pages/App.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,14 @@
import React, { Suspense, useEffect } from 'react'
import React, { Suspense, useEffect, lazy } from 'react'
import { Route, Switch } from 'react-router-dom'
import styled from 'styled-components'
import Header from '../components/Header'
import Popups from '../components/Popups'
import DarkModeQueryParamReader from '../theme/DarkModeQueryParamReader'

import Swap from './Swap'
import { RedirectPathToSwapOnly, RedirectToSwap } from './Swap/redirects'

import Pool from './Pool'

import RemoveLiquidity from './RemoveLiquidity'
import {
RedirectDuplicateTokenIds,
RedirectOldAddLiquidityPathStructure,
RedirectToAddLiquidity
} from './AddLiquidity/redirects'

import Zap from './Zap'
import ComingSoon from './ComingSoon'
import Maintenance from './Maintenance'
import Footer from '../components/Footer'
import useFetchAllPairsCallback from '../hooks/useFetchAllPairs'
import { MainnetWarningModal } from '../components/MainnetWarningModal'
import { Web3ReactProvider } from '@web3-react/core'
import {
isProductionChainId,
isProductionEnvironment,
isStagingEnvironment,
isTestnetChainId,
isTestnetEnvironment
} from '../connectors'
import { isProductionChainId, isProductionEnvironment, isTestnetChainId, isTestnetEnvironment } from '../connectors'
import { useAccount, useConnectors } from '@starknet-react/core'
import { StarknetChainId } from 'starknet/dist/constants'
import { useAccountDetails } from '../hooks'
Expand Down Expand Up @@ -71,6 +49,28 @@ const Marginer = styled.div`
margin-top: 5rem;
`

const Swap = lazy(() => import('./Swap'))
const Pool = lazy(() => import('./Pool'))
const Zap = lazy(() => import('./Zap'))
const ComingSoon = lazy(() => import('./ComingSoon'))
const RemoveLiquidity = lazy(() => import('./RemoveLiquidity'))

const RedirectPathToSwapOnly = lazy(() =>
import('./Swap/redirects').then(module => ({ default: module.RedirectPathToSwapOnly }))
)

const RedirectToSwap = lazy(() => import('./Swap/redirects').then(module => ({ default: module.RedirectToSwap })))

const RedirectToAddLiquidity = lazy(() =>
import('./AddLiquidity/redirects').then(module => ({ default: module.RedirectToAddLiquidity }))
)
const RedirectOldAddLiquidityPathStructure = lazy(() =>
import('./AddLiquidity/redirects').then(module => ({ default: module.RedirectOldAddLiquidityPathStructure }))
)
const RedirectDuplicateTokenIds = lazy(() =>
import('./AddLiquidity/redirects').then(module => ({ default: module.RedirectDuplicateTokenIds }))
)

export default function App() {
const fetchAllPairs = useFetchAllPairsCallback()
const { disconnect } = useConnectors()
Expand Down Expand Up @@ -105,22 +105,24 @@ export default function App() {
<MainnetWarningModal />

<Web3ReactProvider getLibrary={web3 => web3}>
<Switch>
<Route exact strict path="/swap" component={Swap} />
<Route exact strict path="/swap/:outputCurrency" component={RedirectToSwap} />
<Route exact strict path="/pool" component={Pool} />
<Route exact path="/add" component={RedirectToAddLiquidity} />
<Route exact path="/add/:currencyIdA" component={RedirectOldAddLiquidityPathStructure} />
<Route exact path="/add/:currencyIdA/:currencyIdB" component={RedirectDuplicateTokenIds} />
<Route exact path="/create" component={RedirectToAddLiquidity} />
<Route exact path="/create/:currencyIdA" component={RedirectOldAddLiquidityPathStructure} />
<Route exact path="/create/:currencyIdA/:currencyIdB" component={RedirectDuplicateTokenIds} />
<Route exact path="/zap" component={Zap} />
{/* <Route exact path="/bridge" component={Bridge} /> */}
<Route exact path="/stake" component={ComingSoon} />
<Route exact strict path="/remove/:currencyIdA/:currencyIdB" component={RemoveLiquidity} />
<Route component={RedirectPathToSwapOnly} />
</Switch>
<Suspense fallback={'Loading...'}>
<Switch>
<Route exact strict path="/swap" component={Swap} />
<Route exact strict path="/swap/:outputCurrency" component={RedirectToSwap} />
<Route exact strict path="/pool" component={Pool} />
<Route exact path="/add" component={RedirectToAddLiquidity} />
<Route exact path="/add/:currencyIdA" component={RedirectOldAddLiquidityPathStructure} />
<Route exact path="/add/:currencyIdA/:currencyIdB" component={RedirectDuplicateTokenIds} />
<Route exact path="/create" component={RedirectToAddLiquidity} />
<Route exact path="/create/:currencyIdA" component={RedirectOldAddLiquidityPathStructure} />
<Route exact path="/create/:currencyIdA/:currencyIdB" component={RedirectDuplicateTokenIds} />
<Route exact path="/zap" component={Zap} />
{/* <Route exact path="/bridge" component={Bridge} /> */}
<Route exact path="/stake" component={ComingSoon} />
<Route exact strict path="/remove/:currencyIdA/:currencyIdB" component={RemoveLiquidity} />
<Route component={RedirectPathToSwapOnly} />
</Switch>
</Suspense>
</Web3ReactProvider>
<Marginer />
</BodyWrapper>
Expand Down