Skip to content

Commit b021915

Browse files
committed
change open pool to landing page
1 parent 52136b1 commit b021915

File tree

2 files changed

+53
-39
lines changed

2 files changed

+53
-39
lines changed

src/components/EarnBanner/index.tsx

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import earnLargeBg from 'assets/images/earn_background_large.png'
88
import earnSmallBg from 'assets/images/earn_background_small.png'
99
import { APP_PATHS } from 'constants/index'
1010
import { useActiveWeb3React } from 'hooks'
11-
import useLiquidityWidget from 'pages/Earns/useLiquidityWidget'
1211
import { formatAprNumber } from 'pages/Earns/utils'
1312

1413
const EarnBannerContainer = styled.div`
@@ -183,7 +182,6 @@ export default function EarnBanner() {
183182
const navigate = useNavigate()
184183
const { account } = useActiveWeb3React()
185184
const { data } = useExplorerLandingQuery({ userAddress: account })
186-
const { liquidityWidget, handleOpenZapInWidget } = useLiquidityWidget()
187185

188186
const [index, setIndex] = useState(0)
189187
const [animate, setAnimate] = useState(false)
@@ -202,41 +200,38 @@ export default function EarnBanner() {
202200
}, [])
203201

204202
return (
205-
<>
206-
{liquidityWidget}
207-
<EarnBannerContainer>
208-
<EarnBannerWrapper onClick={() => navigate({ pathname: APP_PATHS.EARN })}>
209-
<Description>
210-
Explore and Add Liquidity to High-APR Pools <PrimaryText>Instantly</PrimaryText> with{' '}
211-
<PrimaryText>Any Token(s)</PrimaryText> or <PrimaryText>Position</PrimaryText> you choose!
212-
</Description>
213-
<PoolButton
214-
animate={animate}
215-
onClick={e => {
216-
if (!pool) return
217-
e.stopPropagation()
218-
handleOpenZapInWidget({ exchange: pool.exchange, chainId: pool.chainId, address: pool.address })
219-
}}
220-
>
221-
{!!pool && (
222-
<>
223-
<Flex>
224-
<TokenImage src={pool.tokens[0].logoURI} alt="" />
225-
<TokenImage src={pool.tokens[1].logoURI} alt="" />
226-
<Text fontSize={18} marginLeft={2}>
227-
{pool.tokens[0].symbol}/{pool.tokens[1].symbol}
228-
</Text>
229-
</Flex>
230-
<PoolAprWrapper>
231-
<PoolApr>
232-
{formatAprNumber(pool.apr)}% <AprText>APR</AprText>
233-
</PoolApr>
234-
</PoolAprWrapper>
235-
</>
236-
)}
237-
</PoolButton>
238-
</EarnBannerWrapper>
239-
</EarnBannerContainer>
240-
</>
203+
<EarnBannerContainer>
204+
<EarnBannerWrapper onClick={() => navigate({ pathname: APP_PATHS.EARN })}>
205+
<Description>
206+
Explore and Add Liquidity to High-APR Pools <PrimaryText>Instantly</PrimaryText> with{' '}
207+
<PrimaryText>Any Token(s)</PrimaryText> or <PrimaryText>Position</PrimaryText> you choose!
208+
</Description>
209+
<PoolButton
210+
animate={animate}
211+
onClick={e => {
212+
if (!pool) return
213+
e.stopPropagation()
214+
navigate({ pathname: APP_PATHS.EARN, search: `?openPool=${index}` })
215+
}}
216+
>
217+
{!!pool && (
218+
<>
219+
<Flex>
220+
<TokenImage src={pool.tokens[0].logoURI} alt="" />
221+
<TokenImage src={pool.tokens[1].logoURI} alt="" />
222+
<Text fontSize={18} marginLeft={2}>
223+
{pool.tokens[0].symbol}/{pool.tokens[1].symbol}
224+
</Text>
225+
</Flex>
226+
<PoolAprWrapper>
227+
<PoolApr>
228+
{formatAprNumber(pool.apr)}% <AprText>APR</AprText>
229+
</PoolApr>
230+
</PoolAprWrapper>
231+
</>
232+
)}
233+
</PoolButton>
234+
</EarnBannerWrapper>
235+
</EarnBannerContainer>
241236
)
242237
}

src/pages/Earns/index.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ChainId } from '@kyberswap/ks-sdk-core'
22
import { rgba } from 'polished'
3-
import { useNavigate } from 'react-router-dom'
3+
import { useEffect } from 'react'
4+
import { useNavigate, useSearchParams } from 'react-router-dom'
45
import { useMedia } from 'react-use'
56
import { Box, Flex, Text } from 'rebass'
67
import { EarnPool, useExplorerLandingQuery } from 'services/zapEarn'
@@ -285,9 +286,11 @@ const Card = ({
285286

286287
export default function Earns() {
287288
const navigate = useNavigate()
289+
const [searchParams, setSearchParams] = useSearchParams()
288290
const theme = useTheme()
289291
const { account } = useActiveWeb3React()
290292
const { isLoading, data } = useExplorerLandingQuery({ userAddress: account })
293+
const { liquidityWidget, handleOpenZapInWidget } = useLiquidityWidget()
291294

292295
const title = (title: string, tooltip: string, icon: string) => (
293296
<>
@@ -316,8 +319,24 @@ export default function Earns() {
316319
const upToSmall = useMedia(`(max-width: ${MEDIA_WIDTHS.upToSmall}px)`)
317320
const upToXXSmall = useMedia(`(max-width: ${MEDIA_WIDTHS.upToXXSmall}px)`)
318321

322+
useEffect(() => {
323+
const openPool = searchParams.get('openPool')
324+
const openPoolIndex = parseInt(openPool || '', 10)
325+
326+
if (!isNaN(openPoolIndex) && highlightedPools.length && highlightedPools[openPoolIndex]) {
327+
searchParams.delete('openPool')
328+
setSearchParams(searchParams)
329+
handleOpenZapInWidget({
330+
exchange: highlightedPools[openPoolIndex].exchange,
331+
chainId: highlightedPools[openPoolIndex].chainId,
332+
address: highlightedPools[openPoolIndex].address,
333+
})
334+
}
335+
}, [handleOpenZapInWidget, highlightedPools, searchParams, setSearchParams])
336+
319337
return (
320338
<WrapperBg>
339+
{liquidityWidget}
321340
<Container>
322341
<Text fontSize={36} fontWeight="500">
323342
Maximize Your Earnings in DeFi

0 commit comments

Comments
 (0)