Fix error handling

This commit is contained in:
Willian Mitsuda 2022-08-22 19:57:19 -03:00
parent 5e5dc6f20a
commit 7c0d06dd8f
No known key found for this signature in database
2 changed files with 21 additions and 8 deletions

View File

@ -30,8 +30,6 @@ import { ChecksummedAddress } from "./types";
type AddressMainPageProps = {}; type AddressMainPageProps = {};
const AddressMainPage: React.FC<AddressMainPageProps> = ({}) => { const AddressMainPage: React.FC<AddressMainPageProps> = ({}) => {
const { provider } = useContext(RuntimeContext);
const { addressOrName, direction } = useParams(); const { addressOrName, direction } = useParams();
if (addressOrName === undefined) { if (addressOrName === undefined) {
throw new Error("addressOrName couldn't be undefined here"); throw new Error("addressOrName couldn't be undefined here");
@ -55,6 +53,7 @@ const AddressMainPage: React.FC<AddressMainPageProps> = ({}) => {
urlFixer urlFixer
); );
const { provider } = useContext(RuntimeContext);
const hasCode = useHasCode(provider, checksummedAddress, "latest"); const hasCode = useHasCode(provider, checksummedAddress, "latest");
const addressMetadata = useSourcifyMetadata( const addressMetadata = useSourcifyMetadata(
hasCode ? checksummedAddress : undefined, hasCode ? checksummedAddress : undefined,

View File

@ -1,6 +1,7 @@
import React, { useCallback, useContext, useEffect, useState } from "react"; import React, { useCallback, useContext, useEffect, useState } from "react";
import { useNavigate, useParams, useSearchParams } from "react-router-dom"; import { useNavigate, useParams, useSearchParams } from "react-router-dom";
import StandardFrame from "./StandardFrame"; import StandardFrame from "./StandardFrame";
import AddressOrENSNameNotFound from "./components/AddressOrENSNameNotFound";
import AddressOrENSNameInvalidNonce from "./components/AddressOrENSNameInvalidNonce"; import AddressOrENSNameInvalidNonce from "./components/AddressOrENSNameInvalidNonce";
import AddressOrENSNameNoTx from "./components/AddressOrENSNameNoTx"; import AddressOrENSNameNoTx from "./components/AddressOrENSNameNoTx";
import { useTransactionBySenderAndNonce } from "./useErigonHooks"; import { useTransactionBySenderAndNonce } from "./useErigonHooks";
@ -36,7 +37,7 @@ const AddressTransactionByNonce: React.FC<AddressTransactionByNonceProps> = ({
}, },
[navigate, direction, searchParams] [navigate, direction, searchParams]
); );
const [checksummedAddress, isENS, error] = useAddressOrENS( const [checksummedAddress, , ensError] = useAddressOrENS(
addressOrName, addressOrName,
urlFixer urlFixer
); );
@ -77,12 +78,20 @@ const AddressTransactionByNonce: React.FC<AddressTransactionByNonceProps> = ({
nonce !== undefined && isNaN(nonce) ? undefined : nonce nonce !== undefined && isNaN(nonce) ? undefined : nonce
); );
// Invalid ENS
if (ensError) {
return (
<StandardFrame>
<AddressOrENSNameNotFound
addressOrENSName={addressOrName}
supportsENS={provider?.network.ensAddress !== undefined}
/>
</StandardFrame>
);
}
// Loading... // Loading...
if ( if (checksummedAddress === undefined || nonce === undefined) {
checksummedAddress === undefined ||
nonce === undefined ||
txHash === undefined
) {
return <StandardFrame />; return <StandardFrame />;
} }
@ -107,6 +116,11 @@ const AddressTransactionByNonce: React.FC<AddressTransactionByNonceProps> = ({
); );
} }
// Valid nonce, waiting tx load
if (txHash === undefined) {
return <StandardFrame />;
}
// Valid nonce, but no tx found // Valid nonce, but no tx found
if (txHash === null) { if (txHash === null) {
return ( return (