[Cashtab] [Alias] pt 6.5 - Optimize getAllTxHistory to only make API calls for uncached tx history pages
Summary:
T2551
Depends on D13065
This diff implements the alias caching component to minimize API calls for alias tx history retrieval.
Overview
- upon load of Alias.js, it checks whether cached Alias objects exist. If it doesn't, then execute a full alias tx history retrieval.
- If cached Alias objects do exist, verify whether a refresh is required by comparing the cached and onchain tx counts.
- If a partial tx history refresh is required, retrieve the additional txs entries and concat them to the cached txs entries.
- There are now two alias caching objects, one being aliasTxHistory which stores an array of txs objects, and the other being aliases which is the list of aliases and their addresses.
- the updateAliases() function in useWallets updates the aliases cache object, while the updateCachedAliasTxHistory() function in useWallets updates the aliasTxHistory cache object
- getAllTxHistory() in chronik.js has been overloaded with an optional customStartPage which is used to indicate whether it should retrieve all tx history or a partial one starting from that page supplied.
[Cashtab] [Alias] pt 1 - Create scaffold for new Identity component
[Cashtab] [Alias] pt 2 - Upgrade sendXec() to handle alias registration
[Cashtab] [Alias] pt 3 - Implement isAliasAvailable function
[Cashtab] [Alias] pt 4 - Implement isAddressRegistered function
[Cashtab] [Alias] pt 5 - Implement getAddressFromAlias function
[Cashtab] [Alias] pt 6.1 - Get latest alias tx count from payment address
[Cashtab] [Alias] pt 6.1.1 - Apply Promise.All approach for alias history retrieval
[Cashtab] [Alias] pt 6.2 - Implement getAliasesFromLocalForage
[Cashtab] [Alias] pt 6.3 - Implement updateAliases
[Cashtab] [Alias] pt 6.4 - Update getAliases() to extract both alias and address
[Cashtab] [Alias] pt 6.5 - Optimize getAllTxHistory to only make API calls for uncached tx history pages
[Cashtab] [Alias] pt 6.6 - Render list of Aliases owned by active wallet in Alias.js
[Cashtab] [Alias] pt 6.7 - Deprecate caching related mocks, @TODOs and reviewer logs
[Cashtab] [Alias] pt 7 - Mitigate edge cases for registration records (same rego in same block, validate emoji char counts)
[Cashtab] [Alias] pt 8 - Enable alias lookup for Send XEC component
[Cashtab] [Alias] pt 9 - Enable alias lookup for Send Token component
[Cashtab] [Alias] pt 10 - Upgrade tx history to recognize alias registration txs
[Cashtab] [Alias] pt 11 - Set final registration fees and remove residual dev logs
Test Plan:
- npm test
- npm start
- check IndexedDB keyvaluepairs and ensure aliasTxHistory and aliases cache objects do not exist
- navigate to the Alias page for the first time, refresh IndexedDB and verify the above cache objects have now been created and the array length in aliasTxHistory and the totalPaymentTxCount param in aliases both match the transaction count on explorer.e.cash. Also verify in the console log a full tx history retrieval was triggered
- register a few new aliases then navigate away from and then back to the Alias page. Verify the console log is indicating partial tx history retrieval required and partial tx history retrieval starting from page x, rather than a full tx retrieval
- verify in IndexedDB that the cached tx history prior to the partial tx history retrieval has not been lost and is incremented by the new aliases you just registered
- navigate away from and back to the Alias page and validate via the console log that the cached and onchain tx counts are in sync and no tx retrieval is triggered
- attempt to register one of the newly registered aliases and ensure the alias duplication error notification is displayed and it is not broadcasted
new test cases for changes to cashtabCache:
- open the alias page in a fresh new browser with no existing cache and validate the previous undefined exception in isAddressRegistered does not appear and the console log is displaying invalid cashtabCache detected, initializing to currency.defaultCashtabCache.
- validate a valid cashtabCache detected log is displayed in console after refresh.
- open a different browser which has previously visited a version of cashtab before this cashtabCache update and validate invalid cashtabCache detected, initializing to currency.defaultCashtabCache is displayed in console, followed by valid cashtabCache detected after refresh.
- register a new alias, refresh the page, and ensure cashtabCache is still valid via console log. In localforage keypairs ensure aliases in aliasCache has been updated with your new alias and paymentTxHistory and totalPaymentTxCount params incremented correctly.
- create a new wallet, switch to it, navigate to the Alias page and ensure no errors in the console log.
Reviewers: bytesofman, #bitcoin_abc
Reviewed By: bytesofman, #bitcoin_abc
Differential Revision: https://reviews.bitcoinabc.org/D13085