diff --git a/packages/web-lib/utils/format.bigNumber.tsx b/packages/web-lib/utils/format.bigNumber.tsx index b9f45e0b..b1b643c3 100755 --- a/packages/web-lib/utils/format.bigNumber.tsx +++ b/packages/web-lib/utils/format.bigNumber.tsx @@ -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; diff --git a/packages/web-lib/utils/handlers/handleInputChangeEventValue.test.ts b/packages/web-lib/utils/handlers/handleInputChangeEventValue.test.ts index 166fa280..4960ed5a 100644 --- a/packages/web-lib/utils/handlers/handleInputChangeEventValue.test.ts +++ b/packages/web-lib/utils/handlers/handleInputChangeEventValue.test.ts @@ -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 => { diff --git a/packages/web-lib/utils/handlers/handleInputChangeEventValue.ts b/packages/web-lib/utils/handlers/handleInputChangeEventValue.ts index df7c45fa..bf28fdc3 100644 --- a/packages/web-lib/utils/handlers/handleInputChangeEventValue.ts +++ b/packages/web-lib/utils/handlers/handleInputChangeEventValue.ts @@ -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('.');