diff --git a/src/front/shared/pages/Exchange/QuickSwap/univ3/MintPosition.tsx b/src/front/shared/pages/Exchange/QuickSwap/univ3/MintPosition.tsx index 9f6a88e9c0..62cb213c08 100644 --- a/src/front/shared/pages/Exchange/QuickSwap/univ3/MintPosition.tsx +++ b/src/front/shared/pages/Exchange/QuickSwap/univ3/MintPosition.tsx @@ -263,12 +263,80 @@ function MintPosition(props) { const isBaseFetching = (isFetchTokensInfo || isPoolsByFeeFetching) + + /* @to-do - need optimize code size */ + const calcAmount = (amount, token) => { + if (viewSide == VIEW_SIDE.A_TO_B) { + if (token == TOKEN._0) { + const _amount1 = actions.uniswap.addLiquidityV3CalcAmount({ + amountIn: amount, + price: startPrice, + priceHigh: token0HighPrice, + priceLow: token0LowerPrice, + }).toNumber() + setAmount0(amount) + setAmount1(_amount1) + } + if (token == TOKEN._1) { + const perTokenPrice = actions.uniswap.addLiquidityV3CalcAmount({ + amountIn: 1, + price: startPrice, + priceHigh: token0HighPrice, + priceLow: token0LowerPrice, + }).toNumber() + const _amount0 = new BigNumber(amount).dividedBy(perTokenPrice).toNumber() + setAmount0(_amount0) + setAmount1(amount) + } + } else { + if (token == TOKEN._1) { + const _amount0 = actions.uniswap.addLiquidityV3CalcAmount({ + amountIn: amount, + price: startPrice, + priceHigh: token1HighPrice, + priceLow: token1LowerPrice, + }).toNumber() + setAmount1(amount) + setAmount0(_amount0) + } + if (token == TOKEN._0) { + const perTokenPrice = actions.uniswap.addLiquidityV3CalcAmount({ + amountIn: 1, + price: startPrice, + priceHigh: token1HighPrice, + priceLow: token1LowerPrice, + }).toNumber() + const _amount1 = new BigNumber(amount).dividedBy(perTokenPrice).toNumber() + setAmount1(_amount1) + setAmount0(amount) + } + } + } + + const posInRange = ( + viewSide == VIEW_SIDE.A_TO_B + ) ? ( + new BigNumber(token0LowerPrice).isLessThanOrEqualTo(startPrice) + && new BigNumber(token0HighPrice).isGreaterThanOrEqualTo(startPrice) + ) : ( + new BigNumber(token1LowerPrice).isLessThanOrEqualTo(startPrice) + && new BigNumber(token1HighPrice).isGreaterThanOrEqualTo(startPrice) + ) + + + + const startPriceIsLower = (viewSide == VIEW_SIDE.A_TO_B) ? new BigNumber(startPrice).isLessThan(token0LowerPrice) : new BigNumber(startPrice).isLessThan(token1LowerPrice) + const startPriceIsHigh = (viewSide == VIEW_SIDE.A_TO_B) ? new BigNumber(startPrice).isGreaterThan(token0HighPrice) : new BigNumber(startPrice).isGreaterThan(token1HighPrice) + + console.log('>>>>> IN RANGE, LOWER, HIGH', posInRange, startPriceIsLower, startPriceIsHigh) + + const renderDepositToken0 = () => { return ( { setAmount0(v) }} + onChange={(v) => { calcAmount(v, TOKEN._0) }} symbol={getTokenSymbol(TOKEN._0)} balance={formatAmount(fromWei(TOKEN._0, token0BalanceWei))} isBalanceUpdate={isFetchingBalanceAllowance} @@ -276,37 +344,21 @@ function MintPosition(props) { /> ) } + const renderDepositToken1 = () => { return ( { setAmount1(v) }} + onChange={(v) => { calcAmount(v, TOKEN._1) }} symbol={getTokenSymbol(TOKEN._1)} - balance={formatAmount(fromWei(TOKEN._1, token0BalanceWei))} + balance={formatAmount(fromWei(TOKEN._1, token1BalanceWei))} isBalanceUpdate={isFetchingBalanceAllowance} onBalanceUpdate={() => { setDoFetchBalanceAllowance(true) }} /> ) } - - const posInRange = ( - viewSide == VIEW_SIDE.A_TO_B - ) ? ( - new BigNumber(token0LowerPrice).isLessThanOrEqualTo(startPrice) - && new BigNumber(token0HighPrice).isGreaterThanOrEqualTo(startPrice) - ) : ( - new BigNumber(token1LowerPrice).isLessThanOrEqualTo(startPrice) - && new BigNumber(token1HighPrice).isGreaterThanOrEqualTo(startPrice) - ) - - - const startPriceIsLower = (viewSide == VIEW_SIDE.A_TO_B) ? new BigNumber(startPrice).isLessThan(token0LowerPrice) : new BigNumber(startPrice).isLessThan(token1LowerPrice) - const startPriceIsHigh = (viewSide == VIEW_SIDE.A_TO_B) ? new BigNumber(startPrice).isGreaterThan(token0HighPrice) : new BigNumber(startPrice).isGreaterThan(token1HighPrice) - - console.log('>>>>> IN RANGE, LOWER, HIGH', posInRange, startPriceIsLower, startPriceIsHigh) - return (
{ setCurrentAction(PositionAction.LIST) }}> @@ -438,7 +490,12 @@ function MintPosition(props) {
)}
-

Deposit amounts

+

+ +

{(viewSide == VIEW_SIDE.A_TO_B) ? ( <> {!startPriceIsLower && renderDepositToken0()}