From 511543603a7cc707136fe1f0f0f156cd67c7e298 Mon Sep 17 00:00:00 2001 From: Piotr Matlak Date: Tue, 26 Mar 2024 08:18:43 +0100 Subject: [PATCH 01/11] add refresh buttons for new position and position details --- src/components/NewPosition/NewPosition.tsx | 31 +++++++-- src/components/NewPosition/style.ts | 45 +++++++++++- .../PositionDetails/PositionDetails.tsx | 17 +++-- .../SinglePositionInfo/SinglePositionInfo.tsx | 1 - src/components/PositionDetails/style.ts | 27 +++++++- .../NewPositionWrapper/NewPositionWrapper.tsx | 68 +++++++++++++++++++ .../SinglePositionWrapper.tsx | 34 +++++++++- src/store/reducers/solanaWallet.ts | 3 + src/store/sagas/wallet.ts | 14 +++- 9 files changed, 223 insertions(+), 17 deletions(-) diff --git a/src/components/NewPosition/NewPosition.tsx b/src/components/NewPosition/NewPosition.tsx index ffc089146..2b109cdfd 100644 --- a/src/components/NewPosition/NewPosition.tsx +++ b/src/components/NewPosition/NewPosition.tsx @@ -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 { @@ -105,6 +106,7 @@ export interface INewPosition { currentFeeIndex: number onSlippageChange: (slippage: string) => void initialSlippage: string + handleRefresh: () => void } export const NewPosition: React.FC = ({ @@ -156,7 +158,8 @@ export const NewPosition: React.FC = ({ plotVolumeRange, currentFeeIndex, onSlippageChange, - initialSlippage + initialSlippage, + handleRefresh }) => { const classes = useStyles() @@ -358,9 +361,29 @@ export const NewPosition: React.FC = ({ - - Add new liquidity position - + + + Add new liquidity position + + + {address !== '' ? ( ({ title: { color: colors.white.main, ...typography.heading4, - marginBottom: 18, [theme.breakpoints.down('xs')]: { fontSize: 18 @@ -85,11 +84,53 @@ 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' + } + }, + 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' + } } })) diff --git a/src/components/PositionDetails/PositionDetails.tsx b/src/components/PositionDetails/PositionDetails.tsx index f1b2ef69a..6598ad523 100644 --- a/src/components/PositionDetails/PositionDetails.tsx +++ b/src/components/PositionDetails/PositionDetails.tsx @@ -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' @@ -46,6 +47,7 @@ interface IProps { max: number } userHasStakes?: boolean + handleRefresh: () => void } const PositionDetails: React.FC = ({ @@ -73,7 +75,8 @@ const PositionDetails: React.FC = ({ hasTicksError, reloadHandler, plotVolumeRange, - userHasStakes = false + userHasStakes = false, + handleRefresh }) => { const classes = useStyles() @@ -108,17 +111,16 @@ const PositionDetails: React.FC = ({ container item direction='column' - alignItems='flex-end' + alignItems='center' className={classes.right} wrap='nowrap'> + diff --git a/src/components/PositionDetails/SinglePositionInfo/SinglePositionInfo.tsx b/src/components/PositionDetails/SinglePositionInfo/SinglePositionInfo.tsx index 0b6689728..3ce145144 100644 --- a/src/components/PositionDetails/SinglePositionInfo/SinglePositionInfo.tsx +++ b/src/components/PositionDetails/SinglePositionInfo/SinglePositionInfo.tsx @@ -96,7 +96,6 @@ const SinglePositionInfo: React.FC = ({ Close position - {' '} @@ -537,6 +543,7 @@ export const NewPosition: React.FC = ({ priceALoading={priceALoading} priceBLoading={priceBLoading} feeTierIndex={currentFeeIndex} + setShouldResetPlot={setShouldResetPlot} /> {isCurrentPoolExisting || @@ -579,6 +586,8 @@ export const NewPosition: React.FC = ({ hasTicksError={hasTicksError} reloadHandler={reloadHandler} volumeRange={plotVolumeRange} + shouldResetPlot={shouldResetPlot} + setShouldResetPlot={setShouldResetPlot} /> ) : ( void } export const RangeSelector: React.FC = ({ @@ -65,7 +67,9 @@ export const RangeSelector: React.FC = ({ poolIndex, hasTicksError, reloadHandler, - volumeRange + volumeRange, + shouldResetPlot, + setShouldResetPlot }) => { const classes = useStyles() @@ -208,10 +212,11 @@ export const RangeSelector: React.FC = ({ }, [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) diff --git a/src/components/NewPosition/style.ts b/src/components/NewPosition/style.ts index 2cf4da18a..44181fba7 100644 --- a/src/components/NewPosition/style.ts +++ b/src/components/NewPosition/style.ts @@ -103,8 +103,11 @@ const useStyles = makeStyles((theme: Theme) => ({ minWidth: 'auto', background: 'none', marginRight: 7, - '& :hover': { + '&:hover': { background: 'none' + }, + '&:disabled': { + opacity: 0.5 } }, refreshIcon: { From b4b0830df5e5d1eda0e22d4121affcabcb46ec54 Mon Sep 17 00:00:00 2001 From: Piotr Matlak Date: Fri, 5 Apr 2024 16:06:12 +0200 Subject: [PATCH 08/11] add refreshing global price, fix chart reseting --- src/components/NewPosition/NewPosition.tsx | 4 ++-- .../RangeSelector/RangeSelector.tsx | 2 +- .../PriceRangePlot/PriceRangePlot.tsx | 2 +- .../NewPositionWrapper/NewPositionWrapper.tsx | 19 +++++++++++++------ .../SinglePositionWrapper.tsx | 8 +++++++- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/components/NewPosition/NewPosition.tsx b/src/components/NewPosition/NewPosition.tsx index bab14114d..ec0d23088 100644 --- a/src/components/NewPosition/NewPosition.tsx +++ b/src/components/NewPosition/NewPosition.tsx @@ -204,8 +204,8 @@ export const NewPosition: React.FC = ({ .fill(1) .map((_e, index) => ({ x: index, y: index, index })), midPrice: { - x: 50, - index: 50 + x: 0, + index: 0 }, tokenASymbol: 'ABC', tokenBSymbol: 'XYZ' diff --git a/src/components/NewPosition/RangeSelector/RangeSelector.tsx b/src/components/NewPosition/RangeSelector/RangeSelector.tsx index e533f940d..acfc6d34e 100644 --- a/src/components/NewPosition/RangeSelector/RangeSelector.tsx +++ b/src/components/NewPosition/RangeSelector/RangeSelector.tsx @@ -214,7 +214,7 @@ export const RangeSelector: React.FC = ({ }, [currentPairReversed]) useEffect(() => { - if (poolIndex !== null && shouldResetPlot) { + if (ticksLoading && shouldResetPlot && midPrice.index !== 0) { resetPlot() setShouldResetPlot(false) } diff --git a/src/components/PriceRangePlot/PriceRangePlot.tsx b/src/components/PriceRangePlot/PriceRangePlot.tsx index eee0a09a4..8d3942f79 100644 --- a/src/components/PriceRangePlot/PriceRangePlot.tsx +++ b/src/components/PriceRangePlot/PriceRangePlot.tsx @@ -503,11 +503,11 @@ export const PriceRangePlot: React.FC = ({ 'markers', 'areas', 'lines', - lazyLoadingLayer, globalPriceLayer, currentLayer, volumeRangeLayer, brushLayer, + lazyLoadingLayer, 'axes', 'legends' ]} diff --git a/src/containers/NewPositionWrapper/NewPositionWrapper.tsx b/src/containers/NewPositionWrapper/NewPositionWrapper.tsx index 68b068456..6e03b6b9f 100644 --- a/src/containers/NewPositionWrapper/NewPositionWrapper.tsx +++ b/src/containers/NewPositionWrapper/NewPositionWrapper.tsx @@ -327,7 +327,8 @@ export const NewPositionWrapper: React.FC = ({ const [tokenBPriceData, setTokenBPriceData] = useState(undefined) const [priceBLoading, setPriceBLoading] = useState(false) - useEffect(() => { + + const getGlobalPrice = () => { if (tokenAIndex === null || tokenBIndex === null) { return } @@ -342,6 +343,10 @@ export const NewPositionWrapper: React.FC = ({ } else { setGlobalPrice(undefined) } + } + + useEffect(() => { + getGlobalPrice() }, [tokenAIndex, tokenBIndex]) useEffect(() => { @@ -434,8 +439,8 @@ export const NewPositionWrapper: React.FC = ({ } dispatch(solanaWallet.getBalance()) - const idA = tokens[tokenAIndex].coingeckoId ?? '' - if (idA.length) { + const idA = tokens[tokenAIndex].assetAddress.toString() ?? '' + if (idA) { setPriceALoading(true) await getJupTokenPrice(idA) .then(data => setTokenAPriceData(data)) @@ -445,10 +450,10 @@ export const NewPositionWrapper: React.FC = ({ setTokenAPriceData(undefined) } - const idB = tokens[tokenBIndex].coingeckoId ?? '' - if (idB.length) { + const idB = tokens[tokenBIndex].assetAddress.toString() ?? '' + if (idB) { setPriceBLoading(true) - await getJupTokenPrice(idB) + getJupTokenPrice(idB) .then(data => setTokenBPriceData(data)) .catch(() => setTokenBPriceData(undefined)) .finally(() => setPriceBLoading(false)) @@ -492,6 +497,8 @@ export const NewPositionWrapper: React.FC = ({ ) } } + + getGlobalPrice() } return ( diff --git a/src/containers/SinglePositionWrapper/SinglePositionWrapper.tsx b/src/containers/SinglePositionWrapper/SinglePositionWrapper.tsx index 90a83fd5e..d75eac853 100644 --- a/src/containers/SinglePositionWrapper/SinglePositionWrapper.tsx +++ b/src/containers/SinglePositionWrapper/SinglePositionWrapper.tsx @@ -343,7 +343,7 @@ export const SinglePositionWrapper: React.FC = ({ id }) => { } }, [position?.id]) - useEffect(() => { + const getGlobalPrice = () => { if (!position) { return } @@ -364,6 +364,10 @@ export const SinglePositionWrapper: React.FC = ({ id }) => { } else { setGlobalPrice(undefined) } + } + + useEffect(() => { + getGlobalPrice() }, [xToY, position?.tokenX, position?.tokenY]) const copyPoolAddressHandler = (message: string, variant: Color) => { @@ -404,6 +408,8 @@ export const SinglePositionWrapper: React.FC = ({ id }) => { }) ) ) + + getGlobalPrice() } } From 8f06a8ce7c6b95854156e23096b3a979aea3483d Mon Sep 17 00:00:00 2001 From: Piotr Matlak Date: Mon, 8 Apr 2024 10:27:14 +0200 Subject: [PATCH 09/11] add loader for refresh wallet balance --- .../DepositAmountInput/DepositAmountInput.tsx | 24 ++++++++++++------- .../Inputs/DepositAmountInput/style.ts | 5 ++++ .../DepositSelector/DepositSelector.tsx | 6 ++++- src/components/NewPosition/NewPosition.tsx | 5 +++- .../NewPositionWrapper/NewPositionWrapper.tsx | 10 +++++++- .../SinglePositionWrapper.tsx | 7 ++++-- 6 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/components/Inputs/DepositAmountInput/DepositAmountInput.tsx b/src/components/Inputs/DepositAmountInput/DepositAmountInput.tsx index ef2f218e5..137167178 100644 --- a/src/components/Inputs/DepositAmountInput/DepositAmountInput.tsx +++ b/src/components/Inputs/DepositAmountInput/DepositAmountInput.tsx @@ -21,6 +21,7 @@ interface IProps { balanceValue?: string disabled?: boolean priceLoading?: boolean + isBalanceLoading: boolean } export const DepositAmountInput: React.FC = ({ @@ -38,7 +39,8 @@ export const DepositAmountInput: React.FC = ({ tokenPrice, balanceValue, disabled = false, - priceLoading = false + priceLoading = false, + isBalanceLoading }) => { const classes = useStyles() @@ -145,6 +147,13 @@ export const DepositAmountInput: React.FC = ({ const usdBalance = tokenPrice && balanceValue ? tokenPrice * +balanceValue : 0 + const formattedBalance = currency + ? `${ + balanceValue + ? formatNumbers(thresholds)(balanceValue) + showPrefix(Number(balanceValue)) + : '0' + } ${currency}` + : '- -' return (
@@ -199,14 +208,11 @@ export const DepositAmountInput: React.FC = ({ <> Balance:{' '} - {currency - ? `${ - balanceValue - ? formatNumbers(thresholds)(balanceValue) + - showPrefix(Number(balanceValue)) - : '0' - } ${currency}` - : '- -'} + {isBalanceLoading ? ( + + ) : ( + <>{' '.concat(formattedBalance)} + )}