Add failed tx error msg support; depends on ots_getTransactionError custom API
This commit is contained in:
parent
8b33337e49
commit
0754c4f4bf
|
@ -1,3 +1,3 @@
|
||||||
export const MIN_API_LEVEL = 4;
|
export const MIN_API_LEVEL = 5;
|
||||||
|
|
||||||
export const PAGE_SIZE = 25;
|
export const PAGE_SIZE = 25;
|
||||||
|
|
|
@ -41,6 +41,7 @@ import { DevDoc, UserDoc } from "../sourcify/useSourcify";
|
||||||
import { ResolvedAddresses } from "../api/address-resolver";
|
import { ResolvedAddresses } from "../api/address-resolver";
|
||||||
import { RuntimeContext } from "../useRuntime";
|
import { RuntimeContext } from "../useRuntime";
|
||||||
import { useContractsMetadata } from "../hooks";
|
import { useContractsMetadata } from "../hooks";
|
||||||
|
import { useTransactionError } from "../useErigonHooks";
|
||||||
|
|
||||||
type DetailsProps = {
|
type DetailsProps = {
|
||||||
txData: TransactionData;
|
txData: TransactionData;
|
||||||
|
@ -96,6 +97,7 @@ 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);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ContentFrame tabs>
|
<ContentFrame tabs>
|
||||||
|
@ -114,10 +116,19 @@ const Details: React.FC<DetailsProps> = ({
|
||||||
<span>Success</span>
|
<span>Success</span>
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
<span className="flex items-center w-min rounded-lg space-x-1 px-3 py-1 bg-red-50 text-red-500 text-xs">
|
<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" />
|
<FontAwesomeIcon icon={faTimesCircle} size="1x" />
|
||||||
<span>Fail</span>
|
<span>
|
||||||
|
Fail
|
||||||
|
{errorMsg && (
|
||||||
|
<>
|
||||||
|
{" "}
|
||||||
|
with revert message: '
|
||||||
|
<span className="font-bold underline">{errorMsg}</span>'
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
</InfoRow>
|
</InfoRow>
|
||||||
{txData.confirmedData && (
|
{txData.confirmedData && (
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { Block, BlockWithTransactions } from "@ethersproject/abstract-provider";
|
||||||
import { JsonRpcProvider } from "@ethersproject/providers";
|
import { JsonRpcProvider } from "@ethersproject/providers";
|
||||||
import { getAddress } from "@ethersproject/address";
|
import { getAddress } from "@ethersproject/address";
|
||||||
import { Contract } from "@ethersproject/contracts";
|
import { Contract } from "@ethersproject/contracts";
|
||||||
|
import { defaultAbiCoder } from "@ethersproject/abi";
|
||||||
import { BigNumber } from "@ethersproject/bignumber";
|
import { BigNumber } from "@ethersproject/bignumber";
|
||||||
import { arrayify, hexDataSlice, isHexString } from "@ethersproject/bytes";
|
import { arrayify, hexDataSlice, isHexString } from "@ethersproject/bytes";
|
||||||
import { extract4Bytes } from "./use4Bytes";
|
import { extract4Bytes } from "./use4Bytes";
|
||||||
|
@ -484,3 +485,37 @@ export const useAddressesWithCode = (
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useTransactionError = (
|
||||||
|
provider: JsonRpcProvider | undefined,
|
||||||
|
txHash: string
|
||||||
|
): string | undefined => {
|
||||||
|
const [errorMsg, setErrorMsg] = useState<string | undefined>();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Reset
|
||||||
|
setErrorMsg(undefined);
|
||||||
|
|
||||||
|
if (provider === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const readCodes = async () => {
|
||||||
|
const result = (await provider.send("ots_getTransactionError", [
|
||||||
|
txHash,
|
||||||
|
])) as string;
|
||||||
|
|
||||||
|
// Filter hardcoded Error(string) selector because ethers don't let us
|
||||||
|
// construct it
|
||||||
|
if (result.substr(0, 10) !== "0x08c379a0") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const msg = defaultAbiCoder.decode(["string"], "0x" + result.substr(10));
|
||||||
|
setErrorMsg(msg[0]);
|
||||||
|
};
|
||||||
|
readCodes();
|
||||||
|
}, [provider, txHash]);
|
||||||
|
|
||||||
|
return errorMsg;
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue