Add basic structure for custom errors
This commit is contained in:
parent
d5fa5dda36
commit
f22199d7d5
|
@ -0,0 +1,22 @@
|
||||||
|
import React from "react";
|
||||||
|
import { Switch } from "@headlessui/react";
|
||||||
|
|
||||||
|
type ExpanderSwitchProps = {
|
||||||
|
expanded: boolean;
|
||||||
|
setExpanded: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
|
};
|
||||||
|
|
||||||
|
const ExpanderSwitch: React.FC<ExpanderSwitchProps> = ({
|
||||||
|
expanded,
|
||||||
|
setExpanded,
|
||||||
|
}) => (
|
||||||
|
<Switch
|
||||||
|
className="text-xs font-code"
|
||||||
|
checked={expanded}
|
||||||
|
onChange={setExpanded}
|
||||||
|
>
|
||||||
|
{expanded ? <span className="text-gray-400">[-]</span> : <>[...]</>}
|
||||||
|
</Switch>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default ExpanderSwitch;
|
|
@ -1,4 +1,5 @@
|
||||||
import React, { useContext, useMemo } from "react";
|
import React, { useContext, useMemo, useState } from "react";
|
||||||
|
import { Tab } from "@headlessui/react";
|
||||||
import { TransactionDescription } from "@ethersproject/abi";
|
import { TransactionDescription } from "@ethersproject/abi";
|
||||||
import { BigNumber } from "@ethersproject/bignumber";
|
import { BigNumber } from "@ethersproject/bignumber";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
@ -8,6 +9,8 @@ import { faTimesCircle } from "@fortawesome/free-solid-svg-icons/faTimesCircle";
|
||||||
import ContentFrame from "../ContentFrame";
|
import ContentFrame from "../ContentFrame";
|
||||||
import InfoRow from "../components/InfoRow";
|
import InfoRow from "../components/InfoRow";
|
||||||
import BlockLink from "../components/BlockLink";
|
import BlockLink from "../components/BlockLink";
|
||||||
|
import ModeTab from "../components/ModeTab";
|
||||||
|
import ExpanderSwitch from "../components/ExpanderSwitch";
|
||||||
import BlockConfirmations from "../components/BlockConfirmations";
|
import BlockConfirmations from "../components/BlockConfirmations";
|
||||||
import TransactionAddress from "../components/TransactionAddress";
|
import TransactionAddress from "../components/TransactionAddress";
|
||||||
import Copy from "../components/Copy";
|
import Copy from "../components/Copy";
|
||||||
|
@ -97,7 +100,11 @@ const Details: React.FC<DetailsProps> = ({
|
||||||
return _addresses;
|
return _addresses;
|
||||||
}, [txData]);
|
}, [txData]);
|
||||||
const metadatas = useContractsMetadata(addresses, provider);
|
const metadatas = useContractsMetadata(addresses, provider);
|
||||||
const errorMsg = useTransactionError(provider, txData.transactionHash);
|
const [errorMsg, outputData, isCustomError] = useTransactionError(
|
||||||
|
provider,
|
||||||
|
txData.transactionHash
|
||||||
|
);
|
||||||
|
const [expanded, setExpanded] = useState<boolean>(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ContentFrame tabs>
|
<ContentFrame tabs>
|
||||||
|
@ -111,24 +118,75 @@ const Details: React.FC<DetailsProps> = ({
|
||||||
{txData.confirmedData === undefined ? (
|
{txData.confirmedData === undefined ? (
|
||||||
<span className="italic text-gray-400">Pending</span>
|
<span className="italic text-gray-400">Pending</span>
|
||||||
) : txData.confirmedData.status ? (
|
) : txData.confirmedData.status ? (
|
||||||
<span className="flex items-center w-min rounded-lg space-x-1 px-3 py-1 bg-green-50 text-green-500 text-xs">
|
<span className="flex items-baseline w-min rounded-lg space-x-1 px-3 py-1 bg-green-50 text-green-500 text-xs">
|
||||||
<FontAwesomeIcon icon={faCheckCircle} size="1x" />
|
<FontAwesomeIcon
|
||||||
|
className="self-center"
|
||||||
|
icon={faCheckCircle}
|
||||||
|
size="1x"
|
||||||
|
/>
|
||||||
<span>Success</span>
|
<span>Success</span>
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
<div className="inline-flex justify-start items-center rounded-lg space-x-1 px-3 py-1 bg-red-50 text-red-500 text-xs">
|
<>
|
||||||
<FontAwesomeIcon icon={faTimesCircle} size="1x" />
|
<div className="flex space-x-1 items-baseline">
|
||||||
<span>
|
<div className="flex rounded-lg space-x-1 px-3 py-1 bg-red-50 text-red-500 text-xs">
|
||||||
Fail
|
<FontAwesomeIcon
|
||||||
{errorMsg && (
|
className="self-center"
|
||||||
<>
|
icon={faTimesCircle}
|
||||||
{" "}
|
size="1x"
|
||||||
with revert message: '
|
/>
|
||||||
<span className="font-bold underline">{errorMsg}</span>'
|
<span>
|
||||||
</>
|
Fail
|
||||||
|
{errorMsg && (
|
||||||
|
<>
|
||||||
|
{" "}
|
||||||
|
with revert message: '
|
||||||
|
<span className="font-bold underline">{errorMsg}</span>'
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{isCustomError && <> with custom error</>}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{isCustomError && (
|
||||||
|
<ExpanderSwitch expanded={expanded} setExpanded={setExpanded} />
|
||||||
)}
|
)}
|
||||||
</span>
|
</div>
|
||||||
</div>
|
{expanded && (
|
||||||
|
<Tab.Group>
|
||||||
|
<Tab.List className="flex space-x-1 mt-2 mb-1">
|
||||||
|
<ModeTab disabled={!resolvedTxDesc}>Decoded</ModeTab>
|
||||||
|
<ModeTab>Raw</ModeTab>
|
||||||
|
</Tab.List>
|
||||||
|
<Tab.Panels>
|
||||||
|
<Tab.Panel>
|
||||||
|
{/* {fourBytes === "0x" ? (
|
||||||
|
<>No parameters</>
|
||||||
|
) : resolvedTxDesc === undefined ? (
|
||||||
|
<>Waiting for data...</>
|
||||||
|
) : resolvedTxDesc === null ? (
|
||||||
|
<>Can't decode data</>
|
||||||
|
) : (
|
||||||
|
<DecodedParamsTable
|
||||||
|
args={resolvedTxDesc.args}
|
||||||
|
paramTypes={resolvedTxDesc.functionFragment.inputs}
|
||||||
|
hasParamNames={hasParamNames}
|
||||||
|
userMethod={userMethod}
|
||||||
|
devMethod={devMethod}
|
||||||
|
resolvedAddresses={resolvedAddresses}
|
||||||
|
/>
|
||||||
|
)} */}
|
||||||
|
</Tab.Panel>
|
||||||
|
<Tab.Panel>
|
||||||
|
<textarea
|
||||||
|
className="w-full h-40 bg-gray-50 text-gray-500 font-mono focus:outline-none border rounded p-2"
|
||||||
|
value={outputData}
|
||||||
|
readOnly
|
||||||
|
/>
|
||||||
|
</Tab.Panel>
|
||||||
|
</Tab.Panels>
|
||||||
|
</Tab.Group>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</InfoRow>
|
</InfoRow>
|
||||||
{txData.confirmedData && (
|
{txData.confirmedData && (
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { Switch } from "@headlessui/react";
|
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { faBomb } from "@fortawesome/free-solid-svg-icons/faBomb";
|
import { faBomb } from "@fortawesome/free-solid-svg-icons/faBomb";
|
||||||
import TransactionAddress from "../components/TransactionAddress";
|
import TransactionAddress from "../components/TransactionAddress";
|
||||||
import FormattedBalance from "../components/FormattedBalance";
|
import FormattedBalance from "../components/FormattedBalance";
|
||||||
import FunctionSignature from "./FunctionSignature";
|
import FunctionSignature from "./FunctionSignature";
|
||||||
import InputDecoder from "./decoder/InputDecoder";
|
import InputDecoder from "./decoder/InputDecoder";
|
||||||
|
import ExpanderSwitch from "../components/ExpanderSwitch";
|
||||||
import { TraceEntry } from "../useErigonHooks";
|
import { TraceEntry } from "../useErigonHooks";
|
||||||
import { ResolvedAddresses } from "../api/address-resolver";
|
import { ResolvedAddresses } from "../api/address-resolver";
|
||||||
import {
|
import {
|
||||||
|
@ -71,17 +71,10 @@ const TraceInput: React.FC<TraceInputProps> = ({
|
||||||
<span className="whitespace-nowrap">
|
<span className="whitespace-nowrap">
|
||||||
(
|
(
|
||||||
{hasParams && (
|
{hasParams && (
|
||||||
<Switch
|
<ExpanderSwitch
|
||||||
className="text-xs"
|
expanded={expanded}
|
||||||
checked={expanded}
|
setExpanded={setExpanded}
|
||||||
onChange={setExpanded}
|
/>
|
||||||
>
|
|
||||||
{expanded ? (
|
|
||||||
<span className="text-gray-400">[-]</span>
|
|
||||||
) : (
|
|
||||||
<>[...]</>
|
|
||||||
)}
|
|
||||||
</Switch>
|
|
||||||
)}
|
)}
|
||||||
{(!hasParams || !expanded) && <>)</>}
|
{(!hasParams || !expanded) && <>)</>}
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -492,12 +492,16 @@ const ERROR_MESSAGE_SELECTOR = "0x08c379a0";
|
||||||
export const useTransactionError = (
|
export const useTransactionError = (
|
||||||
provider: JsonRpcProvider | undefined,
|
provider: JsonRpcProvider | undefined,
|
||||||
txHash: string
|
txHash: string
|
||||||
): string | undefined => {
|
): [string | undefined, string | undefined, boolean | undefined] => {
|
||||||
const [errorMsg, setErrorMsg] = useState<string | undefined>();
|
const [errorMsg, setErrorMsg] = useState<string | undefined>();
|
||||||
|
const [data, setData] = useState<string | undefined>();
|
||||||
|
const [isCustomError, setCustomError] = useState<boolean | undefined>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Reset
|
// Reset
|
||||||
setErrorMsg(undefined);
|
setErrorMsg(undefined);
|
||||||
|
setData(undefined);
|
||||||
|
setCustomError(undefined);
|
||||||
|
|
||||||
if (provider === undefined) {
|
if (provider === undefined) {
|
||||||
return;
|
return;
|
||||||
|
@ -510,6 +514,9 @@ export const useTransactionError = (
|
||||||
|
|
||||||
// Empty or success
|
// Empty or success
|
||||||
if (result === "0x") {
|
if (result === "0x") {
|
||||||
|
setErrorMsg(undefined);
|
||||||
|
setData(result);
|
||||||
|
setCustomError(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -522,11 +529,17 @@ export const useTransactionError = (
|
||||||
"0x" + result.substr(10)
|
"0x" + result.substr(10)
|
||||||
);
|
);
|
||||||
setErrorMsg(msg[0]);
|
setErrorMsg(msg[0]);
|
||||||
|
setData(result);
|
||||||
|
setCustomError(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setErrorMsg(undefined);
|
||||||
|
setData(result);
|
||||||
|
setCustomError(true);
|
||||||
};
|
};
|
||||||
readCodes();
|
readCodes();
|
||||||
}, [provider, txHash]);
|
}, [provider, txHash]);
|
||||||
|
|
||||||
return errorMsg;
|
return [errorMsg, data, isCustomError];
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue