osmosis-labs / osmosis-frontend

Web interface for Osmosis Zone
https://app.osmosis.zone/
Apache License 2.0
232 stars 423 forks source link

Data store improvements #1180

Closed jonator closed 1 year ago

jonator commented 1 year ago

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:

jonator commented 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/