Page MenuHomePhabricator

[Cashtab] [chronik utxo handling p6] Cache token info in local storage
ClosedPublic

Authored by bytesofman on Sep 12 2022, 22:45.

Details

Summary

T2447

Depends on D11960

Add cashtabCache to local storage as a new unique key so that it is available across wallets.

Test Plan

npm start
Observe that cashtabCache is added to local storage (dev console --> applications --> storage)
In dev console, observe that cashtabCache updates. First update call requires API calls for token info. Later ones do not.
Send a new token to the wallet and observe cashtabCache updates again.
Change wallets and confirm no errors, token cache still working.
Send and receive token txs, generally try to break it.

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

emack requested changes to this revision.Sep 14 2022, 08:41
emack added a subscriber: emack.
emack added inline comments.
web/cashtab/src/utils/__mocks__/mockCashtabCache.js
2 ↗(On Diff #34933)

Not quite related to this diff but should we start incorporating the token type attribute into this series to make it easier to expand to cover NFTs when the eToken DEX lands in 3 months time? Because if we don't do it now, then we'll end up with the situation in 3 months time where we'll need to retrospectively refresh cache to update existing token info objects with their respective token types.

web/cashtab/src/utils/__tests__/validation.test.js
273 ↗(On Diff #34933)

minor typo

280 ↗(On Diff #34933)

I couldn't tell from the large mock array (cashtabCacheWithOneBadTokenId) whether it contained at least one token ID that is a string that is not exactly 64 chars. Might be worth its own test for malformed token ids.

web/cashtab/src/utils/validation.js
260 ↗(On Diff #34933)

doc hash is optional in the UI so there may not be a value to check the type of

This revision now requires changes to proceed.Sep 14 2022, 08:41
web/cashtab/src/utils/__mocks__/mockCashtabCache.js
2 ↗(On Diff #34933)

While we will likely need to add this info going forward, the migration is trivial since this cache object automatically updates every time the utxo cycle is performed. So, I think it's okay to leave this out until we need it.

web/cashtab/src/utils/__tests__/validation.test.js
273 ↗(On Diff #34933)

Corrected

280 ↗(On Diff #34933)

Want to have a unit test that covers the specific ways isValidCashtabCache detects something is invalid, this is just one of those ways. We already have a specific function for isValidTokenId which has its own unit tests. So in effect, this is just testing whether isValidCashtabCache is appropriately using isValidTokenId

This revision is now accepted and ready to land.Sep 15 2022, 14:01