Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ClusterProvider to remove legacy web3js dependency #267

Merged
merged 5 commits into from
Jul 14, 2023

Conversation

mcintyre94
Copy link
Collaborator

This provider makes 3 requests, and makes their responses available to child components:

  • getFirstAvailableBlock
  • getEpochInfo
  • getEpochSchedule

The first 2 are reasonably straightforward, we have basically the same structure as the legacy web3js, with just number/bigint changes.

getEpochSchedule is a bit more complex. The existing API exposes a class with a bunch of functionality for finding the epoch for a slot, and the first/last slot for an epoch. None of this is RPC functionality, it's all baked into the legacy web3js code. Since the experimental web3js doesn't do any of that, I've copied these functions into the Explorer codebase, as pure functions that take an EpochSchedule (pure data returned by the new RPC method) and a slot/epoch (bigint).

See existing web3js code here: https://github.com/solana-labs/solana-web3.js/blob/9232d2b1019dc50f852ad70aa81624e751d76161/packages/library-legacy/src/epoch-schedule.ts

Also note that I hit a bug in experimental web3js where some of these functions are incorrectly typed as unknown: solana-labs/solana-web3.js#1389
This was easy enough to work around for now

I've also moved localStorageIsAvailable from utils/index.ts to its own utils/local-storage. This lets us import it without pulling in the web3js dependency in utils/index.ts

The result of this PR is that the ClusterProvider in the root layout no longer pulls in the legacy web3js dependency.

@vercel
Copy link

vercel bot commented Jul 11, 2023

@mcintyre94 is attempting to deploy a commit to the Solana Labs Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Jul 11, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
explorer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 14, 2023 2:05pm

Copy link
Collaborator

@steveluscher steveluscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

giphy

app/components/SearchBar.tsx Outdated Show resolved Hide resolved
app/providers/cluster.tsx Outdated Show resolved Hide resolved
app/utils/cluster.ts Outdated Show resolved Hide resolved
app/epoch/[epoch]/page-client.tsx Outdated Show resolved Hide resolved
app/providers/cluster.tsx Show resolved Hide resolved
app/utils/local-storage.ts Outdated Show resolved Hide resolved
app/utils/local-storage.ts Outdated Show resolved Hide resolved
@mcintyre94 mcintyre94 merged commit a292352 into solana-labs:master Jul 14, 2023
3 checks passed
@mcintyre94 mcintyre94 deleted the home-providers-refactor branch July 14, 2023 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants