Skip to content

Commit

Permalink
SOV-4157: Fix maximum value in AmountInput (#912)
Browse files Browse the repository at this point in the history
* Fix maximum value in AmountInput

* Create nervous-mails-punch.md
  • Loading branch information
tiltom authored May 15, 2024
1 parent 6797b95 commit 05ffbb5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-mails-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sovryn/ui": patch
---

SOV-4157: Fix maximum value in AmountInput
15 changes: 1 addition & 14 deletions packages/ui/src/2_molecules/AmountInput/AmountInput.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, waitFor } from '@testing-library/react';
import { render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import React from 'react';
Expand Down Expand Up @@ -107,19 +107,6 @@ describe('AmountInput', () => {
expect(amountInput).toHaveProperty('lang', 'sk-SK');
});

test('does not allow to enter more than 9 whole numbers', async () => {
const { getByTestId } = render(
<AmountInput value={2} dataAttribute="test" />,
);

const amountInput = getByTestId('test');

userEvent.clear(amountInput);
userEvent.paste(amountInput, '10000000000000');

await waitFor(() => expect(amountInput).toHaveValue('999999999'));
});

test('trims unnecessary zeros at the end on blur', async () => {
const { getByTestId } = render(
<AmountInput
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/2_molecules/AmountInput/AmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { HelperButton } from '../HelperButton/HelperButton';
import styles from './AmountInput.module.css';

const MAX_DECIMALS = 18;
const MAX_VALUE = 999999999;
const MAX_VALUE = Number.MAX_VALUE;

export enum AmountInputVariant {
large = 'large',
Expand Down Expand Up @@ -78,7 +78,7 @@ export const AmountInput = React.forwardRef<HTMLInputElement, AmountInputProps>(
unformattedNumberValue = String(maxAmount);
}

if (Number(unformattedNumberValue) >= MAX_VALUE + 1) {
if (Number(unformattedNumberValue) >= MAX_VALUE) {
unformattedNumberValue = String(MAX_VALUE);
}

Expand Down

0 comments on commit 05ffbb5

Please sign in to comment.