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

remove redirect after disconnecting wallet on position details #665

Merged
Changes from 2 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
196 changes: 112 additions & 84 deletions src/containers/SinglePositionWrapper/SinglePositionWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import React, { useEffect, useMemo, useState } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { useHistory } from 'react-router'
import useStyles from './style'
import { Redirect } from 'react-router-dom'

export interface IProps {
id: string
Expand Down Expand Up @@ -67,6 +68,8 @@ export const SinglePositionWrapper: React.FC<IProps> = ({ id }) => {

const [showFeesLoader, setShowFeesLoader] = useState(true)

const [isFinishedDelayRender, setIsFinishedDelayRender] = useState(false)

useEffect(() => {
if (position?.id && waitingForTicksData === null) {
setWaitingForTicksData(true)
Expand Down Expand Up @@ -374,92 +377,117 @@ export const SinglePositionWrapper: React.FC<IProps> = ({ id }) => {
}

useEffect(() => {
if (!position) {
history.push('/pool')
const timer = setTimeout(() => {
setIsFinishedDelayRender(true)
}, 1000)

return () => {
clearTimeout(timer)
}
}, [position])
}, [walletStatus])

return !isLoadingList && position ? (
<PositionDetails
tokenXAddress={position.tokenX.assetAddress}
tokenYAddress={position.tokenY.assetAddress}
poolAddress={position.poolData.address}
copyPoolAddressHandler={copyPoolAddressHandler}
detailsData={data}
midPrice={midPrice}
leftRange={leftRange}
rightRange={rightRange}
currentPrice={current}
onClickClaimFee={() => {
dispatch(actions.claimFee(position.positionIndex))
}}
closePosition={claimFarmRewards => {
dispatch(
actions.closePosition({
positionIndex: position.positionIndex,
onSuccess: () => {
history.push('/pool')
},
claimFarmRewards
})
)
}}
ticksLoading={ticksLoading}
tickSpacing={position?.poolData.tickSpacing ?? 1}
tokenX={{
name: position.tokenX.symbol,
icon: position.tokenX.logoURI,
decimal: position.tokenX.decimals,
balance: +printBN(position.tokenX.balance, position.tokenX.decimals),
liqValue: tokenXLiquidity,
claimValue: tokenXClaim,
usdValue:
typeof tokenXPriceData?.price === 'undefined'
? undefined
: tokenXPriceData.price * +printBN(position.tokenX.balance, position.tokenX.decimals)
}}
tokenXPriceData={tokenXPriceData}
tokenY={{
name: position.tokenY.symbol,
icon: position.tokenY.logoURI,
decimal: position.tokenY.decimals,
balance: +printBN(position.tokenY.balance, position.tokenY.decimals),
liqValue: tokenYLiquidity,
claimValue: tokenYClaim,
usdValue:
typeof tokenYPriceData?.price === 'undefined'
? undefined
: tokenYPriceData.price * +printBN(position.tokenY.balance, position.tokenY.decimals)
}}
tokenYPriceData={tokenYPriceData}
fee={position.poolData.fee}
min={min}
max={max}
initialIsDiscreteValue={initialIsDiscreteValue}
onDiscreteChange={setIsDiscreteValue}
showFeesLoader={showFeesLoader}
hasTicksError={hasTicksError}
reloadHandler={() => {
dispatch(
actions.getCurrentPlotTicks({
poolIndex: position.poolData.poolIndex,
isXtoY: true
})
)
}}
plotVolumeRange={currentVolumeRange}
userHasStakes={!!positionStakes.length}
globalPrice={globalPrice}
xToY={xToY}
setXToY={setXToY}
/>
) : isLoadingList ? (
<Grid container>
<img src={loader} className={classes.loading} />
</Grid>
) : !position ? (
<Grid container justifyContent='center'>
useEffect(() => {
if (isFinishedDelayRender) {
setIsFinishedDelayRender(false)
}
}, [walletStatus])

if (!isLoadingList && position) {
return (
<PositionDetails
tokenXAddress={position.tokenX.assetAddress}
tokenYAddress={position.tokenY.assetAddress}
poolAddress={position.poolData.address}
copyPoolAddressHandler={copyPoolAddressHandler}
detailsData={data}
midPrice={midPrice}
leftRange={leftRange}
rightRange={rightRange}
currentPrice={current}
onClickClaimFee={() => {
dispatch(actions.claimFee(position.positionIndex))
}}
closePosition={claimFarmRewards => {
dispatch(
actions.closePosition({
positionIndex: position.positionIndex,
onSuccess: () => {
history.push('/pool')
},
claimFarmRewards
})
)
}}
ticksLoading={ticksLoading}
tickSpacing={position?.poolData.tickSpacing ?? 1}
tokenX={{
name: position.tokenX.symbol,
icon: position.tokenX.logoURI,
decimal: position.tokenX.decimals,
balance: +printBN(position.tokenX.balance, position.tokenX.decimals),
liqValue: tokenXLiquidity,
claimValue: tokenXClaim,
usdValue:
typeof tokenXPriceData?.price === 'undefined'
? undefined
: tokenXPriceData.price * +printBN(position.tokenX.balance, position.tokenX.decimals)
}}
tokenXPriceData={tokenXPriceData}
tokenY={{
name: position.tokenY.symbol,
icon: position.tokenY.logoURI,
decimal: position.tokenY.decimals,
balance: +printBN(position.tokenY.balance, position.tokenY.decimals),
liqValue: tokenYLiquidity,
claimValue: tokenYClaim,
usdValue:
typeof tokenYPriceData?.price === 'undefined'
? undefined
: tokenYPriceData.price * +printBN(position.tokenY.balance, position.tokenY.decimals)
}}
tokenYPriceData={tokenYPriceData}
fee={position.poolData.fee}
min={min}
max={max}
initialIsDiscreteValue={initialIsDiscreteValue}
onDiscreteChange={setIsDiscreteValue}
showFeesLoader={showFeesLoader}
hasTicksError={hasTicksError}
reloadHandler={() => {
dispatch(
actions.getCurrentPlotTicks({
poolIndex: position.poolData.poolIndex,
isXtoY: true
})
)
}}
plotVolumeRange={currentVolumeRange}
userHasStakes={!!positionStakes.length}
globalPrice={globalPrice}
xToY={xToY}
setXToY={setXToY}
/>
)
}

if (
isLoadingList ||
(!position && walletStatus === Status.Uninitialized && !isFinishedDelayRender)
) {
return (
<Grid container>
<img src={loader} className={classes.loading} />
</Grid>
)
}

if (!position && walletStatus === Status.Initialized && isFinishedDelayRender) {
return <Redirect to='/pool' />
}

return (
<Grid container justifyContent='center' alignItems='center'>
<EmptyPlaceholder desc='Position does not exist in your list!' />
</Grid>
) : null
)
}
Loading