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..403e568ddc 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); @@ -35,6 +37,10 @@ export default function useAddressQuery({ hash, isEnabled = true }: Params): Add placeholderData: ADDRESS_INFO, refetchOnMount: false, retry: (failureCount, error) => { + if (error.status < 500) { + return false; + } + if (isRefetchEnabled) { return false; } @@ -92,7 +98,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) && !NO_RPC_FALLBACK_ERROR_CODES.includes(apiQuery.error?.status ?? 999), retry: false, refetchOnMount: false, }); @@ -107,7 +113,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 +121,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) && + !NO_RPC_FALLBACK_ERROR_CODES.includes(apiQuery.error?.status ?? 999) && + apiQuery.errorUpdateCount > 0 && + rpcQuery.data && + publicClient, + ); + const query = isRpcQuery ? rpcQuery as UseQueryResult
> : apiQuery; return { diff --git a/ui/shared/AppError/AppError.tsx b/ui/shared/AppError/AppError.tsx index aca50cf4d0..c93786ba1b 100644 --- a/ui/shared/AppError/AppError.tsx +++ b/ui/shared/AppError/AppError.tsx @@ -24,6 +24,10 @@ interface Props { } const ERROR_TEXTS: Record