From 24d00f7c396ef21f3e5cdaf61266299c4bd2abdf Mon Sep 17 00:00:00 2001 From: gnewfield <18626088+gnewfield@users.noreply.github.com> Date: Thu, 3 Aug 2023 10:52:18 -0400 Subject: [PATCH] fix: init pool behavior (#7052) * Disable increment/decrement when range prices undefined * Enable full-range price selection for new pools * Add cypress tests * Fix lint error --- cypress/e2e/add-liquidity.test.ts | 47 +++++++++++++++++++ .../InputStepCounter/InputStepCounter.tsx | 4 +- .../RangeSelector/PresetsButtons.tsx | 2 +- src/components/RangeSelector/index.tsx | 8 ++-- src/pages/AddLiquidity/index.tsx | 2 +- 5 files changed, 55 insertions(+), 8 deletions(-) diff --git a/cypress/e2e/add-liquidity.test.ts b/cypress/e2e/add-liquidity.test.ts index 6da0b076e6..0bad6029da 100644 --- a/cypress/e2e/add-liquidity.test.ts +++ b/cypress/e2e/add-liquidity.test.ts @@ -52,4 +52,51 @@ describe('Add Liquidity', () => { cy.get('#add-liquidity-selected-fee .selected-fee-percentage').should('contain.text', '40% select') }) }) + + it('disables increment and decrement until initial prices are inputted', () => { + // ETH / BITCOIN pool (0.05% tier not created) + cy.visit('/add/ETH/0x72e4f9F808C49A2a61dE9C5896298920Dc4EEEa9/500') + // Set starting price in order to enable price range step counters + cy.get('.start-price-input').type('1000') + + // Min Price increment / decrement buttons should be disabled + cy.get('[data-testid="increment-price-range"]').eq(0).should('be.disabled') + cy.get('[data-testid="decrement-price-range"]').eq(0).should('be.disabled') + // Enter min price, which should enable the buttons + cy.get('.rate-input-0').eq(0).type('900').blur() + cy.get('[data-testid="increment-price-range"]').eq(0).should('not.be.disabled') + cy.get('[data-testid="decrement-price-range"]').eq(0).should('not.be.disabled') + + // Repeat for Max Price step counter + cy.get('[data-testid="increment-price-range"]').eq(1).should('be.disabled') + cy.get('[data-testid="decrement-price-range"]').eq(1).should('be.disabled') + // Enter max price, which should enable the buttons + cy.get('.rate-input-0').eq(1).type('1100').blur() + cy.get('[data-testid="increment-price-range"]').eq(1).should('not.be.disabled') + cy.get('[data-testid="decrement-price-range"]').eq(1).should('not.be.disabled') + }) + + it('allows full range selection on new pool creation', () => { + // ETH / BITCOIN pool (0.05% tier not created) + cy.visit('/add/ETH/0x72e4f9F808C49A2a61dE9C5896298920Dc4EEEa9/500') + // Set starting price in order to enable price range step counters + cy.get('.start-price-input').type('1000') + cy.get('[data-testid="set-full-range"]').click() + // Check that the min price is 0 and the max price is infinity + cy.get('.rate-input-0').eq(0).should('have.value', '0') + cy.get('.rate-input-0').eq(1).should('have.value', '∞') + // Increment and decrement buttons are disabled when full range is selected + cy.get('[data-testid="increment-price-range"]').eq(0).should('be.disabled') + cy.get('[data-testid="decrement-price-range"]').eq(0).should('be.disabled') + cy.get('[data-testid="increment-price-range"]').eq(1).should('be.disabled') + cy.get('[data-testid="decrement-price-range"]').eq(1).should('be.disabled') + // Check that url params were added + cy.url().then((url) => { + const params = new URLSearchParams(url) + const minPrice = params.get('minPrice') + const maxPrice = params.get('maxPrice') + // Note: although 0 and ∞ displayed, actual values in query are ticks at limit + return minPrice && maxPrice && parseFloat(minPrice) < parseFloat(maxPrice) + }) + }) }) diff --git a/src/components/InputStepCounter/InputStepCounter.tsx b/src/components/InputStepCounter/InputStepCounter.tsx index ae99b3eb54..99cd348f3c 100644 --- a/src/components/InputStepCounter/InputStepCounter.tsx +++ b/src/components/InputStepCounter/InputStepCounter.tsx @@ -149,7 +149,7 @@ const StepCounter = ({ {!locked && ( - + @@ -167,7 +167,7 @@ const StepCounter = ({ /> {!locked && ( - + diff --git a/src/components/RangeSelector/PresetsButtons.tsx b/src/components/RangeSelector/PresetsButtons.tsx index 29b1e1907c..25baf63ba6 100644 --- a/src/components/RangeSelector/PresetsButtons.tsx +++ b/src/components/RangeSelector/PresetsButtons.tsx @@ -19,7 +19,7 @@ interface PresetsButtonsProps { export default function PresetsButtons({ onSetFullRange }: PresetsButtonsProps) { return ( -