11import { useCapabilities } from 'wagmi' ;
22import { useDappStatus } from './use-dapp-status' ;
33
4+ const isCapabilitySupported = ( capability ?: {
5+ supported ?: boolean ;
6+ status ?: 'supported' | 'ready' | 'unsupported' ;
7+ } ) => {
8+ if ( ! capability ) return false ;
9+
10+ if ( typeof capability . status === 'string' ) {
11+ return capability . status != 'unsupported' ;
12+ }
13+
14+ return ! ! capability . supported ;
15+ } ;
16+
417export const useAA = ( ) => {
518 const { chainId, isAccountActive } = useDappStatus ( ) ;
619 const capabilitiesQuery = useCapabilities ( {
@@ -17,11 +30,18 @@ export const useAA = () => {
1730 }
1831 : undefined ;
1932
20- // per EIP-5792 ANY successful call to getCapabilities is a sign of EIP support
21- const isAA = capabilitiesQuery . isFetched && ! ! capabilitiesQuery . data ;
33+ const isAtomicBatchSupported =
34+ isCapabilitySupported ( capabilities ?. atomic ) ||
35+ // legacy
36+ isCapabilitySupported ( capabilities ?. atomicBatch ) ;
37+
38+ const areAuxiliaryFundsSupported = isCapabilitySupported (
39+ capabilities ?. auxiliaryFunds ,
40+ ) ;
2241
23- const isAtomicBatchSupported = ! ! capabilities ?. atomicBatch ?. supported ;
24- const areAuxiliaryFundsSupported = ! ! capabilities ?. auxiliaryFunds ?. supported ;
42+ // per EIP-5792 ANY successful call to getCapabilities is a sign of EIP support
43+ // but MM is not following the spec properly
44+ const isAA = capabilitiesQuery . isFetched && isAtomicBatchSupported ;
2545
2646 return {
2747 ...capabilitiesQuery ,
0 commit comments