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

add refresh buttons for new position and position details #641

Draft
wants to merge 17 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 7 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
5 changes: 3 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ ServiceWorker.ts
react-app-env.d.ts
config-overrides.js
build
dist
dist
vite.config.ts
.eslintrc.js
.eslintrc.js
storybook-static
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface IDepositSelector {
priceALoading?: boolean
priceBLoading?: boolean
feeTierIndex: number
setShouldResetPlot: (val: boolean) => void
}

export const DepositSelector: React.FC<IDepositSelector> = ({
Expand Down Expand Up @@ -88,7 +89,8 @@ export const DepositSelector: React.FC<IDepositSelector> = ({
onHideUnknownTokensChange,
priceALoading,
priceBLoading,
feeTierIndex
feeTierIndex,
setShouldResetPlot
}) => {
const classes = useStyles()

Expand Down Expand Up @@ -206,6 +208,7 @@ export const DepositSelector: React.FC<IDepositSelector> = ({
tokens={tokens}
current={tokenAIndex !== null ? tokens[tokenAIndex] : null}
onSelect={index => {
setShouldResetPlot(true)
setTokenAIndex(index)
setPositionTokens(index, tokenBIndex, feeTierIndex)
}}
Expand Down Expand Up @@ -241,6 +244,7 @@ export const DepositSelector: React.FC<IDepositSelector> = ({
tokens={tokens}
current={tokenBIndex !== null ? tokens[tokenBIndex] : null}
onSelect={index => {
setShouldResetPlot(true)
setTokenBIndex(index)
setPositionTokens(tokenAIndex, index, feeTierIndex)
}}
Expand All @@ -258,6 +262,7 @@ export const DepositSelector: React.FC<IDepositSelector> = ({
<FeeSwitch
onSelect={fee => {
setPositionTokens(tokenAIndex, tokenBIndex, fee)
setShouldResetPlot(true)
}}
feeTiers={feeTiers}
showOnlyPercents
Expand Down
40 changes: 36 additions & 4 deletions src/components/NewPosition/NewPosition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import DepositSelector from './DepositSelector/DepositSelector'
import MarketIdLabel from './MarketIdLabel/MarketIdLabel'
import PoolInit from './PoolInit/PoolInit'
import RangeSelector from './RangeSelector/RangeSelector'
import refreshIcon from '@static/svg/refresh.svg'
import useStyles from './style'

export interface INewPosition {
Expand Down Expand Up @@ -105,6 +106,7 @@ export interface INewPosition {
currentFeeIndex: number
onSlippageChange: (slippage: string) => void
initialSlippage: string
handleRefresh: () => void
}

export const NewPosition: React.FC<INewPosition> = ({
Expand Down Expand Up @@ -156,7 +158,8 @@ export const NewPosition: React.FC<INewPosition> = ({
plotVolumeRange,
currentFeeIndex,
onSlippageChange,
initialSlippage
initialSlippage,
handleRefresh
}) => {
const classes = useStyles()

Expand All @@ -175,6 +178,9 @@ export const NewPosition: React.FC<INewPosition> = ({
const [settings, setSettings] = React.useState<boolean>(false)
const [slippTolerance, setSlippTolerance] = React.useState<string>(initialSlippage)
const [anchorEl, setAnchorEl] = React.useState<HTMLButtonElement | null>(null)

const [shouldResetPlot, setShouldResetPlot] = useState(true)

const setRangeBlockerInfo = () => {
if (tokenAIndex === null || tokenBIndex === null) {
return 'Select tokens to set price range.'
Expand Down Expand Up @@ -358,9 +364,32 @@ export const NewPosition: React.FC<INewPosition> = ({
</Grid>
</Link>

<Grid container justifyContent='space-between'>
<Typography className={classes.title}>Add new liquidity position</Typography>
<Grid container item alignItems='center' className={classes.options}>
<Grid
container
item
className={classes.subHeader}
alignItems='center'
justifyContent='space-between'>
<Grid
container
item
alignItems='center'
justifyContent='space-between'
className={classes.leftSideSubHeader}>
<Typography className={classes.title}>Add new liquidity position</Typography>
<Button
disabled={tokenAIndex === null || tokenBIndex === null}
onClick={handleRefresh}
className={classes.refreshIconBtn}>
<img src={refreshIcon} className={classes.refreshIcon} />
</Button>
</Grid>
<Grid
container
item
alignItems='center'
justifyContent='flex-end'
className={classes.options}>
{address !== '' ? (
<MarketIdLabel
displayLength={9}
Expand Down Expand Up @@ -514,6 +543,7 @@ export const NewPosition: React.FC<INewPosition> = ({
priceALoading={priceALoading}
priceBLoading={priceBLoading}
feeTierIndex={currentFeeIndex}
setShouldResetPlot={setShouldResetPlot}
/>

{isCurrentPoolExisting ||
Expand Down Expand Up @@ -556,6 +586,8 @@ export const NewPosition: React.FC<INewPosition> = ({
hasTicksError={hasTicksError}
reloadHandler={reloadHandler}
volumeRange={plotVolumeRange}
shouldResetPlot={shouldResetPlot}
setShouldResetPlot={setShouldResetPlot}
/>
) : (
<PoolInit
Expand Down
11 changes: 8 additions & 3 deletions src/components/NewPosition/RangeSelector/RangeSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export interface IRangeSelector {
min: number
max: number
}
shouldResetPlot: boolean
setShouldResetPlot: (val: boolean) => void
}

export const RangeSelector: React.FC<IRangeSelector> = ({
Expand All @@ -65,7 +67,9 @@ export const RangeSelector: React.FC<IRangeSelector> = ({
poolIndex,
hasTicksError,
reloadHandler,
volumeRange
volumeRange,
shouldResetPlot,
setShouldResetPlot
}) => {
const classes = useStyles()

Expand Down Expand Up @@ -208,10 +212,11 @@ export const RangeSelector: React.FC<IRangeSelector> = ({
}, [currentPairReversed])

useEffect(() => {
if (ticksLoading) {
if (poolIndex !== null && shouldResetPlot) {
resetPlot()
setShouldResetPlot(false)
}
}, [ticksLoading, midPrice])
}, [ticksLoading, midPrice, poolIndex])

const autoZoomHandler = (left: number, right: number, canZoomCloser: boolean = false) => {
const leftX = calcPrice(left, isXtoY, xDecimal, yDecimal)
Expand Down
48 changes: 46 additions & 2 deletions src/components/NewPosition/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const useStyles = makeStyles((theme: Theme) => ({
title: {
color: colors.white.main,
...typography.heading4,
marginBottom: 18,

[theme.breakpoints.down('xs')]: {
fontSize: 18
Expand Down Expand Up @@ -85,11 +84,56 @@ const useStyles = makeStyles((theme: Theme) => ({
},
options: {
width: 'fit-content',
marginBottom: 18,
marginBottom: 16,
height: 28
},
switch: {
transition: 'opacity 500ms'
},
jupiterIcon: {
cursor: 'pointer',
transition: 'filter 100ms',
'&:hover': {
filter: 'brightness(1.5)'
}
},
refreshIconBtn: {
padding: 0,
margin: 0,
minWidth: 'auto',
background: 'none',
marginRight: 7,
'&:hover': {
background: 'none'
},
'&:disabled': {
opacity: 0.5
}
},
refreshIcon: {
width: 26,
height: 21,
cursor: 'pointer',
transition: 'filter 100ms',
'&:hover': {
filter: 'brightness(1.5)'
}
},
subHeader: {
alignItems: 'center',

[theme.breakpoints.down('sm')]: {
justifyContent: 'flex-start'
}
},
leftSideSubHeader: {
marginBottom: 16,
width: 'calc(50% - 12px)',

[theme.breakpoints.down('sm')]: {
flex: 'initial',
width: 'auto'
}
}
}))

Expand Down
20 changes: 14 additions & 6 deletions src/components/PositionDetails/PositionDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Link, useHistory } from 'react-router-dom'
import { ILiquidityToken } from './SinglePositionInfo/consts'
import SinglePositionPlot from './SinglePositionPlot/SinglePositionPlot'
import useStyles from './style'
import refreshIcon from '@static/svg/refresh.svg'

import MarketIdLabel from '@components/NewPosition/MarketIdLabel/MarketIdLabel'
import { Color } from '@material-ui/lab'
Expand All @@ -39,13 +40,15 @@ interface IProps {
initialIsDiscreteValue: boolean
onDiscreteChange: (val: boolean) => void
showFeesLoader?: boolean
showLiquidityLoader?: boolean
hasTicksError?: boolean
reloadHandler: () => void
plotVolumeRange?: {
min: number
max: number
}
userHasStakes?: boolean
handleRefresh: () => void
}

const PositionDetails: React.FC<IProps> = ({
Expand All @@ -70,10 +73,12 @@ const PositionDetails: React.FC<IProps> = ({
initialIsDiscreteValue,
onDiscreteChange,
showFeesLoader = false,
showLiquidityLoader = false,
hasTicksError,
reloadHandler,
plotVolumeRange,
userHasStakes = false
userHasStakes = false,
handleRefresh
}) => {
const classes = useStyles()

Expand All @@ -100,6 +105,7 @@ const PositionDetails: React.FC<IProps> = ({
xToY={xToY}
swapHandler={() => setXToY(!xToY)}
showFeesLoader={showFeesLoader}
showLiquidityLoader={showLiquidityLoader}
userHasStakes={userHasStakes}
/>
</Grid>
Expand All @@ -108,17 +114,16 @@ const PositionDetails: React.FC<IProps> = ({
container
item
direction='column'
alignItems='flex-end'
alignItems='center'
className={classes.right}
wrap='nowrap'>
<Grid
container
item
direction='row'
alignItems='flex-end'
alignItems='center'
// justifyContent='space-between'
style={{ paddingLeft: 20, flexDirection: 'row-reverse' }}
className={classes.right}
className={classes.rightSubHeader}
wrap='nowrap'>
<Hidden xsDown>
<Button
Expand All @@ -134,11 +139,14 @@ const PositionDetails: React.FC<IProps> = ({
<span className={classes.buttonText}>+ Add Liquidity</span>
</Button>
</Hidden>
<Button onClick={handleRefresh} className={classes.refreshIconBtn}>
<img src={refreshIcon} className={classes.refreshIcon} />
</Button>
<MarketIdLabel
marketId={poolAddress.toString()}
displayLength={9}
copyPoolAddressHandler={copyPoolAddressHandler}
style={{ paddingBottom: 20, paddingRight: 10 }}
style={{ paddingTop: '6px' }}
/>
</Grid>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface IProp {
xToY: boolean
swapHandler: () => void
showFeesLoader?: boolean
showLiquidityLoader?: boolean
userHasStakes?: boolean
}

Expand All @@ -30,6 +31,7 @@ const SinglePositionInfo: React.FC<IProp> = ({
xToY,
swapHandler,
showFeesLoader = false,
showLiquidityLoader = false,
userHasStakes = false
}) => {
const history = useHistory()
Expand Down Expand Up @@ -96,7 +98,6 @@ const SinglePositionInfo: React.FC<IProp> = ({
Close position
</Button>
<Hidden smUp>
{' '}
<Button
className={classes.button}
variant='contained'
Expand All @@ -119,6 +120,7 @@ const SinglePositionInfo: React.FC<IProp> = ({
}
showBalance
swapHandler={swapHandler}
showLoader={showLiquidityLoader}
/>
<BoxInfo
title={'Unclaimed fees'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const SinglePositionPlot: React.FC<ISinglePositionPlot> = ({
xDecimal={tokenX.decimal}
yDecimal={tokenY.decimal}
isDiscrete={isPlotDiscrete}
coverOnLoading
coverOnLoading={true}
hasError={hasTicksError}
reloadHandler={reloadHandler}
volumeRange={volumeRange}
Expand Down
Loading
Loading