diff --git a/icons/error-pages/403.svg b/icons/error-pages/403.svg new file mode 100644 index 0000000000..d4369a0a61 --- /dev/null +++ b/icons/error-pages/403.svg @@ -0,0 +1,3 @@ + diff --git a/public/icons/name.d.ts b/public/icons/name.d.ts index 4126633c3e..a0d663bdde 100644 --- a/public/icons/name.d.ts +++ b/public/icons/name.d.ts @@ -55,6 +55,7 @@ | "empty_search_result" | "ENS_slim" | "ENS" + | "error-pages/403" | "error-pages/404" | "error-pages/422" | "error-pages/429" diff --git a/ui/address/utils/useAddressQuery.ts b/ui/address/utils/useAddressQuery.ts index 3f1ae73929..391210a78c 100644 --- a/ui/address/utils/useAddressQuery.ts +++ b/ui/address/utils/useAddressQuery.ts @@ -25,6 +25,8 @@ interface Params { isEnabled?: boolean; } +const NO_RPC_FALLBACK_ERROR_CODES = [ 403 ]; + export default function useAddressQuery({ hash, isEnabled = true }: Params): AddressQuery { const [ isRefetchEnabled, setRefetchEnabled ] = React.useState(false); @@ -92,7 +94,7 @@ export default function useAddressQuery({ hash, isEnabled = true }: Params): Add }; }, placeholderData: [ GET_BALANCE ], - enabled: apiQuery.isError || apiQuery.errorUpdateCount > 0, + enabled: (apiQuery.isError || apiQuery.errorUpdateCount > 0) && !(apiQuery.error?.status && NO_RPC_FALLBACK_ERROR_CODES.includes(apiQuery.error?.status)), retry: false, refetchOnMount: false, }); @@ -107,7 +109,7 @@ export default function useAddressQuery({ hash, isEnabled = true }: Params): Add } else if (!apiQuery.isError) { setRefetchEnabled(false); } - }, [ apiQuery.errorUpdateCount, apiQuery.isError, apiQuery.isPlaceholderData ]); + }, [ apiQuery.errorUpdateCount, apiQuery.isError, apiQuery.isPlaceholderData, apiQuery.error?.status ]); React.useEffect(() => { if (!rpcQuery.isPlaceholderData && !rpcQuery.data) { @@ -115,7 +117,14 @@ export default function useAddressQuery({ hash, isEnabled = true }: Params): Add } }, [ rpcQuery.data, rpcQuery.isPlaceholderData ]); - const isRpcQuery = Boolean((apiQuery.isError || apiQuery.isPlaceholderData) && apiQuery.errorUpdateCount > 0 && rpcQuery.data && publicClient); + const isRpcQuery = Boolean( + (apiQuery.isError || apiQuery.isPlaceholderData) && + !(apiQuery.error?.status && NO_RPC_FALLBACK_ERROR_CODES.includes(apiQuery.error?.status)) && + apiQuery.errorUpdateCount > 0 && + rpcQuery.data && + publicClient, + ); + const query = isRpcQuery ? rpcQuery as UseQueryResult
> : apiQuery; return { diff --git a/ui/shared/AppError/AppError.pw.tsx b/ui/shared/AppError/AppError.pw.tsx index c4ec388e37..0cd6acbdca 100644 --- a/ui/shared/AppError/AppError.pw.tsx +++ b/ui/shared/AppError/AppError.pw.tsx @@ -20,6 +20,12 @@ test('status code 422', async({ render }) => { await expect(component).toHaveScreenshot(); }); +test('status code 403', async({ render }) => { + const error = { message: 'Test', cause: { status: 403 } } as Error; + const component = await render(