@@ -25,6 +25,8 @@ interface Params {
25
25
isEnabled ?: boolean ;
26
26
}
27
27
28
+ const NO_RPC_FALLBACK_ERROR_CODES = [ 403 ] ;
29
+
28
30
export default function useAddressQuery ( { hash, isEnabled = true } : Params ) : AddressQuery {
29
31
const [ isRefetchEnabled , setRefetchEnabled ] = React . useState ( false ) ;
30
32
@@ -92,7 +94,7 @@ export default function useAddressQuery({ hash, isEnabled = true }: Params): Add
92
94
} ;
93
95
} ,
94
96
placeholderData : [ GET_BALANCE ] ,
95
- enabled : apiQuery . isError || apiQuery . errorUpdateCount > 0 ,
97
+ enabled : ( apiQuery . isError || apiQuery . errorUpdateCount > 0 ) && ! ( apiQuery . error ?. status && NO_RPC_FALLBACK_ERROR_CODES . includes ( apiQuery . error ?. status ) ) ,
96
98
retry : false ,
97
99
refetchOnMount : false ,
98
100
} ) ;
@@ -107,15 +109,22 @@ export default function useAddressQuery({ hash, isEnabled = true }: Params): Add
107
109
} else if ( ! apiQuery . isError ) {
108
110
setRefetchEnabled ( false ) ;
109
111
}
110
- } , [ apiQuery . errorUpdateCount , apiQuery . isError , apiQuery . isPlaceholderData ] ) ;
112
+ } , [ apiQuery . errorUpdateCount , apiQuery . isError , apiQuery . isPlaceholderData , apiQuery . error ?. status ] ) ;
111
113
112
114
React . useEffect ( ( ) => {
113
115
if ( ! rpcQuery . isPlaceholderData && ! rpcQuery . data ) {
114
116
setRefetchEnabled ( false ) ;
115
117
}
116
118
} , [ rpcQuery . data , rpcQuery . isPlaceholderData ] ) ;
117
119
118
- const isRpcQuery = Boolean ( ( apiQuery . isError || apiQuery . isPlaceholderData ) && apiQuery . errorUpdateCount > 0 && rpcQuery . data && publicClient ) ;
120
+ const isRpcQuery = Boolean (
121
+ ( apiQuery . isError || apiQuery . isPlaceholderData ) &&
122
+ ! ( apiQuery . error ?. status && NO_RPC_FALLBACK_ERROR_CODES . includes ( apiQuery . error ?. status ) ) &&
123
+ apiQuery . errorUpdateCount > 0 &&
124
+ rpcQuery . data &&
125
+ publicClient ,
126
+ ) ;
127
+
119
128
const query = isRpcQuery ? rpcQuery as UseQueryResult < Address , ResourceError < { status : number } > > : apiQuery ;
120
129
121
130
return {
0 commit comments