From 571a5a061c1244acb64e9f3c31218e12fd4dddf4 Mon Sep 17 00:00:00 2001 From: Luiz Felipe Bolsoni Gomes Date: Tue, 14 Jun 2022 23:02:21 -0300 Subject: [PATCH] fix: decimal input --- .../src/systems/Core/components/CoinInput.tsx | 12 +++++++++++- .../systems/Pool/pages/AddLiquidity.test.tsx | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/app/src/systems/Core/components/CoinInput.tsx b/packages/app/src/systems/Core/components/CoinInput.tsx index 806cc13d..856c7fa3 100644 --- a/packages/app/src/systems/Core/components/CoinInput.tsx +++ b/packages/app/src/systems/Core/components/CoinInput.tsx @@ -168,7 +168,17 @@ export function useCoinInput({ function getRightValue(value: string, displayType: string) { if (displayType === "text") return parseToFormattedNumber(value); - return value === "0.0" ? "0" : value; + + switch (value) { + case "0.0": + return "0"; + + case ".": + return "0."; + + default: + return value; + } } type CoinInputProps = Omit & diff --git a/packages/app/src/systems/Pool/pages/AddLiquidity.test.tsx b/packages/app/src/systems/Pool/pages/AddLiquidity.test.tsx index 3a5e27e6..60d9446b 100644 --- a/packages/app/src/systems/Pool/pages/AddLiquidity.test.tsx +++ b/packages/app/src/systems/Pool/pages/AddLiquidity.test.tsx @@ -196,4 +196,23 @@ describe("Add Liquidity", () => { const successFeedback = await screen.findByText(/New pool created/i); expect(successFeedback).toBeInTheDocument(); }); + + it("should show '0.' if typed only '.' in the input", async () => { + jest.unmock("../hooks/useUserPositions.ts"); + + renderWithRouter(, { + route: "/pool/add-liquidity", + }); + + const coinFromInput = screen.getByLabelText(/Coin From Input/); + fireEvent.change(coinFromInput, { + target: { + value: ".", + }, + }); + + await waitFor(() => { + expect(coinFromInput).toHaveValue("0."); + }); + }); });