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

Potential Future API design #20

Open
kesne opened this issue Oct 12, 2021 · 0 comments
Open

Potential Future API design #20

kesne opened this issue Oct 12, 2021 · 0 comments
Labels
enhancement New feature or request future

Comments

@kesne
Copy link
Owner

kesne commented Oct 12, 2021

The current API design is heavily hook-based, which makes sense given some of our current constraints and design inspiration. However, as we continue to evolve the API and lean more and more into the suspense- and concurrent- based API patterns, we can simplify the API design so that it does not depend as heavily on hooks.

One of the benefits of this API design is that all of the non-hook APIs can be called conditionally, instead of needing to be called unconditionally to follow the rules of hooks.

A note on providers

The core of providers shouldn't need any work, as they are the most foundational piece of the library, and must exist in react context.

  • useLogout - This API is probably fine, as it just returns a method that uses a value read out of the context.
  • useWeb3Modal - This is only for advanced use-cases, and just reads a value out of context.
  • WalletProvider - This initializes some values into a context, and renders a Provider.
  • Provider - This just provides values into context.
  • useProvider - This just reads values out of the context.

Thick Providers

I still need to write about this in more depth, but the TL;DR is that we'll have a new provider class, which has the following:

  • Built-in cache response.
  • Methods on the provider that trigger suspsense.
const provider = useProvider();
const address = provider.getUserAddress();
const balance = provider.getBalance(address);

We probably should figure out a new name for provider with this though.

Downsides:

  • Always requires a call to get the provider.
  • Lack of hooks means we can't effectively retain + LRU cache responses, potentially infinite cache growth.
@kesne kesne added enhancement New feature or request future labels Oct 12, 2021
@kesne kesne changed the title Future API design Potential Future API design Oct 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request future
Projects
None yet
Development

No branches or pull requests

1 participant