diff --git a/src/components/Modals/Slippage/Slippage.stories.tsx b/src/components/Modals/Slippage/Slippage.stories.tsx index 084b58c47..0af7d7772 100644 --- a/src/components/Modals/Slippage/Slippage.stories.tsx +++ b/src/components/Modals/Slippage/Slippage.stories.tsx @@ -14,6 +14,7 @@ storiesOf('newUi/swap', module) handleClose={() => {}} anchorEl={null} defaultSlippage={'1'} + initialSlippage='2' /> )) diff --git a/src/components/Modals/Slippage/Slippage.tsx b/src/components/Modals/Slippage/Slippage.tsx index 4da854c2d..77d2ca4a8 100644 --- a/src/components/Modals/Slippage/Slippage.tsx +++ b/src/components/Modals/Slippage/Slippage.tsx @@ -8,6 +8,7 @@ interface Props { handleClose: () => void anchorEl: HTMLButtonElement | null defaultSlippage: string + initialSlippage: string infoText?: string headerText?: string } @@ -18,11 +19,12 @@ const Slippage: React.FC = ({ handleClose, anchorEl, defaultSlippage, + initialSlippage, infoText, headerText }) => { const classes = useStyles() - const [slippTolerance, setSlippTolerance] = React.useState('1') + const [slippTolerance, setSlippTolerance] = React.useState(initialSlippage) const inputRef = React.useRef(null) const allowOnlyDigitsAndTrimUnnecessaryZeros: React.ChangeEventHandler< diff --git a/src/components/NewPosition/NewPosition.stories.tsx b/src/components/NewPosition/NewPosition.stories.tsx index 5503a7cd0..60720884a 100644 --- a/src/components/NewPosition/NewPosition.stories.tsx +++ b/src/components/NewPosition/NewPosition.stories.tsx @@ -135,6 +135,8 @@ storiesOf('position/newPosition', module) onHideUnknownTokensChange={() => {}} reloadHandler={() => {}} currentFeeIndex={feeIndex} + onSlippageChange={() => {}} + initialSlippage={'1'} /> ) @@ -219,6 +221,8 @@ storiesOf('position/newPosition', module) onHideUnknownTokensChange={() => {}} reloadHandler={() => {}} currentFeeIndex={feeIndex} + onSlippageChange={() => {}} + initialSlippage={'1'} /> ) diff --git a/src/components/NewPosition/NewPosition.tsx b/src/components/NewPosition/NewPosition.tsx index e13e7c3be..94e268bfe 100644 --- a/src/components/NewPosition/NewPosition.tsx +++ b/src/components/NewPosition/NewPosition.tsx @@ -95,6 +95,8 @@ export interface INewPosition { max: number } currentFeeIndex: number + onSlippageChange: (slippage: string) => void + initialSlippage: string } export const NewPosition: React.FC = ({ @@ -137,7 +139,9 @@ export const NewPosition: React.FC = ({ hasTicksError, reloadHandler, plotVolumeRange, - currentFeeIndex + currentFeeIndex, + onSlippageChange, + initialSlippage }) => { const classes = useStyles() @@ -153,7 +157,7 @@ export const NewPosition: React.FC = ({ const [tokenBDeposit, setTokenBDeposit] = useState('') const [settings, setSettings] = React.useState(false) - const [slippTolerance, setSlippTolerance] = React.useState('1') + const [slippTolerance, setSlippTolerance] = React.useState(initialSlippage) const [anchorEl, setAnchorEl] = React.useState(null) const setRangeBlockerInfo = () => { if (tokenAIndex === null || tokenBIndex === null) { @@ -300,6 +304,7 @@ export const NewPosition: React.FC = ({ const setSlippage = (slippage: string): void => { setSlippTolerance(slippage) + onSlippageChange(slippage) } return ( @@ -338,6 +343,7 @@ export const NewPosition: React.FC = ({ handleClose={handleCloseSettings} anchorEl={anchorEl} defaultSlippage={'1'} + initialSlippage={initialSlippage} infoText='Slippage tolerance is a pricing difference between the price at the confirmation time and the actual price of the transaction users are willing to accept when initializing position.' headerText='Position Transaction Settings' /> diff --git a/src/components/Swap/Swap.stories.tsx b/src/components/Swap/Swap.stories.tsx index 51af1390f..381c75b37 100644 --- a/src/components/Swap/Swap.stories.tsx +++ b/src/components/Swap/Swap.stories.tsx @@ -172,6 +172,8 @@ storiesOf('newUi/swap', module) ]} initialHideUnknownTokensValue={false} onHideUnknownTokensChange={() => {}} + onSlippageChange={() => {}} + initialSlippage={'1'} /> )) diff --git a/src/components/Swap/Swap.tsx b/src/components/Swap/Swap.tsx index 05da96059..0f8feb561 100644 --- a/src/components/Swap/Swap.tsx +++ b/src/components/Swap/Swap.tsx @@ -92,6 +92,8 @@ export interface ISwap { tokenToPriceData?: CoingeckoPriceData priceFromLoading?: boolean priceToLoading?: boolean + onSlippageChange: (slippage: string) => void + initialSlippage: string } export const Swap: React.FC = ({ @@ -115,7 +117,9 @@ export const Swap: React.FC = ({ tokenFromPriceData, tokenToPriceData, priceFromLoading, - priceToLoading + priceToLoading, + onSlippageChange, + initialSlippage }) => { const classes = useStyles() enum inputTarget { @@ -130,7 +134,7 @@ export const Swap: React.FC = ({ const [amountTo, setAmountTo] = React.useState('') const [swap, setSwap] = React.useState(null) const [rotates, setRotates] = React.useState(0) - const [slippTolerance, setSlippTolerance] = React.useState('1') + const [slippTolerance, setSlippTolerance] = React.useState(initialSlippage) const [throttle, setThrottle] = React.useState(false) const [settings, setSettings] = React.useState(false) const [detailsOpen, setDetailsOpen] = React.useState(false) @@ -394,6 +398,7 @@ export const Swap: React.FC = ({ } const setSlippage = (slippage: string): void => { setSlippTolerance(slippage) + onSlippageChange(slippage) } const handleClickSettings = (event: React.MouseEvent) => { @@ -453,6 +458,7 @@ export const Swap: React.FC = ({ handleClose={handleCloseSettings} anchorEl={anchorEl} defaultSlippage={'1'} + initialSlippage={initialSlippage} /> diff --git a/src/containers/NewPositionWrapper/NewPositionWrapper.tsx b/src/containers/NewPositionWrapper/NewPositionWrapper.tsx index df2a1a5fd..7024b7703 100644 --- a/src/containers/NewPositionWrapper/NewPositionWrapper.tsx +++ b/src/containers/NewPositionWrapper/NewPositionWrapper.tsx @@ -372,6 +372,12 @@ export const NewPositionWrapper = () => { } }, [poolsVolumeRanges, poolIndex, isXtoY, xDecimal, yDecimal]) + const initialSlippage = localStorage.getItem('INVARIANT_NEW_POSITION_SLIPPAGE') ?? '1' + + const onSlippageChange = (slippage: string) => { + localStorage.setItem('INVARIANT_NEW_POSITION_SLIPPAGE', slippage) + } + return ( { }} plotVolumeRange={currentVolumeRange} currentFeeIndex={currentUiFeeIndex} + onSlippageChange={onSlippageChange} + initialSlippage={initialSlippage} /> ) } diff --git a/src/containers/WrappedSwap/WrappedSwap.tsx b/src/containers/WrappedSwap/WrappedSwap.tsx index 3b10e97f4..0e917e81c 100644 --- a/src/containers/WrappedSwap/WrappedSwap.tsx +++ b/src/containers/WrappedSwap/WrappedSwap.tsx @@ -170,6 +170,12 @@ export const WrappedSwap = () => { } }, [tokenTo]) + const initialSlippage = localStorage.getItem('INVARIANT_SWAP_SLIPPAGE') ?? '1' + + const onSlippageChange = (slippage: string) => { + localStorage.setItem('INVARIANT_SWAP_SLIPPAGE', slippage) + } + return ( { tokenToPriceData={tokenToPriceData} priceFromLoading={priceFromLoading} priceToLoading={priceToLoading} + onSlippageChange={onSlippageChange} + initialSlippage={initialSlippage} /> ) } diff --git a/src/store/consts/static.ts b/src/store/consts/static.ts index c2219d027..ce00ec100 100644 --- a/src/store/consts/static.ts +++ b/src/store/consts/static.ts @@ -244,7 +244,7 @@ const mainnetBestTiersCreator = () => { bestTiers.push({ tokenX, tokenY, - bestTierIndex: 1 + bestTierIndex: 3 }) } } @@ -262,22 +262,22 @@ export const bestTiers: Record = { { tokenX: USDC_DEV.address, tokenY: WSOL_DEV.address, - bestTierIndex: 1 + bestTierIndex: 3 }, { tokenX: USDC_DEV.address, tokenY: BTC_DEV.address, - bestTierIndex: 1 + bestTierIndex: 3 }, { tokenX: RENDOGE_DEV.address, tokenY: BTC_DEV.address, - bestTierIndex: 3 + bestTierIndex: 5 }, { tokenX: USDC_DEV.address, tokenY: RENDOGE_DEV.address, - bestTierIndex: 3 + bestTierIndex: 5 } ], Testnet: [], @@ -352,10 +352,10 @@ export const WSOL_POSITION_INIT_LAMPORTS = new BN(6164600) export const WSOL_POOL_INIT_LAMPORTS = new BN(106000961) -export const minimumRangesForTiers = [20, 20, 74, 80, 64, 28, 28, 28, 28] +export const minimumRangesForTiers = [20, 20, 20, 20, 74, 80, 64, 28, 28, 28, 28] export const maxSafeConcentrationsForTiers = [ - 400.52, 400.52, 41.49, 21.47, 8.13, 5.45, 5.45, 5.45, 5.45 + 400.52, 400.52, 400.52, 400.52, 41.49, 21.47, 8.13, 5.45, 5.45, 5.45, 5.45 ] export const ALL_FEE_TIERS_DATA = FEE_TIERS.map((tier, index) => ({