Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed BigNumber.js scoping #1312

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/utils/validation/stringIsFloat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
};
Loading