web-monetization-extension
web-monetization-extension copied to clipboard
Format asset scale for UI
Whenever the extension displays an amount on the UI, the asset scale that gets displayed must be based on the following rules:
(info: this applies to the Settings page before and after connecting to a wallet; and to the page where a user configures their hourly rate-of-pay for monetization)
While the background of the extension handles an amount in asset scale 9, and the UI displays the amount:
- in asset scale 2 for asset codes that have an asset scale <= 2 (e.g. fiat currencies like USD, MXN, EUR etc.)
- in asset scale 3 or 4 for asset codes that have an asset scale >2 and <= 4 (e.g. 17.018 OR 0.1234)
- in scientific notation when the amount is < 1 and the asset code has an asset scale >= 5 and <= 9 (e.g. an amount of 0.00005 should be displayed as 5e-5) (if needed, refer to this link)
- the entire amount in decimal point, when the amount is > 1 and the asset scale is > 4 and <= 9 (e.g. 1.000000009)
This applies to the following areas of the extension's UI:
-
On the Settings page, before connecting the extension to a wallet, there is an "Amount" field (scientific notation not applicable)
-
On the Settings page, when a wallet is already connected to the extension, there is a "Remaining balance" field (scientific notation applicable)
-
When the extension is connected to a wallet, on the page where the current rate-of-pay is set, there is an hourly rate for Web Monetization; the "Remaining balance"; and the "Send amount now" for making a once-off payment (scientific notation applicable)
Summary
- For fiat currencies, always display asset scale 2 (i.e. this applies for all asset codes that have asset scale <= 2 e.g. EUR etc.).
- If the asset is crypto, display the entire amount as a decimal, or in scientific notation, depending on the asset scale rules described above.