Commit c42a5ccf authored by Sam Chen's avatar Sam Chen Committed by GitHub

chore: access router data with hooks (#4121)

* chore: access router data with hooks

* chore: clean RouteComponentProps

* chore: use children instead of render

* add import
parent 7ba9b1fa
import { useWeb3React } from '@web3-react/core' import { useWeb3React } from '@web3-react/core'
import { useEffect } from 'react' import { useEffect } from 'react'
import { UaEventOptions } from 'react-ga4/types/ga4' import { UaEventOptions } from 'react-ga4/types/ga4'
import { RouteComponentProps } from 'react-router-dom' import { useLocation } from 'react-router-dom'
import { isMobile } from 'utils/userAgent' import { isMobile } from 'utils/userAgent'
import { getCLS, getFCP, getFID, getLCP, Metric } from 'web-vitals' import { getCLS, getFCP, getFID, getLCP, Metric } from 'web-vitals'
...@@ -63,7 +63,8 @@ function reportWebVitals({ name, delta, id }: Metric) { ...@@ -63,7 +63,8 @@ function reportWebVitals({ name, delta, id }: Metric) {
} }
// tracks web vitals and pageviews // tracks web vitals and pageviews
export function useAnalyticsReporter({ pathname, search }: RouteComponentProps['location']) { export function useAnalyticsReporter() {
const { pathname, search } = useLocation()
useEffect(() => { useEffect(() => {
getFCP(reportWebVitals) getFCP(reportWebVitals)
getFID(reportWebVitals) getFID(reportWebVitals)
......
...@@ -11,7 +11,7 @@ import UnsupportedCurrencyFooter from 'components/swap/UnsupportedCurrencyFooter ...@@ -11,7 +11,7 @@ import UnsupportedCurrencyFooter from 'components/swap/UnsupportedCurrencyFooter
import useParsedQueryString from 'hooks/useParsedQueryString' import useParsedQueryString from 'hooks/useParsedQueryString'
import { useCallback, useContext, useEffect, useState } from 'react' import { useCallback, useContext, useEffect, useState } from 'react'
import { AlertTriangle } from 'react-feather' import { AlertTriangle } from 'react-feather'
import { RouteComponentProps } from 'react-router-dom' import { useHistory, useParams } from 'react-router-dom'
import { Text } from 'rebass' import { Text } from 'rebass'
import { import {
useRangeHopCallbacks, useRangeHopCallbacks,
...@@ -77,12 +77,14 @@ import { ...@@ -77,12 +77,14 @@ import {
const DEFAULT_ADD_IN_RANGE_SLIPPAGE_TOLERANCE = new Percent(50, 10_000) const DEFAULT_ADD_IN_RANGE_SLIPPAGE_TOLERANCE = new Percent(50, 10_000)
export default function AddLiquidity({ export default function AddLiquidity() {
match: { const history = useHistory()
params: { currencyIdA, currencyIdB, feeAmount: feeAmountFromUrl, tokenId }, const {
}, currencyIdA,
history, currencyIdB,
}: RouteComponentProps<{ currencyIdA?: string; currencyIdB?: string; feeAmount?: string; tokenId?: string }>) { feeAmount: feeAmountFromUrl,
tokenId,
} = useParams<{ currencyIdA?: string; currencyIdB?: string; feeAmount?: string; tokenId?: string }>()
const { account, chainId, provider } = useWeb3React() const { account, chainId, provider } = useWeb3React()
const theme = useContext(ThemeContext) const theme = useContext(ThemeContext)
const toggleWalletModal = useToggleWalletModal() // toggle wallet when disconnected const toggleWalletModal = useToggleWalletModal() // toggle wallet when disconnected
......
import { useWeb3React } from '@web3-react/core' import { useWeb3React } from '@web3-react/core'
import { Redirect, RouteComponentProps } from 'react-router-dom' import { Redirect, useParams } from 'react-router-dom'
import { WRAPPED_NATIVE_CURRENCY } from '../../constants/tokens' import { WRAPPED_NATIVE_CURRENCY } from '../../constants/tokens'
import AddLiquidity from './index' import AddLiquidity from './index'
export function RedirectDuplicateTokenIds( export function RedirectDuplicateTokenIds() {
props: RouteComponentProps<{ currencyIdA: string; currencyIdB: string; feeAmount?: string }> const { currencyIdA, currencyIdB } = useParams<{ currencyIdA: string; currencyIdB: string; feeAmount?: string }>()
) {
const {
match: {
params: { currencyIdA, currencyIdB },
},
} = props
const { chainId } = useWeb3React() const { chainId } = useWeb3React()
...@@ -28,5 +22,5 @@ export function RedirectDuplicateTokenIds( ...@@ -28,5 +22,5 @@ export function RedirectDuplicateTokenIds(
) { ) {
return <Redirect to={`/add/${currencyIdA}`} /> return <Redirect to={`/add/${currencyIdA}`} />
} }
return <AddLiquidity {...props} /> return <AddLiquidity />
} }
...@@ -10,7 +10,7 @@ import UnsupportedCurrencyFooter from 'components/swap/UnsupportedCurrencyFooter ...@@ -10,7 +10,7 @@ import UnsupportedCurrencyFooter from 'components/swap/UnsupportedCurrencyFooter
import { SwitchLocaleLink } from 'components/SwitchLocaleLink' import { SwitchLocaleLink } from 'components/SwitchLocaleLink'
import { useCallback, useContext, useState } from 'react' import { useCallback, useContext, useState } from 'react'
import { Plus } from 'react-feather' import { Plus } from 'react-feather'
import { RouteComponentProps } from 'react-router-dom' import { useHistory, useParams } from 'react-router-dom'
import { Text } from 'rebass' import { Text } from 'rebass'
import { ThemeContext } from 'styled-components/macro' import { ThemeContext } from 'styled-components/macro'
...@@ -49,12 +49,9 @@ import { PoolPriceBar } from './PoolPriceBar' ...@@ -49,12 +49,9 @@ import { PoolPriceBar } from './PoolPriceBar'
const DEFAULT_ADD_V2_SLIPPAGE_TOLERANCE = new Percent(50, 10_000) const DEFAULT_ADD_V2_SLIPPAGE_TOLERANCE = new Percent(50, 10_000)
export default function AddLiquidity({ export default function AddLiquidity() {
match: { const { currencyIdA, currencyIdB } = useParams<{ currencyIdA?: string; currencyIdB?: string }>()
params: { currencyIdA, currencyIdB }, const history = useHistory()
},
history,
}: RouteComponentProps<{ currencyIdA?: string; currencyIdB?: string }>) {
const { account, chainId, provider } = useWeb3React() const { account, chainId, provider } = useWeb3React()
const theme = useContext(ThemeContext) const theme = useContext(ThemeContext)
......
import { Redirect, RouteComponentProps } from 'react-router-dom' import { Redirect, useParams } from 'react-router-dom'
import AddLiquidityV2 from './index' import AddLiquidityV2 from './index'
export function RedirectDuplicateTokenIdsV2(props: RouteComponentProps<{ currencyIdA: string; currencyIdB: string }>) { export function RedirectDuplicateTokenIdsV2() {
const { const { currencyIdA, currencyIdB } = useParams<{ currencyIdA: string; currencyIdB: string }>()
match: {
params: { currencyIdA, currencyIdB },
},
} = props
if (currencyIdA && currencyIdB && currencyIdA.toLowerCase() === currencyIdB.toLowerCase()) { if (currencyIdA && currencyIdB && currencyIdA.toLowerCase() === currencyIdB.toLowerCase()) {
return <Redirect to={`/add/v2/${currencyIdA}`} /> return <Redirect to={`/add/v2/${currencyIdA}`} />
} }
return <AddLiquidityV2 {...props} /> return <AddLiquidityV2 />
} }
...@@ -83,7 +83,7 @@ export default function App() { ...@@ -83,7 +83,7 @@ export default function App() {
const history = useHistory() const history = useHistory()
const location = useLocation() const location = useLocation()
const currentPage = getCurrentPageFromLocation(location.pathname) const currentPage = getCurrentPageFromLocation(location.pathname)
useAnalyticsReporter(useLocation()) useAnalyticsReporter()
initializeAnalytics() initializeAnalytics()
useEffect(() => { useEffect(() => {
...@@ -97,8 +97,12 @@ export default function App() { ...@@ -97,8 +97,12 @@ export default function App() {
return ( return (
<ErrorBoundary> <ErrorBoundary>
<Route component={DarkModeQueryParamReader} /> <Route>
<Route component={ApeModeQueryParamReader} /> <DarkModeQueryParamReader />
</Route>
<Route>
<ApeModeQueryParamReader />
</Route>
<AppWrapper> <AppWrapper>
<Trace page={currentPage}> <Trace page={currentPage}>
<HeaderWrapper> <HeaderWrapper>
...@@ -110,50 +114,73 @@ export default function App() { ...@@ -110,50 +114,73 @@ export default function App() {
<TopLevelModals /> <TopLevelModals />
<Suspense fallback={<Loader />}> <Suspense fallback={<Loader />}>
<Switch> <Switch>
<Route path="/vote" component={Vote} /> <Route strict path="/vote">
<Vote />
</Route>
<Route exact strict path="/create-proposal"> <Route exact strict path="/create-proposal">
<Redirect to="/vote/create-proposal" /> <Redirect to="/vote/create-proposal" />
</Route> </Route>
<Route exact strict path="/claim" component={OpenClaimAddressModalAndRedirectToSwap} /> <Route exact strict path="/claim">
<Route exact strict path="/uni" component={Earn} /> <OpenClaimAddressModalAndRedirectToSwap />
<Route exact strict path="/uni/:currencyIdA/:currencyIdB" component={Manage} /> </Route>
<Route exact strict path="/uni">
<Route exact strict path="/send" component={RedirectPathToSwapOnly} /> <Earn />
<Route exact strict path="/swap/:outputCurrency" component={RedirectToSwap} /> </Route>
<Route path="/swap" component={Swap} /> <Route exact strict path="/uni/:currencyIdA/:currencyIdB">
<Manage />
<Route exact strict path="/pool/v2/find" component={PoolFinder} /> </Route>
<Route exact strict path="/pool/v2" component={PoolV2} />
<Route exact strict path="/pool" component={Pool} /> <Route exact strict path="/send">
<Route exact strict path="/pool/:tokenId" component={PositionPage} /> <RedirectPathToSwapOnly />
</Route>
<Route <Route exact strict path="/swap/:outputCurrency">
exact <RedirectToSwap />
strict </Route>
path="/add/v2/:currencyIdA?/:currencyIdB?" <Route exact strict path="/swap">
component={RedirectDuplicateTokenIdsV2} <Swap />
/> </Route>
<Route
exact <Route exact strict path="/pool/v2/find">
strict <PoolFinder />
path="/add/:currencyIdA?/:currencyIdB?/:feeAmount?" </Route>
component={RedirectDuplicateTokenIds} <Route exact strict path="/pool/v2">
/> <PoolV2 />
</Route>
<Route <Route exact strict path="/pool">
exact <Pool />
strict </Route>
path="/increase/:currencyIdA?/:currencyIdB?/:feeAmount?/:tokenId?" <Route exact strict path="/pool/:tokenId">
component={AddLiquidity} <PositionPage />
/> </Route>
<Route exact strict path="/remove/v2/:currencyIdA/:currencyIdB" component={RemoveLiquidity} /> <Route exact strict path="/add/v2/:currencyIdA?/:currencyIdB?">
<Route exact strict path="/remove/:tokenId" component={RemoveLiquidityV3} /> <RedirectDuplicateTokenIdsV2 />
</Route>
<Route exact strict path="/migrate/v2" component={MigrateV2} /> <Route exact strict path="/add/:currencyIdA?/:currencyIdB?/:feeAmount?">
<Route exact strict path="/migrate/v2/:address" component={MigrateV2Pair} /> <RedirectDuplicateTokenIds />
</Route>
<Route component={RedirectPathToSwapOnly} />
<Route exact strict path="/increase/:currencyIdA?/:currencyIdB?/:feeAmount?/:tokenId?">
<AddLiquidity />
</Route>
<Route exact strict path="/remove/v2/:currencyIdA/:currencyIdB">
<RemoveLiquidity />
</Route>
<Route exact strict path="/remove/:tokenId">
<RemoveLiquidityV3 />
</Route>
<Route exact strict path="/migrate/v2">
<MigrateV2 />
</Route>
<Route exact strict path="/migrate/v2/:address">
<MigrateV2Pair />
</Route>
<Route>
<RedirectPathToSwapOnly />
</Route>
</Switch> </Switch>
</Suspense> </Suspense>
<Marginer /> <Marginer />
......
...@@ -3,8 +3,7 @@ import { CurrencyAmount, Token } from '@uniswap/sdk-core' ...@@ -3,8 +3,7 @@ import { CurrencyAmount, Token } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core' import { useWeb3React } from '@web3-react/core'
import JSBI from 'jsbi' import JSBI from 'jsbi'
import { useCallback, useState } from 'react' import { useCallback, useState } from 'react'
import { Link } from 'react-router-dom' import { Link, useParams } from 'react-router-dom'
import { RouteComponentProps } from 'react-router-dom'
import styled from 'styled-components/macro' import styled from 'styled-components/macro'
import { CountUp } from 'use-count-up' import { CountUp } from 'use-count-up'
...@@ -86,11 +85,8 @@ const DataRow = styled(RowBetween)` ...@@ -86,11 +85,8 @@ const DataRow = styled(RowBetween)`
`}; `};
` `
export default function Manage({ export default function Manage() {
match: { const { currencyIdA, currencyIdB } = useParams<{ currencyIdA: string; currencyIdB: string }>()
params: { currencyIdA, currencyIdB },
},
}: RouteComponentProps<{ currencyIdA: string; currencyIdB: string }>) {
const { account } = useWeb3React() const { account } = useWeb3React()
// get currencies and pair // get currencies and pair
......
...@@ -24,7 +24,8 @@ import JSBI from 'jsbi' ...@@ -24,7 +24,8 @@ import JSBI from 'jsbi'
import { NEVER_RELOAD, useSingleCallResult } from 'lib/hooks/multicall' import { NEVER_RELOAD, useSingleCallResult } from 'lib/hooks/multicall'
import { ReactNode, useCallback, useEffect, useMemo, useState } from 'react' import { ReactNode, useCallback, useEffect, useMemo, useState } from 'react'
import { AlertCircle, AlertTriangle, ArrowDown } from 'react-feather' import { AlertCircle, AlertTriangle, ArrowDown } from 'react-feather'
import { Redirect, RouteComponentProps } from 'react-router' import { Redirect } from 'react-router'
import { useParams } from 'react-router-dom'
import { Text } from 'rebass' import { Text } from 'rebass'
import { useAppDispatch } from 'state/hooks' import { useAppDispatch } from 'state/hooks'
import { Bound, resetMintState } from 'state/mint/v3/actions' import { Bound, resetMintState } from 'state/mint/v3/actions'
...@@ -662,11 +663,8 @@ function V2PairMigration({ ...@@ -662,11 +663,8 @@ function V2PairMigration({
) )
} }
export default function MigrateV2Pair({ export default function MigrateV2Pair() {
match: { const { address } = useParams<{ address: string }>()
params: { address },
},
}: RouteComponentProps<{ address: string }>) {
// reset mint state on component mount, and as a cleanup (on unmount) // reset mint state on component mount, and as a cleanup (on unmount)
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
useEffect(() => { useEffect(() => {
......
...@@ -28,7 +28,7 @@ import { useV3PositionFromTokenId } from 'hooks/useV3Positions' ...@@ -28,7 +28,7 @@ import { useV3PositionFromTokenId } from 'hooks/useV3Positions'
import { useSingleCallResult } from 'lib/hooks/multicall' import { useSingleCallResult } from 'lib/hooks/multicall'
import useNativeCurrency from 'lib/hooks/useNativeCurrency' import useNativeCurrency from 'lib/hooks/useNativeCurrency'
import { useCallback, useMemo, useRef, useState } from 'react' import { useCallback, useMemo, useRef, useState } from 'react'
import { Link, RouteComponentProps } from 'react-router-dom' import { Link, useParams } from 'react-router-dom'
import { Bound } from 'state/mint/v3/actions' import { Bound } from 'state/mint/v3/actions'
import { useIsTransactionPending, useTransactionAdder } from 'state/transactions/hooks' import { useIsTransactionPending, useTransactionAdder } from 'state/transactions/hooks'
import styled from 'styled-components/macro' import styled from 'styled-components/macro'
...@@ -315,11 +315,8 @@ const useInverter = ({ ...@@ -315,11 +315,8 @@ const useInverter = ({
} }
} }
export function PositionPage({ export function PositionPage() {
match: { const { tokenId: tokenIdFromUrl } = useParams<{ tokenId?: string }>()
params: { tokenId: tokenIdFromUrl },
},
}: RouteComponentProps<{ tokenId?: string }>) {
const { chainId, account, provider } = useWeb3React() const { chainId, account, provider } = useWeb3React()
const theme = useTheme() const theme = useTheme()
......
...@@ -25,7 +25,7 @@ import useTransactionDeadline from 'hooks/useTransactionDeadline' ...@@ -25,7 +25,7 @@ import useTransactionDeadline from 'hooks/useTransactionDeadline'
import { useV3PositionFromTokenId } from 'hooks/useV3Positions' import { useV3PositionFromTokenId } from 'hooks/useV3Positions'
import useNativeCurrency from 'lib/hooks/useNativeCurrency' import useNativeCurrency from 'lib/hooks/useNativeCurrency'
import { useCallback, useMemo, useState } from 'react' import { useCallback, useMemo, useState } from 'react'
import { Redirect, RouteComponentProps } from 'react-router-dom' import { Redirect, useLocation, useParams } from 'react-router-dom'
import { Text } from 'rebass' import { Text } from 'rebass'
import { useBurnV3ActionHandlers, useBurnV3State, useDerivedV3BurnInfo } from 'state/burn/v3/hooks' import { useBurnV3ActionHandlers, useBurnV3State, useDerivedV3BurnInfo } from 'state/burn/v3/hooks'
import { useTransactionAdder } from 'state/transactions/hooks' import { useTransactionAdder } from 'state/transactions/hooks'
...@@ -43,12 +43,9 @@ import { ResponsiveHeaderText, SmallMaxButton, Wrapper } from './styled' ...@@ -43,12 +43,9 @@ import { ResponsiveHeaderText, SmallMaxButton, Wrapper } from './styled'
const DEFAULT_REMOVE_V3_LIQUIDITY_SLIPPAGE_TOLERANCE = new Percent(5, 100) const DEFAULT_REMOVE_V3_LIQUIDITY_SLIPPAGE_TOLERANCE = new Percent(5, 100)
// redirect invalid tokenIds // redirect invalid tokenIds
export default function RemoveLiquidityV3({ export default function RemoveLiquidityV3() {
location, const { tokenId } = useParams<{ tokenId: string }>()
match: { const location = useLocation()
params: { tokenId },
},
}: RouteComponentProps<{ tokenId: string }>) {
const parsedTokenId = useMemo(() => { const parsedTokenId = useMemo(() => {
try { try {
return BigNumber.from(tokenId) return BigNumber.from(tokenId)
......
...@@ -10,7 +10,7 @@ import { sendEvent } from 'components/analytics' ...@@ -10,7 +10,7 @@ import { sendEvent } from 'components/analytics'
import { useV2LiquidityTokenPermit } from 'hooks/useV2LiquidityTokenPermit' import { useV2LiquidityTokenPermit } from 'hooks/useV2LiquidityTokenPermit'
import { useCallback, useContext, useMemo, useState } from 'react' import { useCallback, useContext, useMemo, useState } from 'react'
import { ArrowDown, Plus } from 'react-feather' import { ArrowDown, Plus } from 'react-feather'
import { RouteComponentProps } from 'react-router' import { useHistory, useParams } from 'react-router-dom'
import { Text } from 'rebass' import { Text } from 'rebass'
import { ThemeContext } from 'styled-components/macro' import { ThemeContext } from 'styled-components/macro'
...@@ -47,12 +47,9 @@ import { ClickableText, MaxButton, Wrapper } from '../Pool/styleds' ...@@ -47,12 +47,9 @@ import { ClickableText, MaxButton, Wrapper } from '../Pool/styleds'
const DEFAULT_REMOVE_LIQUIDITY_SLIPPAGE_TOLERANCE = new Percent(5, 100) const DEFAULT_REMOVE_LIQUIDITY_SLIPPAGE_TOLERANCE = new Percent(5, 100)
export default function RemoveLiquidity({ export default function RemoveLiquidity() {
history, const history = useHistory()
match: { const { currencyIdA, currencyIdB } = useParams<{ currencyIdA: string; currencyIdB: string }>()
params: { currencyIdA, currencyIdB },
},
}: RouteComponentProps<{ currencyIdA: string; currencyIdB: string }>) {
const [currencyA, currencyB] = [useCurrency(currencyIdA) ?? undefined, useCurrency(currencyIdB) ?? undefined] const [currencyA, currencyB] = [useCurrency(currencyIdA) ?? undefined, useCurrency(currencyIdB) ?? undefined]
const { account, chainId, provider } = useWeb3React() const { account, chainId, provider } = useWeb3React()
const [tokenA, tokenB] = useMemo(() => [currencyA?.wrapped, currencyB?.wrapped], [currencyA, currencyB]) const [tokenA, tokenB] = useMemo(() => [currencyA?.wrapped, currencyB?.wrapped], [currencyA, currencyB])
......
...@@ -19,7 +19,7 @@ import JSBI from 'jsbi' ...@@ -19,7 +19,7 @@ import JSBI from 'jsbi'
import { Context, useCallback, useContext, useEffect, useMemo, useState } from 'react' import { Context, useCallback, useContext, useEffect, useMemo, useState } from 'react'
import { ReactNode } from 'react' import { ReactNode } from 'react'
import { ArrowDown, CheckCircle, HelpCircle } from 'react-feather' import { ArrowDown, CheckCircle, HelpCircle } from 'react-feather'
import { RouteComponentProps } from 'react-router-dom' import { useHistory } from 'react-router-dom'
import { Text } from 'rebass' import { Text } from 'rebass'
import { useToggleWalletModal } from 'state/application/hooks' import { useToggleWalletModal } from 'state/application/hooks'
import { InterfaceTrade } from 'state/routing/types' import { InterfaceTrade } from 'state/routing/types'
...@@ -77,7 +77,8 @@ export function getIsValidSwapQuote( ...@@ -77,7 +77,8 @@ export function getIsValidSwapQuote(
return !!swapInputError && !!trade && (tradeState === TradeState.VALID || tradeState === TradeState.SYNCING) return !!swapInputError && !!trade && (tradeState === TradeState.VALID || tradeState === TradeState.SYNCING)
} }
export default function Swap({ history }: RouteComponentProps) { export default function Swap() {
const history = useHistory()
const { account, chainId } = useWeb3React() const { account, chainId } = useWeb3React()
const loadedUrlParams = useDefaultsFromURLSearch() const loadedUrlParams = useDefaultsFromURLSearch()
......
import { useEffect } from 'react' import { useEffect } from 'react'
import { Redirect, RouteComponentProps } from 'react-router-dom' import { Redirect, useLocation, useParams } from 'react-router-dom'
import { useAppDispatch } from 'state/hooks' import { useAppDispatch } from 'state/hooks'
import { ApplicationModal, setOpenModal } from '../../state/application/reducer' import { ApplicationModal, setOpenModal } from '../../state/application/reducer'
// Redirects to swap but only replace the pathname // Redirects to swap but only replace the pathname
export function RedirectPathToSwapOnly({ location }: RouteComponentProps) { export function RedirectPathToSwapOnly() {
const location = useLocation()
return <Redirect to={{ ...location, pathname: '/swap' }} /> return <Redirect to={{ ...location, pathname: '/swap' }} />
} }
// Redirects from the /swap/:outputCurrency path to the /swap?outputCurrency=:outputCurrency format // Redirects from the /swap/:outputCurrency path to the /swap?outputCurrency=:outputCurrency format
export function RedirectToSwap(props: RouteComponentProps<{ outputCurrency: string }>) { export function RedirectToSwap() {
const { const location = useLocation()
location: { search }, const { search } = location
match: { const { outputCurrency } = useParams<{ outputCurrency: string }>()
params: { outputCurrency },
},
} = props
return ( return (
<Redirect <Redirect
to={{ to={{
...props.location, ...location,
pathname: '/swap', pathname: '/swap',
search: search:
search && search.length > 1 search && search.length > 1
...@@ -32,10 +30,10 @@ export function RedirectToSwap(props: RouteComponentProps<{ outputCurrency: stri ...@@ -32,10 +30,10 @@ export function RedirectToSwap(props: RouteComponentProps<{ outputCurrency: stri
) )
} }
export function OpenClaimAddressModalAndRedirectToSwap(props: RouteComponentProps) { export function OpenClaimAddressModalAndRedirectToSwap() {
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
useEffect(() => { useEffect(() => {
dispatch(setOpenModal(ApplicationModal.ADDRESS_CLAIM)) dispatch(setOpenModal(ApplicationModal.ADDRESS_CLAIM))
}, [dispatch]) }, [dispatch])
return <RedirectPathToSwapOnly {...props} /> return <RedirectPathToSwapOnly />
} }
...@@ -14,7 +14,7 @@ import ms from 'ms.macro' ...@@ -14,7 +14,7 @@ import ms from 'ms.macro'
import { useState } from 'react' import { useState } from 'react'
import { ArrowLeft } from 'react-feather' import { ArrowLeft } from 'react-feather'
import ReactMarkdown from 'react-markdown' import ReactMarkdown from 'react-markdown'
import { RouteComponentProps } from 'react-router-dom' import { useParams } from 'react-router-dom'
import styled from 'styled-components/macro' import styled from 'styled-components/macro'
import { ButtonPrimary } from '../../components/Button' import { ButtonPrimary } from '../../components/Button'
...@@ -152,11 +152,8 @@ function getDateFromBlock( ...@@ -152,11 +152,8 @@ function getDateFromBlock(
return undefined return undefined
} }
export default function VotePage({ export default function VotePage() {
match: { const { governorIndex, id } = useParams<{ governorIndex: string; id: string }>()
params: { governorIndex, id },
},
}: RouteComponentProps<{ governorIndex: string; id: string }>) {
const parsedGovernorIndex = Number.parseInt(governorIndex) const parsedGovernorIndex = Number.parseInt(governorIndex)
const { chainId, account } = useWeb3React() const { chainId, account } = useWeb3React()
......
...@@ -7,9 +7,15 @@ import VotePage from './VotePage' ...@@ -7,9 +7,15 @@ import VotePage from './VotePage'
export default function Vote() { export default function Vote() {
return ( return (
<> <>
<Route exact strict path="/vote/:governorIndex/:id" component={VotePage} /> <Route exact strict path="/vote/:governorIndex/:id">
<Route exact strict path="/vote/create-proposal" component={CreateProposal} /> <VotePage />
<Route exact strict path="/vote" component={Landing} /> </Route>
<Route exact strict path="/vote/create-proposal">
<CreateProposal />
</Route>
<Route exact strict path="/vote">
<Landing />
</Route>
</> </>
) )
} }
import { parse } from 'qs' import { parse } from 'qs'
import { useEffect } from 'react' import { useEffect } from 'react'
import { RouteComponentProps } from 'react-router-dom' import { useLocation } from 'react-router-dom'
import { useAppDispatch } from 'state/hooks' import { useAppDispatch } from 'state/hooks'
import { updateUserDarkMode } from '../state/user/reducer' import { updateUserDarkMode } from '../state/user/reducer'
export default function DarkModeQueryParamReader({ location: { search } }: RouteComponentProps): null { export default function DarkModeQueryParamReader(): null {
const { search } = useLocation()
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
useEffect(() => { useEffect(() => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment