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

feat: EIP-5792 in OnchainKitProvider #1181

Merged
merged 23 commits into from
Sep 4, 2024
Merged

feat: EIP-5792 in OnchainKitProvider #1181

merged 23 commits into from
Sep 4, 2024

Conversation

0xAlec
Copy link
Contributor

@0xAlec 0xAlec commented Aug 29, 2024

What changed? Why?

  • add useCapabilitiesSafe hook
  • add EIP-5792 capabilities to OnchainKitProvider for consumption in child components

Notes to reviewers

How has it been tested?
unit tests and console logging the capabilities on Playground

Copy link

vercel bot commented Aug 29, 2024

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

Name Status Preview Comments Updated (UTC)
onchainkit-coverage ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 4, 2024 6:57pm
onchainkit-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 4, 2024 6:57pm
onchainkit-routes ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 4, 2024 6:57pm


// Metamask doesn't support wallet_getCapabilities
const isMetamaskWallet = connector?.id === 'io.metamask';
const enabled = isConnected && !isMetamaskWallet;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

optionally we can also just check for error returned from useCapabilities but there will still be an error displayed in the console for unsupported RPCs - IMO this is a more scalable solution than manually excluding individual connector IDs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cc @alissacrane-cb on Tanstack query best practices

src/OnchainKitProvider.tsx Outdated Show resolved Hide resolved
import type { WalletCapabilities } from './types';

export function useCapabilitiesSafe({
chain,
Copy link
Contributor

Choose a reason for hiding this comment

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

Going forward we are moving away from using chain, instead we will have directly chainId.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed in latest diff

paymaster: boolean; // If the wallet supports ERC-4337 Paymasters for gas sponsorship
batching: boolean; // If the wallet supports atomic batching of transactions
funding: boolean; // If the wallet supports auxiliary funding of accounts (e.g. Magic Spend)
};
Copy link
Contributor

Choose a reason for hiding this comment

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

mmmm if those are boolean, probably we should use the has prefix

export type WalletCapabilities = {
  hasPaymasterSupport: boolean;
  hasBatchingSupport: boolean;
  hasFundingSupport: boolean;
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let's continue this discussion on Wilson's comment below

export function useCapabilitiesSafe({
chainId,
}: UseCapabilitiesSafeParams): WalletCapabilities {
const { isConnected } = useAccount();
Copy link
Contributor

Choose a reason for hiding this comment

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

Btw as follow up PR, check with @abcrane123 if this will cause a SSR issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

i don't think this will be an issue

@coinbase coinbase deleted a comment from 0xAlec Sep 4, 2024
@coinbase coinbase deleted a comment from 0xAlec Sep 4, 2024
return {
hasPaymasterService: capabilities[chainId]?.paymasterService?.supported,
hasAtomicBatch: capabilities[chainId]?.atomicBatch?.supported,
hasAuxiliaryFunds: capabilities[chainId]?.auxiliaryFunds?.supported,
Copy link
Contributor

Choose a reason for hiding this comment

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

if these can be undefined, should they be cast to a boolean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should be fine per this test?

Copy link
Contributor

Choose a reason for hiding this comment

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

that just tests if !capabilities though right? is it possible for useCapabilities to return some of the capabilities, but not all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch :) fixed in the latest diff!

@0xAlec 0xAlec merged commit 63742da into main Sep 4, 2024
16 checks passed
@0xAlec 0xAlec deleted the alec/capabilities branch September 4, 2024 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

5 participants