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: re-type walletCapabilities object #1238

Merged
merged 13 commits into from
Sep 16, 2024
Merged

feat: re-type walletCapabilities object #1238

merged 13 commits into from
Sep 16, 2024

Conversation

0xAlec
Copy link
Contributor

@0xAlec 0xAlec commented Sep 11, 2024

What changed? Why?

  • use viem native typing for walletCapabilities object
  • move useCapabilitiesSafe to internal/hooks and call on a per-component basis
  • memoize useCapabilitiesSafe

now developers can use capabilities that are not explicitly supported by OnchainKit since we are using the native viem typing

Notes to reviewers

How has it been tested?

Copy link

vercel bot commented Sep 11, 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 13, 2024 3:09pm
onchainkit-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 13, 2024 3:09pm
onchainkit-routes ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 13, 2024 3:09pm

AtomicBatch = 'atomicBatch',
AuxiliaryFunds = 'auxiliaryFunds',
PaymasterService = 'paymasterService',
}
Copy link
Contributor Author

@0xAlec 0xAlec Sep 11, 2024

Choose a reason for hiding this comment

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

we'll still need to use this enum for any capabilities we support in OnchainKit but now developers can use non-OCK supported capabilities since it isn't custom typed anymore

const { walletCapabilities } = useOnchainKit()

if (walletCapabilities[someOtherCapability]){
  ...
}

Copy link
Contributor

Choose a reason for hiding this comment

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

For each of them, we should probably add a comment that links on where the EIP is.

Just because I can imagine a convo in 2 months where someone else tries to figure out what those are and they take a few to find the correct docs.

hasAuxiliaryFunds: false,
hasPaymasterService: false,
},
walletCapabilities: {},
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not expose this at all here, but instead being part of his own Hook.

Also this change will trigger a braking change, so we need to time this merge correctly.

hasAuxiliaryFunds: false,
hasPaymasterService: false,
},
walletCapabilities: walletCapabilities ?? {},
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be store here anymore!

But instead our useCapabilities hook should memoize this info.

And long story short we should have a

import { useCapabilities } from `@coinbase/onchainkit`;

and just use that around the library to get the data.

import { useCapabilities } from 'wagmi/experimental';
import type { UseCapabilitiesSafeParams } from '../../types';

export function useCapabilitiesSafe({
Copy link
Contributor

Choose a reason for hiding this comment

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

I still feel like we should rename this useCapabilities, as the fact that we are not exporting this externally adding the word Safe just feels odd.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it will make more sense once we add the functionality to debounce or stop subsequent calls to non-EIP5792 wallets on this hook

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(which isn't supported in the vanilla Wagmi hook - hence unsafe)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd also say the vanilla Wagmi hook is unsafe because it does not return an empty object for non-EIP5792 wallets

@@ -18,7 +19,7 @@ export const useSendWalletTransactions = ({
if (!transactions) {
return;
}
if (walletCapabilities.hasAtomicBatch) {
if (walletCapabilities[Capabilities.AtomicBatch]?.supported) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I like the enum, is very clean

@@ -77,7 +78,9 @@ export function TransactionProvider({
: TRANSACTION_TYPE_CONTRACTS;

// Retrieve wallet capabilities
const { walletCapabilities } = useOnchainKit();
const walletCapabilities = useCapabilitiesSafe({
chainId: chainId || 84532,
Copy link
Contributor

@Zizzamia Zizzamia Sep 12, 2024

Choose a reason for hiding this comment

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

I feel like using baseSepolia.id from Viem is a bit more clean

@@ -77,7 +79,9 @@ export function TransactionProvider({
: TRANSACTION_TYPE_CONTRACTS;

// Retrieve wallet capabilities
const { walletCapabilities } = useOnchainKit();
const walletCapabilities = useCapabilitiesSafe({
chainId: chainId || baseSepolia.id,
Copy link
Contributor

@Zizzamia Zizzamia Sep 14, 2024

Choose a reason for hiding this comment

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

We need to make sure we handle this correctly where:

  • we prioritize the chainId from the Transaction component
  • if that not present we use the chainId from useOnchainKit()
  • which if not present at OnchainKit config defaults to BaseSepolia.

We can not merge this PR, if this is not present! Just FYI
cc @0xAlec @alessey @cpcramer @abcrane123

import type { Config } from 'wagmi';
import type {
SendTransactionMutateAsync,
WriteContractMutateAsync,
} from 'wagmi/query';
import type { WalletCapabilities as OnchainKitWalletCapabilities } from '../types';
// 🌲☀🌲
Copy link
Contributor

Choose a reason for hiding this comment

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

Not big deal, but this is an easter egg that should alway be as first line only :)

So you probably want to remove it from here

Copy link
Contributor

@Zizzamia Zizzamia left a comment

Choose a reason for hiding this comment

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

Merging the PR as it is, and then fixing this in a quick follow.

@Zizzamia Zizzamia merged commit 603d02c into main Sep 16, 2024
16 checks passed
@Zizzamia Zizzamia deleted the eip5792-retype branch September 16, 2024 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants