2021-12-27 18:48:46 +00:00
|
|
|
import React, { useContext } from "react";
|
|
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
|
|
|
import { faChevronLeft } from "@fortawesome/free-solid-svg-icons/faChevronLeft";
|
|
|
|
|
import { faChevronRight } from "@fortawesome/free-solid-svg-icons/faChevronRight";
|
|
|
|
|
import NavButton from "./NavButton";
|
|
|
|
|
import { ChecksummedAddress } from "../types";
|
|
|
|
|
import { RuntimeContext } from "../useRuntime";
|
2021-12-27 22:20:13 +00:00
|
|
|
import {
|
|
|
|
|
useTransactionBySenderAndNonce,
|
|
|
|
|
useTransactionCount,
|
|
|
|
|
} from "../useErigonHooks";
|
2021-12-27 18:48:46 +00:00
|
|
|
|
|
|
|
|
type NavNonceProps = {
|
|
|
|
|
sender: ChecksummedAddress;
|
|
|
|
|
nonce: number;
|
|
|
|
|
};
|
|
|
|
|
|
2021-12-27 22:20:13 +00:00
|
|
|
const NavNonce: React.FC<NavNonceProps> = ({ sender, nonce }) => {
|
2021-12-27 18:48:46 +00:00
|
|
|
const { provider } = useContext(RuntimeContext);
|
|
|
|
|
const prevTxHash = useTransactionBySenderAndNonce(
|
|
|
|
|
provider,
|
|
|
|
|
sender,
|
|
|
|
|
nonce - 1
|
|
|
|
|
);
|
|
|
|
|
const nextTxHash = useTransactionBySenderAndNonce(
|
|
|
|
|
provider,
|
|
|
|
|
sender,
|
|
|
|
|
nonce + 1
|
|
|
|
|
);
|
2021-12-27 22:20:13 +00:00
|
|
|
const count = useTransactionCount(provider, sender);
|
|
|
|
|
const lastTxHash = useTransactionBySenderAndNonce(
|
|
|
|
|
provider,
|
|
|
|
|
sender,
|
|
|
|
|
count !== undefined ? count - 1 : undefined
|
|
|
|
|
);
|
2021-12-27 18:48:46 +00:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="pl-2 self-center flex space-x-1">
|
|
|
|
|
<NavButton txHash={prevTxHash} disabled={nonce === 0}>
|
|
|
|
|
<FontAwesomeIcon icon={faChevronLeft} />
|
|
|
|
|
</NavButton>
|
|
|
|
|
<NavButton
|
|
|
|
|
txHash={nextTxHash}
|
2021-12-27 22:20:13 +00:00
|
|
|
disabled={count === undefined || nonce >= count - 1}
|
2021-12-27 18:48:46 +00:00
|
|
|
>
|
|
|
|
|
<FontAwesomeIcon icon={faChevronRight} />
|
|
|
|
|
</NavButton>
|
|
|
|
|
<NavButton
|
|
|
|
|
txHash={lastTxHash}
|
2021-12-27 22:20:13 +00:00
|
|
|
disabled={count === undefined || nonce >= count - 1}
|
2021-12-27 18:48:46 +00:00
|
|
|
>
|
|
|
|
|
<FontAwesomeIcon icon={faChevronRight} />
|
|
|
|
|
<FontAwesomeIcon icon={faChevronRight} />
|
|
|
|
|
</NavButton>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default React.memo(NavNonce);
|