-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use capabilities instead of connectorId for feature detection (#1069)
- Loading branch information
Showing
2 changed files
with
43 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
A hook to safely check wallet_getCapabilities support | ||
Responsabilities: | ||
- Check for unsupported wallets (e.g: metamask) | ||
- Use experimental useCapabilities | ||
- Check atomicBatch (batchcall) and paymasterService for a given chain | ||
- Default to false | ||
*/ | ||
|
||
import { Chain } from 'viem'; | ||
import { useAccount } from 'wagmi'; | ||
import { useCapabilities } from 'wagmi/experimental'; | ||
|
||
export type UseCapabilitiesSafeProps = { | ||
chain: Chain; | ||
}; | ||
|
||
export default function useCapabilitiesSafe({ chain }: UseCapabilitiesSafeProps) { | ||
const { connector, isConnected } = useAccount(); | ||
|
||
// Metamask doesn't support wallet_getCapabilities | ||
const isMetamaskWallet = connector?.id === 'io.metamask'; | ||
const enabled = isConnected && !isMetamaskWallet; | ||
|
||
const { data: capabilities } = useCapabilities({ query: { enabled } }); | ||
|
||
const atomicBatchEnabled = | ||
(capabilities && capabilities[chain.id]?.atomicBatch?.supported === true) ?? false; | ||
const paymasterServiceEnabled = | ||
(capabilities && capabilities[chain.id]?.paymasterService?.supported === true) ?? false; | ||
|
||
return { | ||
atomicBatchEnabled, | ||
paymasterServiceEnabled, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters