T3461
This diff clears some lingering technical debt related to how Cashtab handles tokens.
Before this diff
- Cashtab wallet has a 'tokens' key in state, which includes some token info
- Other token info collected by API call when SendToken screen is loaded
- Still other token info is cached
- Various shims are in place to deal with expected info not being in the cache when it could or should be
After this diff
- Put all the token info you need in the cache
A number of knock-on impacts led to this diff expanding. As with previous migrations -- the size is regrettable but imo worth the impact.
- Now that we store tokens as a map (instead of an array of objects), we need JSON helper methods to store / activate wallets (we already do this with cashtabCache)
- Since we need the helper method anyway, and we are migrating wallets anyway, upgrade wallet shape so that paths is a map, and we can stop doing the tedious .find() method throughout Cashtab. It is certainly overkill that we support multiple paths in a map. However, if we ever decide to expand Cashtab to support HD wallets or other coins, we will be happy to have this shape supported.
- Add new helper methods decimalizeTokenAmount and undecimalizeTokenAmount to convert token quantities to and from decimalized amounts. We have been using BN for this, and we do still use it in some places -- however the implementation for BN is confusing, esp as there is no existing function and need to remember the correct way to use shiftedBy. These new methods are string-based and do not require any library. Since we have a new function for calculating token balances and info, I did not want to bring in legacy methods that will need to be refactored later.
- The way Cashtab updates wallet state in the update method of useWallet.js is a mess. Clean it up now that we have some type stability in chronik. Now the workflow is streamlined and all functions are unit tested.