Skip to content

Commit

Permalink
fix: Unable to clear input
Browse files Browse the repository at this point in the history
  • Loading branch information
karelianpie committed May 19, 2023
1 parent 9355d94 commit ed4c0d6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/web-lib/utils/format.bigNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {BigNumberish} from 'ethers';

export type TNormalizedBN = {
raw: BigNumber,
normalized: number | string,
normalized: number | string | '',
}

export const {Zero} = ethers.constants;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ describe('handleInputChangeEventValue', (): void => {
expect(normalized).toBe('10.123456');
});

it('returns 0 for empty input', (): void => {
it('returns raw Zero and normalized empty string for empty input', (): void => {
const {raw, normalized} = handleInputChangeEventValue('', 18);
expect(raw.toString()).toBe('0');
expect(normalized).toBe('0');
expect(normalized).toBe('');
});

it('replaces comma with period in input value', (): void => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import {ethers} from 'ethers';
import {constants, ethers} from 'ethers';

import type {TNormalizedBN} from '../format';

export function handleInputChangeEventValue(value: string, decimals?: number): TNormalizedBN {
if (value === '') {
return {raw: constants.Zero, normalized: ''};
}

let amount = value.replace(/,/g, '.').replace(/[^0-9.]/g, '');
const amountParts = amount.split('.');

Expand Down

0 comments on commit ed4c0d6

Please sign in to comment.