Closed jonator closed 1 year ago
Further, still, since we'd do this refactor it may be worth investigating using react-query to handle this work of fetching/caching/invalidating data, then we could use wrapper hooks as the data stores on the resulting query data. We could rest in peace knowing the data is only queried once in the app lifecycle. Then, we could remove the use of MobX entirely for managing queried data, though I still think it's useful for the UI config stores. This may let us remove the keplr-wallet/stores dependency entirely.
See this article: https://www.andronio.me/2021/11/15/migrating-from-mobx-state-tree-to-react-query/
Problem
The organization of our query and data stores was somewhat emergent from the organization of the chain queries and not planned at a high level. We have a lot of query stores that fetch and do highly-coupled compute on low-level chain data/primitives (notably gauges, locks, etc), then we have some data stores that wrap those query stores and do additional computations. Those data stores are not in the root store, but are created and used as needed, which may or may not be inefficient as the user navigates the pages, and sometimes causes us to repeat/copy&paste the computations (I've spotted this most noticeably in the various pool card views).
Proposed Solution
We may be able to remove a lot of repeated (or dead) code by investigating the following:
Duration
s,Date
s, etc.ObservableQueryFilteredPools
class by only fetching data as it is requested by the views (by overriding thecanFetch
function). This let us avoid a full pools query in the pool detail page, amongst other areas. Though, some of our current query stores extend theHasMapStore
which will only initialize a query store (and thus kick off a query) as keys are encountered (example, gauges). We may be able to leave thoseHasMapStore
child query classes alone, but we should make sure we're only requesting data as needed with the rest of the query stores. To accomplish this, we could look into extending theHasMapStore
in more places, as it results in a small amount of code to maintain.