hyperlane-xyz / hyperlane-explorer

Web app for the Hyperlane Explorer
https://explorer.hyperlane.xyz
Other
50 stars 46 forks source link

Fetch CoreChains dynamically from the DB domains table #74

Open jmrossy opened 1 month ago

jmrossy commented 1 month ago

Currently it imports CoreChains from the Registry lib to determine if scraped. It would be better to query the DB for this information.

Once this is done, remove the hard-coded CoreChains list from the registry as it's no longer needed.

https://discord.com/channels/935678348330434570/935678739663192184/1241041835976294442

jmrossy commented 2 days ago

The general approach here is to remove uses of CoreChains from @hyperlane-xyz/registry and instead query the domain table via Hasura's GraphQL API. See below for pics of the domain table.

If the scraped chain list could be retrieved synchronously, this would be an easy change: just swap that in where we currently reach for the registry export. That's not possible here; it will need to be fetched via an async GraphQL query via the urql lib.

There are a few ways to solve this kind of problem in a react app:

  1. Create a new useDatabaseChains() hook which executes a query. Depending on how well urql caches the data, we may need to push that data into the zustand state store.
  2. Add a new wrapper component in _app.ts which suspends the normal app tree until this data is available.
  3. Trigger an effect somewhere that performs a one-off graphql query and places the data either in the store (preferable) or just in some global state somewhere

Either way, given that utils like isPiChain currently assume this data is globally and synchronously available, some refactoring will be needed. Overall, not a small task but not huge either.

Some relevant files:

Screenshot 2024-07-02 at 2 31 36 PM Screenshot 2024-07-02 at 2 32 18 PM