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

chore: BigNumber.toString(10) to prevent output as exponential #12576

Merged
merged 4 commits into from
May 27, 2024

Conversation

martykan
Copy link
Member

@martykan martykan commented May 26, 2024

Description

This change ensures that all toString calls on BigNumber objects include base 10 as a parameter. By doing this, we prevent numbers from being displayed in exponential form.

  • added unit and e2e test for ETH staking with balances >= 1000 ETH

Screenshot 2024-05-27 at 15 37 45 (1)

@martykan martykan force-pushed the fix/bignumber-tostring-exponential branch from 1597485 to f4dbc86 Compare May 26, 2024 15:58
@martykan martykan marked this pull request as ready for review May 26, 2024 18:01
Copy link
Member

@tomasklim tomasklim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am worried that someone will forget to add 10 and the same issue will occur again later.

It is now already missing in e.g. blockfrost.ts

Can we modify the BigNumber config to a really big number?

BigNumber.config({ EXPONENTIAL_AT: 1e+50 });

or modify toString prototype to have base=10 by default?

const originalToString = BigNumber.prototype.toString;

BigNumber.prototype.toString = (base = 10) => originalToString.call(this, base);

@martykan
Copy link
Member Author

Yeah, it's true that this is not that maintainable. My idea to solve this was by making an Eslint plugin, since I already have a script which I used to make these changes.

But based on your ideas, I think the best solution would probably be to create a new wrapper package which we would import instead of BigNumber, there would use BigNumber.clone() to create our instance and set the config on it. Or override the prototype.

@martykan martykan force-pushed the fix/bignumber-tostring-exponential branch from c59cac9 to 8fe54c4 Compare May 27, 2024 10:47
@martykan martykan requested review from Nodonisko, a team and karliatto as code owners May 27, 2024 10:47
@martykan martykan force-pushed the fix/bignumber-tostring-exponential branch from 8fe54c4 to b6b7a7e Compare May 27, 2024 10:50
@martykan martykan force-pushed the fix/bignumber-tostring-exponential branch from b6b7a7e to 3a3a16b Compare May 27, 2024 10:56
Copy link

socket-security bot commented May 27, 2024

🚨 Potential security issues detected. Learn more about Socket for GitHub ↗︎

To accept the risk, merge this PR and you will not be notified again.

Alert Package NoteSource
Filesystem access npm/resolve-from@5.0.0
Filesystem access npm/argparse@2.0.1
Filesystem access npm/glob@7.2.3
Filesystem access npm/glob@7.2.3
New author npm/ms@2.1.2
Uses eval npm/ajv@6.12.6
Trivial Package npm/escape-string-regexp@1.0.5
Filesystem access npm/fs.realpath@1.0.0
Filesystem access npm/resolve-from@4.0.0
  • orphan: npm/resolve-from@4.0.0
Filesystem access npm/chardet@0.7.0
Filesystem access npm/graceful-fs@4.2.11
New author npm/istanbul-lib-source-maps@4.0.1
Filesystem access npm/istanbul-lib-source-maps@4.0.1
New author npm/babel-plugin-istanbul@6.1.1
Filesystem access npm/babel-plugin-istanbul@6.1.1
Shell access npm/babel-plugin-istanbul@6.1.1
New author npm/convert-source-map@2.0.0
Filesystem access npm/get-package-type@0.1.0
Shell access npm/cross-spawn@7.0.3
Filesystem access npm/cross-spawn@7.0.3
New author npm/merge-stream@2.0.0
  • orphan: npm/merge-stream@2.0.0
Filesystem access npm/isexe@2.0.0
  • orphan: npm/isexe@2.0.0
New author npm/@babel/plugin-syntax-import-meta@7.10.4
New author npm/@babel/plugin-syntax-logical-assignment-operators@7.10.4
New author npm/@babel/plugin-syntax-numeric-separator@7.10.4
New author npm/anymatch@3.1.3
New author npm/fb-watchman@2.0.2
Network access npm/fb-watchman@2.0.2
Shell access npm/fb-watchman@2.0.2
Filesystem access npm/argparse@1.0.10
  • orphan: npm/argparse@1.0.10
Filesystem access npm/is-docker@2.2.1
Trivial Package npm/is-arrayish@0.2.1
New author npm/kind-of@6.0.3
Filesystem access npm/debug@2.6.9
  • orphan: npm/debug@2.6.9
Network access npm/debug@2.6.9
  • orphan: npm/debug@2.6.9
Uses eval npm/bluebird@3.7.2
Uses eval npm/bluebird@3.7.2
Uses eval npm/bluebird@3.7.2
Uses eval npm/bluebird@3.7.2
Uses eval npm/bluebird@3.7.2
Uses eval npm/bluebird@3.7.2
Uses eval npm/bluebird@3.7.2
Network access npm/https-proxy-agent@5.0.1
Network access npm/https-proxy-agent@5.0.1
Filesystem access npm/@nodelib/fs.stat@2.0.5
Filesystem access npm/@nodelib/fs.scandir@2.1.5
Trivial Package npm/at-least-node@1.0.0
Filesystem access npm/path-type@4.0.0
Trivial Package npm/isarray@2.0.5
Filesystem access npm/escalade@3.1.1
Filesystem access npm/require-directory@2.1.1
  • orphan: npm/require-directory@2.1.1
Filesystem access npm/readdirp@3.6.0
Network access npm/methods@1.1.2
Filesystem access npm/chownr@2.0.0
Network access npm/http-proxy-agent@5.0.0
Network access npm/http-proxy-agent@5.0.0
New author npm/for-each@0.3.3
  • orphan: npm/for-each@0.3.3
Filesystem access npm/loader-runner@4.3.0
  • orphan: npm/loader-runner@4.3.0
Uses eval npm/loader-runner@4.3.0
  • orphan: npm/loader-runner@4.3.0
Filesystem access npm/glob@7.1.6
  • orphan: npm/glob@7.1.6
Filesystem access npm/glob@7.1.6
  • orphan: npm/glob@7.1.6
Floating dependency npm/@types/eslint-scope@3.7.4
  • orphan: npm/@types/eslint-scope@3.7.4
Floating dependency npm/@types/eslint-scope@3.7.4
  • orphan: npm/@types/eslint-scope@3.7.4
Floating dependency npm/@types/jsdom@20.0.1
Floating dependency

@martykan martykan requested a review from tomasklim May 27, 2024 11:25
@MiroslavProchazka
Copy link
Contributor

@Nodonisko @mroz22 can you please do the final review and approve/add comment? Thanks!

@tomasklim tomasklim merged commit 65cacb6 into develop May 27, 2024
77 of 79 checks passed
@tomasklim tomasklim deleted the fix/bignumber-tostring-exponential branch May 27, 2024 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants