Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

fix: correct behavior when typing only "." in the coin input #291

Merged
merged 1 commit into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/app/src/systems/Core/components/CoinInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<UseCoinParams, "onChange"> &
Expand Down
19 changes: 19 additions & 0 deletions packages/app/src/systems/Pool/pages/AddLiquidity.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<App />, {
route: "/pool/add-liquidity",
});

const coinFromInput = screen.getByLabelText(/Coin From Input/);
fireEvent.change(coinFromInput, {
target: {
value: ".",
},
});

await waitFor(() => {
expect(coinFromInput).toHaveValue("0.");
});
});
});