2022-01-31 18:37:29 +00:00
|
|
|
import React, { useContext } from "react";
|
|
|
|
import { useNavigate } from "react-router-dom";
|
|
|
|
import StandardFrame from "./StandardFrame";
|
|
|
|
import AddressOrENSNameInvalidNonce from "./components/AddressOrENSNameInvalidNonce";
|
|
|
|
import { ChecksummedAddress } from "./types";
|
|
|
|
import { transactionURL } from "./url";
|
|
|
|
import { useTransactionBySenderAndNonce } from "./useErigonHooks";
|
|
|
|
import { RuntimeContext } from "./useRuntime";
|
|
|
|
|
|
|
|
type AddressTransactionByNonceProps = {
|
|
|
|
checksummedAddress: ChecksummedAddress | undefined;
|
2022-01-31 19:26:27 +00:00
|
|
|
rawNonce: string;
|
2022-01-31 18:37:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const AddressTransactionByNonce: React.FC<AddressTransactionByNonceProps> = ({
|
|
|
|
checksummedAddress,
|
2022-01-31 19:26:27 +00:00
|
|
|
rawNonce,
|
2022-01-31 18:37:29 +00:00
|
|
|
}) => {
|
|
|
|
const { provider } = useContext(RuntimeContext);
|
2022-01-31 19:26:27 +00:00
|
|
|
|
|
|
|
const nonce = parseInt(rawNonce, 10);
|
2022-01-31 18:37:29 +00:00
|
|
|
const txHash = useTransactionBySenderAndNonce(
|
|
|
|
provider,
|
|
|
|
checksummedAddress,
|
2022-01-31 19:26:27 +00:00
|
|
|
isNaN(nonce) ? undefined : nonce
|
2022-01-31 18:37:29 +00:00
|
|
|
);
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
2022-01-31 19:35:34 +00:00
|
|
|
if (checksummedAddress === undefined) {
|
|
|
|
return <StandardFrame />;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Garbage nonce
|
|
|
|
if (isNaN(nonce)) {
|
2022-01-31 18:37:29 +00:00
|
|
|
return (
|
|
|
|
<StandardFrame>
|
|
|
|
<AddressOrENSNameInvalidNonce
|
|
|
|
addressOrENSName={checksummedAddress}
|
2022-01-31 19:26:27 +00:00
|
|
|
nonce={rawNonce}
|
2022-01-31 18:37:29 +00:00
|
|
|
/>
|
|
|
|
</StandardFrame>
|
|
|
|
);
|
|
|
|
}
|
2022-01-31 19:35:34 +00:00
|
|
|
|
|
|
|
// Valid nonce, but no tx found
|
|
|
|
if (!txHash) {
|
2022-01-31 18:37:29 +00:00
|
|
|
return (
|
|
|
|
<StandardFrame>
|
|
|
|
<AddressOrENSNameInvalidNonce
|
|
|
|
addressOrENSName={checksummedAddress}
|
|
|
|
nonce={nonce.toString()}
|
|
|
|
/>
|
|
|
|
</StandardFrame>
|
|
|
|
);
|
|
|
|
}
|
2022-01-31 19:35:34 +00:00
|
|
|
|
|
|
|
// Success; replace and render filler
|
|
|
|
navigate(transactionURL(txHash), { replace: true });
|
2022-01-31 18:37:29 +00:00
|
|
|
return <StandardFrame />;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default AddressTransactionByNonce;
|