HomePhabricator

[Cashtab] Improve and standardize cashtab token cache

Description

[Cashtab] Improve and standardize cashtab token cache

Summary:
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.

Test Plan:
npm test

This diff is deployed at https://cashtab-local-dev.netlify.app/

Note: if you have a wallet with a lot of tokens, it make take some time to load. I considered adding a spinner to update, but since this delay is only expected for a small number of wallets and only before the new token cache is populated, I do not think it is worth adding this change to the app.

Reviewers: #bitcoin_abc, emack

Reviewed By: #bitcoin_abc, emack

Subscribers: Fabien, emack

Differential Revision: https://reviews.bitcoinabc.org/D15784

Details

Provenance
bytesofmanAuthored on Mar 26 2024, 00:15
bytesofmanPushed on Mar 29 2024, 13:34
Reviewer
Restricted Project
Differential Revision
D15784: [Cashtab] Improve and standardize cashtab token cache
Parents
rABCb0fc2d830f26: [e.cash] Remove Governance item from core-tech page
Branches
Unknown
Tags
Unknown