Error handling UI improvements

This commit is contained in:
Willian Mitsuda 2022-01-29 20:44:26 -03:00
parent d70c22b5a0
commit 20fc443009
4 changed files with 70 additions and 11 deletions

View File

@ -2,6 +2,7 @@ import React, { useCallback, useContext } 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 AddressOrENSNameNotFound from "./components/AddressOrENSNameNotFound";
import AddressOrENSNameInvalidNonce from "./components/AddressOrENSNameInvalidNonce";
import { ChecksummedAddress } from "./types"; import { ChecksummedAddress } from "./types";
import { transactionURL } from "./url"; import { transactionURL } from "./url";
import { useTransactionBySenderAndNonce } from "./useErigonHooks"; import { useTransactionBySenderAndNonce } from "./useErigonHooks";
@ -25,18 +26,15 @@ const AddressTransaction: React.FC = () => {
}, },
[navigate, searchParams] [navigate, searchParams]
); );
const [checksummedAddress, isENS, error] = useAddressOrENS( const [checksummedAddress, , error] = useAddressOrENS(
addressOrName, addressOrName,
urlFixer urlFixer
); );
const rawNonce = searchParams.get("nonce"); const rawNonce = searchParams.get("nonce");
if (rawNonce === null) {
throw new Error("rawNonce couldn't be undefined here");
}
let nonce: number | undefined = undefined; let nonce: number | undefined = undefined;
try { try {
nonce = parseInt(rawNonce); nonce = rawNonce === null ? undefined : parseInt(rawNonce);
} catch (err) { } catch (err) {
// ignore // ignore
} }
@ -48,7 +46,35 @@ const AddressTransaction: React.FC = () => {
); );
if (error) { if (error) {
return <AddressOrENSNameNotFound addressOrENSName={addressOrName} />; return (
<StandardFrame>
<AddressOrENSNameNotFound addressOrENSName={addressOrName} />
</StandardFrame>
);
}
if (checksummedAddress !== undefined && rawNonce === null) {
return (
<StandardFrame>
<AddressOrENSNameInvalidNonce
addressOrENSName={checksummedAddress}
nonce={"undefined"}
/>
</StandardFrame>
);
}
if (
checksummedAddress !== undefined &&
nonce !== undefined &&
txHash === null
) {
return (
<StandardFrame>
<AddressOrENSNameInvalidNonce
addressOrENSName={checksummedAddress}
nonce={nonce.toString()}
/>
</StandardFrame>
);
} }
if (txHash) { if (txHash) {
navigate(transactionURL(txHash)); navigate(transactionURL(txHash));

View File

@ -1,11 +1,12 @@
import React, { useContext } from "react"; import React, { useContext } from "react";
import PlainAddress from "./PlainAddress";
import { resolverRendererRegistry } from "../api/address-resolver"; import { resolverRendererRegistry } from "../api/address-resolver";
import { useResolvedAddress } from "../useResolvedAddresses"; import { useResolvedAddress } from "../useResolvedAddresses";
import { RuntimeContext } from "../useRuntime"; import { RuntimeContext } from "../useRuntime";
import PlainAddress from "./PlainAddress"; import { ChecksummedAddress } from "../types";
type AddressOrENSNameProps = { type AddressOrENSNameProps = {
address: string; address: ChecksummedAddress;
selectedAddress?: string; selectedAddress?: string;
dontOverrideColors?: boolean; dontOverrideColors?: boolean;
}; };

View File

@ -0,0 +1,25 @@
import React from "react";
import StandardSubtitle from "../StandardSubtitle";
import ContentFrame from "../ContentFrame";
import AddressOrENSName from "./AddressOrENSName";
type AddressOrENSNameInvalidNonceProps = {
addressOrENSName: string;
nonce: string;
};
const AddressOrENSNameInvalidNonce: React.FC<
AddressOrENSNameInvalidNonceProps
> = ({ addressOrENSName, nonce }) => (
<>
<StandardSubtitle>Transaction Details</StandardSubtitle>
<ContentFrame>
<div className="flex py-4 text-sm">
<AddressOrENSName address={addressOrENSName} />
<span>: no transaction found for nonce="{nonce}".</span>
</div>
</ContentFrame>
</>
);
export default React.memo(AddressOrENSNameInvalidNonce);

View File

@ -1,4 +1,6 @@
import React from "react"; import React from "react";
import StandardSubtitle from "../StandardSubtitle";
import ContentFrame from "../ContentFrame";
type AddressOrENSNameNotFoundProps = { type AddressOrENSNameNotFoundProps = {
addressOrENSName: string; addressOrENSName: string;
@ -7,9 +9,14 @@ type AddressOrENSNameNotFoundProps = {
const AddressOrENSNameNotFound: React.FC<AddressOrENSNameNotFoundProps> = ({ const AddressOrENSNameNotFound: React.FC<AddressOrENSNameNotFoundProps> = ({
addressOrENSName, addressOrENSName,
}) => ( }) => (
<span className="text-base"> <>
<StandardSubtitle>Transaction Details</StandardSubtitle>
<ContentFrame>
<div className="py-4 text-sm">
"{addressOrENSName}" is not an ETH address or ENS name. "{addressOrENSName}" is not an ETH address or ENS name.
</span> </div>
</ContentFrame>
</>
); );
export default React.memo(AddressOrENSNameNotFound); export default React.memo(AddressOrENSNameNotFound);