use-ink/useink

Create helper functions for formatting Big Numbers in BN.js

Opened this issue · 0 comments

Feature Request

  • Create helper functions that take a BN.js, string, or number as a NUMBER input and format it in human readable ways. Each api registry has chain decimal information, which should be used to properly format decimals, etc.

Suggestion

useBalance()?.freeBalance will return something like 1096562700458522 for Contracts on Rococo.

  • We should be able to easily display that as 1,196.56 ROC, 1196.5627, 1096.562700458522, etc. We can control how many significant numbers are shown, show the currency, use commas, etc.
  • Add helpers for decimal math without floating point numbers. e.g. Chain A uses 12 decimals and Chain B uses 18 decimals. If we want to calculate an exchange rate between the two we want to do this easily.

Motivation

Formatting BN is tedious, and very common.

Use Cases

Displaying a user's balance with only two decimals. e.g. 1,096.56 ROC