bitbox-wallet-app
bitbox-wallet-app copied to clipboard
Formatting refactor
This PR (WIP):
- Fixes the BTC 2 digits backend formatting bug
- Proposes a draft solution to centralize formatting handling in the backend, exploiting higher precision when available
I still see room for some improvements in FromUnit implementation precision.
See commit messages for details.
Once agreed on this first draft, the next step is to refactor the frontend part, moving all the occasional formatting done there into the backend.
@benma during our last eng sync you proposed to find a solution to avoid having currency/coins string around in the code, like here: https://github.com/Beerosagos/bitbox-wallet-app/blob/formatting-refactor/backend/coins/coin/conversions.go#L14
I made a check and I could not find a struct with all the available fiats in the backend. I noticed that supported currencies are listed in frontend `rates.tsx' (https://github.com/Beerosagos/bitbox-wallet-app/blob/formatting-refactor/frontends/web/src/components/rates/rates.tsx#L41) and shared with backend only when activated by the user.
I would suggest to open a separated issue/PR to move the list of available currencies in the backend, behind a dedicated endpoint. WDYT?
@benma after our talk about float precision I decided to make some tests and verify how much we can relay on float64 to correctly handle coins and fiats, since it is currently used to compute conversions in the backend (e.g. https://github.com/digitalbitbox/bitbox-wallet-app/blob/master/backend/coins/coin/conversions.go#L30).
From this playground https://go.dev/play/p/DAU9m6ybqKh it seems that the 18 digits precision required by ETH coins is not completely satisfied, also with relatively small amounts. big.Float seems to have a better behavior.
I would suggest to update conversion and formatting functions to use big.Float or big.Rat to reach a better precision. In case you agree, I am not sure if this should be included in this PR, or maybe it is better to make a dedicated one. WDYT?