Make nav nonce control dumb; use just urls for navigation; speed up with prefetch
This commit is contained in:
parent
6a6e2cdb14
commit
f9f7a569e2
@ -1,18 +1,21 @@
|
|||||||
import { NavLink } from "react-router-dom";
|
import { NavLink } from "react-router-dom";
|
||||||
import { transactionURL } from "../url";
|
import { ChecksummedAddress } from "../types";
|
||||||
|
import { addressByNonceURL } from "../url";
|
||||||
|
|
||||||
// TODO: extract common component with block/NavButton
|
// TODO: extract common component with block/NavButton
|
||||||
type NavButtonProps = {
|
type NavButtonProps = {
|
||||||
txHash: string | null | undefined;
|
sender: ChecksummedAddress;
|
||||||
|
nonce: number;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const NavButton: React.FC<NavButtonProps> = ({
|
const NavButton: React.FC<NavButtonProps> = ({
|
||||||
txHash,
|
sender,
|
||||||
|
nonce,
|
||||||
disabled,
|
disabled,
|
||||||
children,
|
children,
|
||||||
}) => {
|
}) => {
|
||||||
if (disabled || txHash === null || txHash === undefined) {
|
if (disabled) {
|
||||||
return (
|
return (
|
||||||
<span className="bg-link-blue bg-opacity-10 text-gray-300 rounded px-2 py-1 text-xs">
|
<span className="bg-link-blue bg-opacity-10 text-gray-300 rounded px-2 py-1 text-xs">
|
||||||
{children}
|
{children}
|
||||||
@ -23,7 +26,7 @@ const NavButton: React.FC<NavButtonProps> = ({
|
|||||||
return (
|
return (
|
||||||
<NavLink
|
<NavLink
|
||||||
className="bg-link-blue bg-opacity-10 text-link-blue hover:bg-opacity-100 hover:text-white rounded px-2 py-1 text-xs"
|
className="bg-link-blue bg-opacity-10 text-link-blue hover:bg-opacity-100 hover:text-white rounded px-2 py-1 text-xs"
|
||||||
to={transactionURL(txHash)}
|
to={addressByNonceURL(sender, nonce)}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</NavLink>
|
</NavLink>
|
||||||
|
@ -7,7 +7,6 @@ import { ChecksummedAddress } from "../types";
|
|||||||
import { RuntimeContext } from "../useRuntime";
|
import { RuntimeContext } from "../useRuntime";
|
||||||
import {
|
import {
|
||||||
prefetchTransactionBySenderAndNonce,
|
prefetchTransactionBySenderAndNonce,
|
||||||
useTransactionBySenderAndNonce,
|
|
||||||
useTransactionCount,
|
useTransactionCount,
|
||||||
} from "../useErigonHooks";
|
} from "../useErigonHooks";
|
||||||
import { useSWRConfig } from "swr";
|
import { useSWRConfig } from "swr";
|
||||||
@ -19,22 +18,7 @@ type NavNonceProps = {
|
|||||||
|
|
||||||
const NavNonce: React.FC<NavNonceProps> = ({ sender, nonce }) => {
|
const NavNonce: React.FC<NavNonceProps> = ({ sender, nonce }) => {
|
||||||
const { provider } = useContext(RuntimeContext);
|
const { provider } = useContext(RuntimeContext);
|
||||||
const prevTxHash = useTransactionBySenderAndNonce(
|
|
||||||
provider,
|
|
||||||
sender,
|
|
||||||
nonce - 1
|
|
||||||
);
|
|
||||||
const nextTxHash = useTransactionBySenderAndNonce(
|
|
||||||
provider,
|
|
||||||
sender,
|
|
||||||
nonce + 1
|
|
||||||
);
|
|
||||||
const count = useTransactionCount(provider, sender);
|
const count = useTransactionCount(provider, sender);
|
||||||
const lastTxHash = useTransactionBySenderAndNonce(
|
|
||||||
provider,
|
|
||||||
sender,
|
|
||||||
count !== undefined ? count - 1 : undefined
|
|
||||||
);
|
|
||||||
|
|
||||||
// Prefetch
|
// Prefetch
|
||||||
const swrConfig = useSWRConfig();
|
const swrConfig = useSWRConfig();
|
||||||
@ -60,17 +44,19 @@ const NavNonce: React.FC<NavNonceProps> = ({ sender, nonce }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="pl-2 self-center flex space-x-1">
|
<div className="pl-2 self-center flex space-x-1">
|
||||||
<NavButton txHash={prevTxHash} disabled={nonce === 0}>
|
<NavButton sender={sender} nonce={nonce - 1} disabled={nonce === 0}>
|
||||||
<FontAwesomeIcon icon={faChevronLeft} />
|
<FontAwesomeIcon icon={faChevronLeft} />
|
||||||
</NavButton>
|
</NavButton>
|
||||||
<NavButton
|
<NavButton
|
||||||
txHash={nextTxHash}
|
sender={sender}
|
||||||
|
nonce={nonce + 1}
|
||||||
disabled={count === undefined || nonce >= count - 1}
|
disabled={count === undefined || nonce >= count - 1}
|
||||||
>
|
>
|
||||||
<FontAwesomeIcon icon={faChevronRight} />
|
<FontAwesomeIcon icon={faChevronRight} />
|
||||||
</NavButton>
|
</NavButton>
|
||||||
<NavButton
|
<NavButton
|
||||||
txHash={lastTxHash}
|
sender={sender}
|
||||||
|
nonce={count !== undefined ? count - 1 : -1}
|
||||||
disabled={count === undefined || nonce >= count - 1}
|
disabled={count === undefined || nonce >= count - 1}
|
||||||
>
|
>
|
||||||
<FontAwesomeIcon icon={faChevronRight} />
|
<FontAwesomeIcon icon={faChevronRight} />
|
||||||
|
@ -20,6 +20,9 @@ export const blockTxsURL = (blockNum: BlockTag) => `/block/${blockNum}/txs`;
|
|||||||
|
|
||||||
export const transactionURL = (txHash: string) => `/tx/${txHash}`;
|
export const transactionURL = (txHash: string) => `/tx/${txHash}`;
|
||||||
|
|
||||||
|
export const addressByNonceURL = (address: ChecksummedAddress, nonce: number) =>
|
||||||
|
`/address/${address}?nonce=${nonce}`;
|
||||||
|
|
||||||
export enum SourcifySource {
|
export enum SourcifySource {
|
||||||
// Resolve trusted IPNS for root IPFS
|
// Resolve trusted IPNS for root IPFS
|
||||||
IPFS_IPNS,
|
IPFS_IPNS,
|
||||||
|
Loading…
Reference in New Issue
Block a user