-
Notifications
You must be signed in to change notification settings - Fork 158
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
Changes from all commits
b2cb5a7
7244644
55e3e00
a3a536e
dc3e28b
3b11d7f
5fcbd35
caf783f
35f86ec
4ee404e
a96bf66
b705e42
2fb8811
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@coinbase/onchainkit': patch | ||
--- | ||
|
||
**feat**: re-typed walletCapabilities object in `OnchainKitConfig`. by @0xAlec #1238 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Capabilities | ||
export enum Capabilities { | ||
AtomicBatch = 'atomicBatch', | ||
AuxiliaryFunds = 'auxiliaryFunds', | ||
PaymasterService = 'paymasterService', | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useMemo } from 'react'; | ||
import type { WalletCapabilities } from 'viem'; | ||
import { useAccount } from 'wagmi'; | ||
import { useCapabilities } from 'wagmi/experimental'; | ||
import type { UseCapabilitiesSafeParams } from '../../types'; | ||
|
||
export function useCapabilitiesSafe({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still feel like we should rename this There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (which isn't supported in the vanilla Wagmi hook - hence There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd also say the vanilla Wagmi hook is |
||
chainId, | ||
}: UseCapabilitiesSafeParams): WalletCapabilities { | ||
const { isConnected } = useAccount(); | ||
|
||
const { data: capabilities, error } = useCapabilities({ | ||
query: { enabled: isConnected }, | ||
}); | ||
|
||
return useMemo(() => { | ||
if (error || !capabilities || !capabilities[chainId]) { | ||
return {}; | ||
} | ||
|
||
return capabilities[chainId]; | ||
}, [capabilities, chainId, error]); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,15 +7,17 @@ import { | |
useState, | ||
} from 'react'; | ||
import type { Address } from 'viem'; | ||
import { baseSepolia } from 'viem/chains'; | ||
import { | ||
useAccount, | ||
useConfig, | ||
useSwitchChain, | ||
useWaitForTransactionReceipt, | ||
} from 'wagmi'; | ||
import { waitForTransactionReceipt } from 'wagmi/actions'; | ||
import { Capabilities } from '../../constants'; | ||
import { useCapabilitiesSafe } from '../../internal/hooks/useCapabilitiesSafe'; | ||
import { useValue } from '../../internal/hooks/useValue'; | ||
import { useOnchainKit } from '../../useOnchainKit'; | ||
import { | ||
GENERIC_ERROR_MESSAGE, | ||
TRANSACTION_TYPE_CALLS, | ||
|
@@ -77,7 +79,9 @@ export function TransactionProvider({ | |
: TRANSACTION_TYPE_CONTRACTS; | ||
|
||
// Retrieve wallet capabilities | ||
const { walletCapabilities } = useOnchainKit(); | ||
const walletCapabilities = useCapabilitiesSafe({ | ||
chainId: chainId || baseSepolia.id, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to make sure we handle this correctly where:
We can not merge this PR, if this is not present! Just FYI |
||
}); // defaults to Base Sepolia if not provided | ||
|
||
const { switchChainAsync } = useSwitchChain(); | ||
|
||
|
@@ -127,7 +131,8 @@ export function TransactionProvider({ | |
// For batched, use statusSendCalls or statusWriteContracts | ||
// For single, use statusSendCall or statusWriteContract | ||
const transactionStatus = useMemo(() => { | ||
const transactionStatuses = walletCapabilities.hasAtomicBatch | ||
const transactionStatuses = walletCapabilities[Capabilities.AtomicBatch] | ||
?.supported | ||
? { | ||
[TRANSACTION_TYPE_CALLS]: statusSendCalls, | ||
[TRANSACTION_TYPE_CONTRACTS]: statusWriteContracts, | ||
|
@@ -143,7 +148,7 @@ export function TransactionProvider({ | |
statusSendCall, | ||
statusWriteContract, | ||
transactionType, | ||
walletCapabilities.hasAtomicBatch, | ||
walletCapabilities[Capabilities.AtomicBatch], | ||
]); | ||
|
||
// Transaction hash for single transaction (non-batched) | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.