From 64368be48dfe41cdeea2ec3f8810316b64de290a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20M=C4=83rgineanu?= Date: Mon, 25 Nov 2024 11:30:35 +0200 Subject: [PATCH 1/2] Fixed BigNumber.js scoping --- src/utils/validation/stringIsFloat.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/utils/validation/stringIsFloat.ts b/src/utils/validation/stringIsFloat.ts index bc575c800..173f62669 100755 --- a/src/utils/validation/stringIsFloat.ts +++ b/src/utils/validation/stringIsFloat.ts @@ -14,12 +14,14 @@ export const stringIsFloat = (amount: string) => { // eslint-disable-next-line let [wholes, decimals] = amount.split('.'); + const LocalBigNumber = BigNumber.clone(); + if (decimals) { const areAllNumbers = decimals .split('') .every((digit) => !isNaN(parseInt(digit))); - BigNumber.set({ + LocalBigNumber.set({ DECIMAL_PLACES: areAllNumbers ? decimals.length : BigNumber.config().DECIMAL_PLACES @@ -30,6 +32,10 @@ export const stringIsFloat = (amount: string) => { } } const number = decimals ? [wholes, decimals].join('.') : wholes; - const bNparsed = new BigNumber(number); - return bNparsed.toString(10) === number && bNparsed.comparedTo(0) >= 0; + const bNparsed = LocalBigNumber(number); + + const output = + bNparsed.toString(10) === number && bNparsed.comparedTo(0) >= 0; + + return output; }; From ba3fe2c08cf499c311deacddb107fb44f9667d0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20M=C4=83rgineanu?= Date: Mon, 25 Nov 2024 11:34:33 +0200 Subject: [PATCH 2/2] Updated CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 222444976..ba9ec82b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- [Fixed BigNumber configuration, scoped to a function level in "stringIsFloat"](https://github.com/multiversx/mx-sdk-dapp/pull/1312) + ## [[v3.0.12](https://github.com/multiversx/mx-sdk-dapp/pull/1310)] - 2024-11-20 - [Fixed "stringIsFloat" issue for huge decimal numbers](https://github.com/multiversx/mx-sdk-dapp/pull/1309)